WSDL2Java 存根类接收 ArrayList 而不是单个对象

发布于 2024-12-01 03:43:36 字数 1636 浏览 0 评论 0原文

我对网络服务非常陌生,所以请原谅我的无知。我正在尝试使用向我提供 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 的类(与没有破折号的复杂类型相同)。当我调用应该返回此 DLTankInventory 对象的方法时,它会抛出 ClassCastException ,表示它无法将 ArrayList 转换为 DLTankInventory。

我使用soapUI程序来测试Web服务并且它可以工作,但它返回多个DLTankInventory对象(可能返回一个数组?)。 WSDL2Java 工具似乎认为它应该只返回一个 DLTankInventory 对象。我做错了什么?如果需要,我可以发布更多 wsdl 或客户端代码。

谢谢

--编辑 我进入 Stub 类并修改了函数以将返回的对象转换为 DLTankInventory 对象的 ArrayList,它现在似乎正在工作。我的问题仍然是为什么 WSDL2Java 希望使其返回单个对象。 WSDL 是否错误?有人告诉我这是正确的。

I'm very new to web services so please forgive my ignorance. I'm trying to consume a web service to which I was provided the wsdl. There are several complex types being returned by the web service. Here is an example of one:

<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>

I used WSDL2Java to create the client classes and everything seems ok there. It created a class called DLTankInventory (same as the complexType without the dash). When I call the method that should return this DLTankInventory object it throws a ClassCastException saying it can't cast ArrayList to DLTankInventory.

I used the soapUI program to test the web service and it works, but it returns multiple DLTankInventory objects (maybe returning an array?). The WSDL2Java tool seems to think it should only return one DLTankInventory object. What am I doing wrong? I can post more of the wsdl or client code if needed.

Thanks

--EDIT
I went into the Stub class and modified the function to cast the returning Object to an ArrayList of DLTankInventory object and it seems to be working now. My question still is why WSDL2Java wanted to make it return a single object. Is the WSDL wrong? I've been told it is correct.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一梦浮鱼 2024-12-08 03:43:36

仅传输原始数据类型。您必须序列化和反序列化(对此我不熟悉)对象,或者通过获取字段然后从中创建一个对象来创建您想要的类的对象。

Only the primitive data types are transported. You have to serialize and deserialize(about which am not familiar) the object, or else create the object of the class you wanted, by taking the fields and later creating an object out of it.

心碎无痕… 2024-12-08 03:43:36

听起来您正在使用某种 Web 服务框架,例如 CXF、Axis 或 XFire。如果您在尝试使用框架反序列化消息(使用由同一框架生成的存根)时收到 ClassCastException,则这是您正在使用的特定 Wsdl2Java 库实现中的错误。

假设它是像 CXF 或 Axis 这样的开源实现,您应该在他们的论坛/留言板上报告这一点,或者发布一个简单的测试用例供他们尝试。

It sounds like you're using some sort of Web Services framework like CXF, Axis, or XFire. If you're receiving a ClassCastException while trying to use the framework to deserialize a message, using the stubs which were generated by that same framework, then that is a bug in the particular Wsdl2Java library implementation you're using.

Assuming it's an open-source implementation like CXF or Axis, you should report this on their forums/message boards, or post a simple test case for them to try out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文