C#访问WS时不能正确反序列化对象
lizzz 2005-10-19 04:11:05 当我用C#访问java ws的时候自定义java对象以及List都能够被C#正确的反序列化成C#的代理类。但是在处理java的HashMap的时候WSDL描述为:
<complexType name="mapItem">
<sequence>
<element name="key" nillable="true" type="xsd:anyType" />
<element name="value" nillable="true" type="xsd:anyType" />
</sequence>
</complexType>
<complexType name="Map">
<sequence>
<element name="item" minOccurs="0" maxOccurs="unbounded" type="apachesoap:mapItem" />
</sequence>
</complexType>
并且也生成了C#端的代理类:
[System.Xml.Serialization.SoapTypeAttribute("Map", "http://xml.apache.org/xml-soap")]
public class Map {
public mapItem[] item;
}
[System.Xml.Serialization.SoapTypeAttribute("mapItem", "http://xml.apache.org/xml-soap")]
public class mapItem {
public object key;
public object value;
}
当调用ws的时候java ws端返回的soap报文为:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getMResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://test">
<getMReturn href="#id0"/>
</ns1:getMResponse>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Map" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://xml.apache.org/xml-soap">
<item>
<key xsi:type="soapenc:string">testkey</key>
<value xsi:type="soapenc:string">testvalue</value>
</item>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
(原始的java段数据含义为在一个HashMap对象中存储了一组数据,key=testkey;value=testvalue)。
当C#客户端接收到这段报文后居然生成了一个Map对象,但是Map中的mapItem[]是空的。
请问在什么情况下可能出现这种问题呢?