Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

WSDL2Java stub class receiving ArrayList instead of single object  RSS feed

 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:



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.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
From the XML schema fragment you provided, which only defines the type DL-TankInventory (compare to a type like String, Integer etc), it is impossible to tell what the web service is to return.
The type can be used with a maxOccurs that are either greater than 1 or "unbounded" - this specifies how many occurrences of the type that the response may contain.
Which web service stack are you using?
If you have time and energy to spare, do try the "wsimport" tool that comes with the standard JavaSE 6 distribution. Perhaps it is able to handle the WSDL better.
Best wishes!
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I forgot to include this part:



Which appears to me that it should only return one DL-TankInventory object?

I'm not familiar with wsimport, I'll have to look that one up.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Yes, you are right - when maxOccurs is not specified, its default value is 1.
Do try wsimport - there may be some problem with the tool you use (at least this would be my guess after having seen the WSDL fragment supplied).
Best wishes!
 
Michael Bruesch
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the WSDL2Java tool is creating the client classes correctly, but I think the WSDL itself may not be accurate. Before I try another tool (wsimport) I want to see if I can fix this issue since we only use Axis here at work. I tried adding the maxOccurs attribute to the response but it caused an exception:



It says: javax.wsdl.WSDLException: WSDLException (at /definitions/message[4]/part): faultCode=INVALID_WSDL: Encountered illegal extension attribute 'maxOccurs'. Extension attributes must be in a namespace other than WSDL's.

Where would I add the maxOccurs attribute?
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I think you will need to have some kind of "container" element that contains element(s) of the type DL-TankInventory.
In such an element, you could set maxOccurs on the element of the type DL-TankInventory.
Best wishes!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!