【问题标题】:Can a WCF data contract be recursive? For example a binary tree? Is there a difference with ASMX services in supporting recursive data structures?WCF 数据契约可以递归吗?例如二叉树? ASMX 服务在支持递归数据结构方面有什么不同吗?
【发布时间】:2010-11-29 12:10:33
【问题描述】:

在 SOA 中,我相信 wsdl 不支持递归数据类型,但我看到了一些代理实际工作的示例。有人知道更多吗?

【问题讨论】:

    标签: wcf wsdl soa


    【解决方案1】:

    允许使用递归类型定义,甚至允许循环对象图并可序列化。但是,为了避免在序列化和反序列化时耗尽堆栈空间,您需要创建一个覆盖 CreateSerializer 方法的自定义行为,并在创建 DataContractSerializer 时将 preserveObjectReferences 参数设置为 true。请参阅 James Kovacs 的blog 了解更多信息。

    【讨论】:

    • 谢谢特拉维斯,这就是我一直在寻找的答案。确实很好的博客
    【解决方案2】:

    请定义递归的含义。以下是在 WSDL 中使用的有效 XML Schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         elementFormDefault="qualified" attributeFormDefault="unqualified">
        <xs:element name="Node" type="NodeType"/>
        <xs:complexType name="NodeType">
            <xs:sequence>
                <xs:element name="Node" type="NodeType"/>
            </xs:sequence>
        </xs:complexType>
    </xs:schema>
    

    【讨论】:

    • 假设你有这样的东西: [DataContract] public class Tree{ [DataMember] public Tree Left{ get;set; } [DataMember] 公共树权{ get;set; [DataMember] 公共字符串数据{ get;set; } } }
    • 在 SOA 中,不是不支持递归数据类型吗?
    • @Neo:我从没听说过。如果你能找到引用,请张贴。
    猜你喜欢
    • 2012-10-29
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 2016-04-19
    • 2014-03-29
    • 2016-03-18
    • 1970-01-01
    • 2021-08-06
    相关资源
    最近更新 更多