【发布时间】:2011-08-25 12:12:06
【问题描述】:
我对网络服务很陌生,所以请原谅我的无知。我正在尝试使用向我提供 wsdl 的 Web 服务。 Web 服务返回了几种复杂类型。这是一个例子:
<complexType name="DL-TankInventory">
<sequence>
<element name="DateTime" type="xsd:long" minOccurs="1" maxOccurs="1"/>
<element name="TankNumber" type="xsd:short" minOccurs="1" maxOccurs="1"/>
<element name="ProductCode" type="xsd:byte" minOccurs="1" maxOccurs="1"/>
<element name="StatusBits" type="xsd:short" minOccurs="1" maxOccurs="1"/>
<element name="ProductVolume" type="xsd:double" minOccurs="1" maxOccurs="1"/>
<element name="ProductTcVolume" type="xsd:double" minOccurs="1" maxOccurs="1"/>
<element name="Ullage" type="xsd:double" minOccurs="1" maxOccurs="1"/>
<element name="ProductHeight" type="xsd:double" minOccurs="1" maxOccurs="1"/>
<element name="WaterHeight" type="xsd:double" minOccurs="1" maxOccurs="1"/>
<element name="WaterVolume" type="xsd:double" minOccurs="1" maxOccurs="1"/>
<element name="AvgFuelTemperature" type="xsd:double" minOccurs="1" maxOccurs="1"/>
</sequence>
</complexType>
我使用 WSDL2Java 创建客户端类,那里的一切似乎都正常。它创建了一个名为 DLTankInventory 的类(与没有破折号的 complexType 相同)。当我调用应该返回这个 DLTankInventory 对象的方法时,它会抛出一个 ClassCastException,说它不能将 ArrayList 转换为 DLTankInventory。
我使用soapUI 程序测试了Web 服务,它可以工作,但是它返回多个DLTankInventory 对象(可能返回一个数组?)。 WSDL2Java 工具似乎认为它应该只返回一个 DLTankInventory 对象。我究竟做错了什么?如果需要,我可以发布更多 wsdl 或客户端代码。
谢谢
--编辑 我进入了 Stub 类并修改了函数以将返回的 Object 转换为 DLTankInventory 对象的 ArrayList,它现在似乎可以工作了。我的问题仍然是为什么 WSDL2Java 想让它返回单个对象。 WSDL 错了吗?有人告诉我这是正确的。
【问题讨论】:
标签: web-services wsdl wsdl2java