【问题标题】:WCF Schema common elements always nullWCF 架构公共元素始终为空
【发布时间】:2015-03-26 14:03:46
【问题描述】:

我正在使用 xsd 生成 OperationContract 中可用的对象。 XSD 的地址、城市、州和 zip 元素很常见

<xs:element name="Address" nillable="true">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:maxLength value="50"/>
    </xs:restriction>
  </xs:simpleType>
</xs:element>

并在整个 XML 中使用。

<xs:element ref="Address"  />

当我编译架构时,类会使用公共元素正确生成。 当我运行服务时,OperationContext 包含来自客户端的预期请求:

      <NameLast>Last</NameLast>
      <NameFirst>First</NameFirst>
      <Address xmlns="http://tempuri.org/">123 2nd St</Address>
      <City xmlns="http://tempuri.org/">Somewhere</City>

然而,公共元素具有 xmlns 属性(如上所示),并且在接收到的对象中,所有公共元素都包含空值。

我的声誉不够高,无法显示屏幕截图,但所有不在公共元素中的数据都正确传递。如NameLast = "Last", Address = Null。

我是使用 Schemas 的新手,如果有任何指导,我将不胜感激。谢谢。

【问题讨论】:

    标签: c# xml wcf xsd


    【解决方案1】:

    我相信你想要的是这个,放在你的结束 &lt;/xs:schema&gt; 标签之前:

    <xs:simpleType name="AddressType">
      <xs:restriction base="xs:string">
        <xs:maxLength value="50"/>
      </xs:restriction>
    </xs:simpleType>
    

    并在整个架构中使用:

    <xs:element name="Address" type="AddressType"  />
    

    【讨论】:

    • 谢谢丹!这解决了问题。
    猜你喜欢
    • 2020-08-12
    • 2014-08-18
    • 1970-01-01
    • 2015-12-04
    • 1970-01-01
    • 2016-01-27
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多