Is there any way to enable a WCF service to accept a request where order is not significant i.e. can you send in the following and get it to deserialise correctly:
<Request>
<Field1>Val1</Field1>
<Field2>Val2</Field2>
<Field3>Val3</Field3>
</Request>
or
<Request>
<Field3>Val3</Field3>
<Field1>Val1</Field1>
<Field2>Val2</Field2>
</Request>
or
<Request>
<Field2>Val2</Field2>
<Field3>Val3</Field3>
<Field1>Val1</Field1>
</Request>
etc …
I know the default behaviour of the data contract serialiser but can I get it to ignore the order altogether? Do I need a different/custom serialiser?
I cant seem to find a definitive answer anywhere.
Cheers,
Billy
If you use the
DataContractSerializerYour xml must be in a defined order. Either through the default which is alphabetical. Or through the order you define decorating your members of your definition.If you attempt to deserialize some xml and it is in the wrong order, it will only deserialize values which are to the serializer, in the correct place.
If you use the
XMLSerializerinstead, this does not rely on the xml being in an order and will deserialize if it finds the correct nodes which is the behaviour you seem to want.Have a look at this tutorial on the XmlSerializer as an example.