I have an object which I serialize nicely into this:
<?xml version="1.0" encoding="utf-8" ?>
<people xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" userID="AX12345">
<group groupID="1234_ABCD">
<person name="Name 0" id="0" />
<person name="Name 1" id="1" />
<person name="Name 2" id="2" />
<person name="Name 3" id="3" />
</group>
</people>
Which is returned as a string to this:
[OperationContract]
[WebGet(UriTemplate = "format/{format}/userid/{userid}/sessionkey/{sessionkey}")]
string Get(string format,string userid,string sessionkey);
When I view the returned data this service, I get this.
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<GetResponse xmlns="http://tempuri.org/">
<GetResult>**<?xml version="1.0" encoding="utf-8"?><people xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" userID="123BOBBY"><group groupID="1234_ABCD"><person name="Name 0" id="0" /><person name="Name 1" id="1" /><person name="Name 2" id="2" /><person name="Name 3" id="3" /></group></people></**GetResult>
</GetResponse>
</s:Body>
</s:Envelope>
And what I would like is this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header />
<s:Body>
<GetResponse xmlns="http://tempuri.org/">
<GetResult>
<people userID="AX12345">
<group groupID="1234_ABCD">
<person name="Name 0" id="0" />
<person name="Name 1" id="1" />
<person name="Name 2" id="2" />
<person name="Name 3" id="3" />
</group>
</people>
</GetResult>
</GetResponse>
</s:Body>
</s:Envelope>
I am a beginner with all this.
It turns out the answer was fairly simple.
DataContractSerializer is the default serializer, and
[XmlSerializerFormat]overrides the serialization.In my classes I have added serialization attributes:
While I am happy with the short term gain, I will be looking deeper into this to make sure I keep control of the output.
Thanks
P