I have a recurring problem when passing Serialized objects between non-.NET Clients, and .NET WCF Services.
When WCF Deserializes objects, it is strictly dependant upon the order of properties.
That is, if I define my class as:
public class Foo
{
public int ID { get; set; }
public int Bar { get; set; }
}
Then WCF Will serialize the object as as:
<Foo>
<Bar>123</Bar>
<ID>456</ID>
</Foo>
Note: The properties are serialized in alphabetical order.
If you attempt to Deserialize an object which has the positions of Bar
and ID
swapped, WCF will treat the incorrectly positioned elements as null.
Whilst I know I can use the DataMember
attribute, and force a specific ordering, I want to reduce the number of times I have to debug issues where fields are 'mysteriously' null.
So, my question is: Can you tell the WCF Deserializer to ignore the order of fields, when deserializing objects.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…