.net - 是什么决定了 WCF WSDL 中 XML 属性的顺序?

标签 .net xml wcf wsdl

之前也有人问过类似的问题,我的理解是XML或者schema中不能指​​定XML属性的顺序。但是,我想知道,WSDL 中的 XML 属性的顺序是由 WCF 随机生成的还是遵循某些规则。

例如,在某个阶段,我们在生成的 WSDL 中有以下(部分)XML 标记。

<xs:element maxOccurs="unbounded" minOccurs="0"

现在再次生成它就变成了

<xs:element minOccurs="0" maxOccurs="unbounded"

交换了最小值和最大值的顺序。

另一个例子:

<wsdl:port binding="tns:BasicHttpBinding_IReferenceDataBusinessService" name="BasicHttpBinding_IReferenceDataBusinessService">

成为

<wsdl:port name="BasicHttpBinding_IReferenceDataBusinessService" binding="tns:BasicHttpBinding_IReferenceDataBusinessService">

只是想知道是什么决定了 WCF 中的此类订单?是否可以调整流程以保持相同的顺序,从而更轻松地比较两个 WSDL 文件?

谢谢。

最佳答案

您承认属性顺序无关紧要,然后继续暗示您无论如何都希望按照属性顺序行事。根据定义,它是一个实现细节。依赖任何给定的属性排序,后果自负。

此外,属性顺序只是按词法比较 XML 文档的众多障碍之一。在开始这样的努力之前,请熟悉 Canonical XML Version 1.1 涵盖的所有内容。 .总结如下:

The canonical form of an XML document is physical representation of the document produced by the method described in this specification. The changes are summarized in the following list:

  • The document is encoded in UTF-8
  • Line breaks normalized to #xA on input, before parsing
  • Attribute values are normalized, as if by a validating processor
  • Character and parsed entity references are replaced
  • CDATA sections are replaced with their character content
  • The XML declaration and document type declaration are removed
  • Empty elements are converted to start-end tag pairs
  • Whitespace outside of the document element and within start and end tags is normalized
  • All whitespace in character content is retained (excluding characters removed during line feed normalization)
  • Attribute value delimiters are set to quotation marks (double quotes)
  • Special characters in attribute values and character content are replaced by character references
  • Superfluous namespace declarations are removed from each element
  • Default attributes are added to each element
  • Fixup of xml:base attributes [C14N-Issues] is performed
  • Lexicographic order is imposed on the namespace declarations and attributes of each element

健壮的代码不依赖于实现在任何这些维度上的意外(非必要)属性。

关于.net - 是什么决定了 WCF WSDL 中 XML 属性的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31195817/

相关文章:

java - 尝试显示/取消隐藏 LinearLayout 时无法调用 setVisibility 方法

sql-server - 如何从 SQL Server 中的 XML 列获取所有数据

c# - 插入和更新的 URI 约定 - WCF Rest API

c# - 使用服务引用时无法将 IAsyncResult 转换为 AsyncResult

android - 具有适用于 Android 和 iOS 的相互证书的消息安全性

.net - 如果系统日期设置为 future ,为什么请求在 wp8 上会失败?

c# - 创建另一个程序的程序

c# - 生成一个带一位小数点的随机 double

c# - .NET 文件流写入方法写入所有空行

c++ - boost 属性树 xml 编写器输出中没有行尾