WSDL2Java stub class receiving ArrayList instead of single object
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开发者_如何学Go 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.
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.
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.
精彩评论