I build a WCF Rest service to provide data for another process. suppose that his name is GetData.
This one provide a xml response having this structure :
<?xml version="1.0" encoding="utf-8"?>
<GetDataResponse xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetDataResult>
<DataMessage>
<a></a>
<b></b>
<c></c>
</DataMessage>
</GetDataResult>
</GetDataResponse>
the service interface :
[XmlSerializerFormat]
[OperationContract(Name = "GetData")]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "Data/{Param}")]
List<DataMessage> GetData(string Params);
I would like to deserialize the xml after saving it, following the DataMessage class. So, I would like to have this schema :
<?xml version="1.0" encoding="utf-8"?>
<DataMessages xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<DataMessage>
<a></a>
<b></b>
<c></c>
</DataMessage>
</DataMessages>
What should I do to define the service response schema to have it like this?
Thank you.
You can use some attributes in the
System.Xml.Serializationnamespace to define an object graph which maps to the schema you have. The code below does that.