数据成员顺序和 XML 反序列化 [英] Data Member Order and XML Deserialization

查看:29
本文介绍了数据成员顺序和 XML 反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 RESTful WCF 应用程序,它使用自定义类作为服务方法参数.这些类用 [DataContract] 属性修饰,它们的每个属性都用 [DataMember] 属性修饰.

I have a RESTful WCF application that makes use of custom classes as service method parameters. These classes are decorated with the [DataContract] attribute and each of their properties is decorated with the [DataMember] attribute.

反序列化器的工作方式与 MSDN 上的以下数据成员订单"页面一致:http://msdn.microsoft.com/en-us/library/ms729813.aspx.

The deserializer works consistent with the following "Data Member Order" page at MSDN: http://msdn.microsoft.com/en-us/library/ms729813.aspx.

也就是说,它期望 XML 格式的输入数据中的元素遵循所描述的顺序.事实上,如果其中一个元素出现乱序,反序列化后它就没有提交的值,而是为空.

That is, it expects the elements in XML formatted input data to follow the order so described. In fact, if one of the elements is out of order, after deserialization it does not have the submitted value but rather is null.

是否有一种好方法可以让调用程序自由地对 xml 元素进行排序(即,以任何顺序)并针对元素的每个排序进行反序列化?

Is there a good way to allow the calling program to order the xml elements freely (i.e., in any order) and to have the deserialization come out right for every ordering of the elements?

推荐答案

大多数 XML 不允许以任意顺序输入元素.据我所知,没有充分的理由允许这样做.

Most XML does not permit elements to be entered in arbitrary order. There's no good reason to permit this, as far as I know.

数据契约序列化程序根本不支持这一点.它会增加开销,并且没有任何价值.

The Data Contract Serializer does not support this at all. It would add overhead, and provide no value.

为什么您的调用者不能只发送正确的 XML?

Why can't your callers just send the correct XML?

这篇关于数据成员顺序和 XML 反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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