WCF Schema公共元素始终为null

时间:2015-03-26 14:03:46

标签: c# xml wcf xsd

我正在使用xsd生成OperationContract中可用的对象。 XSD的地址,城市,州和邮政编码是常见的

<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 =&#34; Last&#34;,Address = Null。

我是使用Schemas的新手,并且会欣赏任何方向。感谢。

1 个答案:

答案 0 :(得分:0)

我相信你想要的是这个,放在你的结束</xs:schema>标签之前:

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

并在整个架构中使用:

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