Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF架构公共元素始终为空_C#_Xml_Wcf_Xsd - Fatal编程技术网

C# WCF架构公共元素始终为空

C# WCF架构公共元素始终为空,c#,xml,wcf,xsd,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> </x

我正在使用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>
Last
弗斯特
第二街123号
某处
但是,公共元素具有xmlns属性(如上所示),并且在接收的对象中,所有公共元素都包含空值

我的声誉不足以显示屏幕截图,但所有不在公共元素中的数据都被正确传递。例如NameLast=“Last”,Address=Null


我对使用模式还不熟悉,希望有任何指导。谢谢。

我相信您想要的是这个,放在您的结束标签之前。
标签:

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

并在整个模式中使用:

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

谢谢你,丹!这解决了问题。