File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Automatically gen. code from WSDL results in XML with same tag for array and array elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Automatically gen. code from WSDL results in XML with same tag for array and array elements" Watch "Automatically gen. code from WSDL results in XML with same tag for array and array elements" New topic
Author

Automatically gen. code from WSDL results in XML with same tag for array and array elements

Igc Sa
Greenhorn

Joined: Sep 20, 2011
Posts: 3
Hi all,

I had to generate webservices from WSDL and I used Eclipse to do so (New -> Webservices -> Top-bottom, etc)
So far the generated code is good except for one thing: the arrays are not working as expected because the array tag is the same as the one given for the elements in the array.

This example will show you clearly what's going on:

A part of my WSDL where I have an array called "Transmisiones" whose elements should be tagged as "TransmisionDatos":



What I expected it to generate (an array Transmisiones with N embedded TransmisionDatos elements):


What it actually generates (response received using SoapUI for testing):


As you can see, surprisingly the tag for the array Transmisiones is the same as for the elements of the array.

I've been playing with the WSDL for days but I couldn't get the tool to generate code that uses a different tag for the array and its elements.

This code is useless because the program that is calling my WS expects a response with correctly build arrays.

Do I have to change the WSDL or any other thing? I'm going crazy over this, any help will be greatly appreciated . Cheers.
Igc Sa
Greenhorn

Joined: Sep 20, 2011
Posts: 3
Maybe I didn't make it clear enough.

I just want to know how to set up an array in WSDL so that the code generated by WSDL2Java names the array container (ListOfThings) different than the elements it contains (Thing)



Arrays in Webservices, it can't be so complicated, somebody must have hit this issue before.

Please help.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Have you tried wsimport in the JavaSE 6 JDK?
wsimport is similar to WSDL2Java. It is the standard web-service-artifact-producing-comman from Sun/Oracle.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
1. Basically, I used Eclipse to create a xml schema file NewXMLSchema.xsd
2. I generate an example of xml file using that NewXMLSchema.xml

I found the error is
<xs:element ref="ns1atosEspecificos" minOccurs="0"/>

Edited: to be specific

I remove minOccurs="0" and it worked because minOccurs="0" means Transmisiones should have no children TransmisionDatos

<xsd:element ref="tns:Transmisiones"/>

Igc Sa
Greenhorn

Joined: Sep 20, 2011
Posts: 3
Thank you both for your answers.
I had to leave this problem with a temporary solution (removing maxOccurs I got a simpler WSDL that generated an array of 1 element, or just a nested element inside the other) because I had a lot of other urgent stuff to do but I really appreciate your time and dedication.
However, I just changed the WDSL to remove minOccurs and still keep getting the same name for the array and the elements of the array:



The WSDL was provided by the client and I guess that the XML generated from it should be fine so I'm wondering if this is all a problem related to the tool I use to generate the code.
Maybe I should give a try to wsimport as Ivan Krizsan suggested, if I get back to the issue I'll keep you posted.

Thanks again to all of you for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Automatically gen. code from WSDL results in XML with same tag for array and array elements