WCF Disable Deserialization Order Sensitivity

You can specify the serialization order by decorating the elements in your data contract:

[DataContract]
public class Foo 
{ 
  [DataMember(Order=1)]
  public int ID { get; set; } 

  [DataMember(Order=2)]
  public int Bar { get; set; } 
}

So you can make sure the serialization order is the same all the time. But there is no way to tell the deserializer to “forget” about the order – the point is: this is handled by means of an XML schema, and done using the <xs:sequence> element – and that does imply and require order. You cannot just turn that off, I’m afraid.

Based on that XML schema, your non-.NET clients should be able to verify whether or not their XML that they’re about to send conforms to that schema – and if it doesn’t because the Bar and ID element have been swapped, they shouldn’t be sending that invalid XML.

Leave a Comment