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[]是空的。

请问在什么情况下可能出现这种问题呢?
...全文
247 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xamaizi 2005-10-20
  • 打赏
  • 举报
回复
学习一下:)
lizzz 2005-10-20
  • 打赏
  • 举报
回复
没人碰到类似的问题吗?
lizzz 2005-10-19
  • 打赏
  • 举报
回复
代码本身不是很长,分成了3块,wsdl定义、C#代理类和收到的soap报文,自己也顶一下。
lovewindy 2005-10-19
  • 打赏
  • 举报
回复
太长的代码了,帮顶

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧