WCF禁用反序列化订单灵敏度 [英] WCF Disable Deserialization Order Sensitivity

查看:120
本文介绍了WCF禁用反序列化订单灵敏度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个反复出现的问题之间non-.NET传递时,序列化对象的客户,和.NET WCF服务。

I have a recurring problem when passing Serialized objects between non-.NET Clients, and .NET WCF Services.

当的WCF反序列化的对象,它是严格依赖于属性的顺序。

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; } 
}

然后WCF会序列化对象为:

Then WCF Will serialize the object as as:

<Foo>
  <Bar>123</Bar>
  <ID>456</ID>
</Foo>

注:该属性是序列化的字母顺序。

Note: The properties are serialized in alphabetical order.

如果您尝试反序列化对象,它有栏的位置 ID 交换,WCF将把正确定位的元素为空。

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.

所以,我的问题是:你能告诉WCF解串器忽略字段的顺序,反序列化对象时。

So, my question is: Can you tell the WCF Deserializer to ignore the order of fields, when deserializing objects.

推荐答案

有一个古老的线程在这个位置:

There's an old thread on this here:

<一个href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a891928b-d27a-4ef2-83b3-ee407c6b9187">http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/a891928b-d27a-4ef2-83b3-ee407c6b9187

看起来唯一的选择是交换序列化,但后来它成为选择的是更讨厌。

Looks like the only option is to swap the serializer, but then it becomes opt in which is even more annoying.

编辑::您可以编写自己的串行重新排序的元素,然后将它传递给的DataContractSerializer

you could write your own serializer to re-order the elements and then pass it on to DataContractSerializer.

这篇关于WCF禁用反序列化订单灵敏度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆