我正在使用网络服务而且我有这个来自wsdl:
<xs:complexType name="Person">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="PersonAddresses" type="ns:PersonAddress" />
</xs:sequence>
</xs:complexType>
来自xsd:
<!--Complex Type for PersonAddress-->
<xs:complexType name="PersonAddress">
<xs:sequence>
<xs:element name="Address" type="Address" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<!--Complex Type for Address-->
<xs:complexType name="Address">
<xs:sequence>
<xs:element name="Addr1" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="Addr2" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="City" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="State" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="Zip" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
使用生成的代理,我创建一个PersonAddress集合并向其添加Address对象。
...
var convertedAddresses = new PersonAddress[addressesToCounvert.Count];
for (int i = 0; i < addresses.Count; i++)
{
convertedAddresses[i] = ConvertAddress(addresses[i]);
}
person.PersonAddresses = convertedAddresses;
...
当我提交请求时,它看起来像这样
<PersonAddress>
<Address>
...
</Address>
</PersonAddress>
<PersonAddress>
<Address>
...
</Address>
</PersonAddress>
那么我做错了什么......所需的格式是
<PersonAddress>
<Address>
...
</Address>
<Address>
...
</Address>
</PersonAddress>
感谢任何输入
答案 0 :(得分:1)
据我所知,您获得的输出与WSDL / XSD定义相匹配。基于WSDL,<Person>
元素可以包含多个<PersonAddress>
元素。基于XSD,<PersonAddress>
元素可以包含0或1个<Address>
元素。使用所提供信息的有效结构将是:
<Person>
<PersonAddress>
<Address>
...
</Address>
</PersonAddress>
</Person>
<Person>
<PersonAddress>
<Address>
...
</Address>
</PersonAddress>
<PersonAddress>
<Address>
...
</Address>
<PersonAddress>
</Person>
请注意<PersonAddress>
的拼写不一致。在您提供的WSDL代码中,<Person>
元素定义为包含0到多个<PersonAddresses>
元素(请注意“地址”的复数形式)。为了这个答案的目的,我假设这只是一个错字,<PersonAddresses>
应该在WSDL中拼写为<PersonAddress>
。我想确保指出这一点,以防问题只是你正在使用错误的对象(即可能有一个<PersonAddresses>
复杂类型允许其中包含1到多个<Address>
个元素)