WCF Disable Deserialization Order Sensitivity

后端 未结 4 590
说谎
说谎 2020-12-09 15:01

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

4条回答
  •  难免孤独
    2020-12-09 15:49

    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 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.

提交回复
热议问题