26

I am working towards an android application. I need to use a web service. I have a wsdl file but I want to convert that into java so that I can use its functions in my Java programs. Is there any way of converting a wsdl file into Java?

GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Farhan
  • 3,206
  • 14
  • 49
  • 62
  • supose that u have jdk 1.6 or higher go in cmd in the location you want to output the generated classes and in that location write: wsimport -keep -verbose http ://myWsdlURL?wsdl – Cassian Mar 06 '15 at 14:34

7 Answers7

27

Yes you can use:

Wsdl2java eclipse plugin

With this all you will need is to supply the wsdl, and the client which is the Java classes will be automatically generated for you.

Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
12

Just to generate the java classes from wsdl to me the best tool is "cxf wsdl2java". Its pretty simple and easy to use. I have found some complexities with some data type in axis2. But unfortunately you can't use those client stub code in your android application because android environment doesn't allow the "java/javax" package name in compiling time unless you rename the package name.

And in the android.jar all the javax.* sources for web service consuming are not available. To resolve these I have developed this WS Client Generation Tool for android.

In background it uses "cxf wsdl2java" to generate the java client stub for android platform for you, And I have written some sources to consume the web service in a smarter way.

Just give the wsdl file location it will give you the sources and some library. you have to just put the sources and the libraries in your project. and you can just call it in some "method call fashion" just we do in our enterprise project, you don't need to know the namespace/soap action etc. For example, you have a service to login, what you need to do is :

LoginService service = new LoginService ( );
Login login = service.getLoginPort ( );
LoginServiceResponse resp = login.login ( "someUser", "somePass" );

And its fully open and free.

Community
  • 1
  • 1
Asraful Haque
  • 753
  • 8
  • 11
  • Can you tell me, in which jar file, I can see method support by this service, please. Thanks :) – hqt Mar 30 '14 at 16:56
8

jdk 6 comes with wsimport that u can use to create Java-classes from a WSDL. It also creates a Service-class.

http://docs.oracle.com/javase/6/docs/technotes/tools/share/wsimport.html

Patrick P
  • 111
  • 1
  • 5
6

Assuming that you have JAXB installed Go to the following directory C:\Program Files\jaxb\bin open command window here

> xjc -wsdl http://localhost/mywsdl/MyDWsdl.wsdl C:\Users\myname\Desktop

C:\Users\myname\Desktop is the ouput folder you can change that to your preference

http://localhost/mywsdl/MyDWsdl.wsdl is the link to the WSDL

George Otieno
  • 536
  • 4
  • 10
5

i founded a great toool to auto parse and connect to web services

http://www.wsdl2code.com

http://www.wsdl2code.com/pages/Example.aspx

 SampleService srv1 = new SampleService();
     req = new Request();                     
     req.companyId = "1";
     req.userName = "userName";                                     
     req.password = "pas";
     Response response =    srv1.ServiceSample(req);
Bennya
  • 554
  • 5
  • 10
5

You can use the eclipse plugin as suggested by Oscar earlier. Or if you are a command line person, you can use Apache Axis WSDL2Java tool from command prompt. You can find more details here http://axis.apache.org/axis/java/reference.html#WSDL2JavaReference

Vini
  • 8,299
  • 11
  • 37
  • 49
2

You can use the WSDL2JAVA Codegen (or) You can simply use the 'Web Service/WebServiceClient' Wizard available in the Eclipse IDE. Open the IDE and press 'Ctrl+N', selectfor 'Web Service/WebServiceClient', specify the wsdl URL, ouput folder and select finish.

It creates the complete source files that you would need.

Anuj Balan
  • 7,629
  • 23
  • 58
  • 92
  • Sir, I couldn't find webserviceclient in the eclipse.. can you please elaborate a bit more on that.. thnx – Farhan Aug 03 '11 at 15:38
  • Sir, I can't see any web service or webserviceclient when I press Ctrl+N. am I missing some plugins?? – Farhan Aug 03 '11 at 16:19
  • 1
    What you need is 'org.eclipse.jst.ws'. Download links>> http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/galileor I have worked with Eclipse 3.3 to 3.6, and Web Services is available in 3.3, but not 3.6. – Anuj Balan Aug 04 '11 at 05:00
  • [Using Eclipse's Web Service Client wizard](http://www.eclipse.org/webtools/community/education/web/t320/Generating_a_client_from_WSDL.pdf) is what I have done, [thanks to this nice guide](http://www.eclipse.org/webtools/community/education/web/t320/Generating_a_client_from_WSDL.pdf). Unexplained errors of access to the WDSL. But the Java classes are generated ! Now, how to use them ? I want to call Java methods that connect to the Web Service and perform WS operations. – Nicolas Barbulesco Apr 04 '13 at 16:30
  • @Nicolas: Check this ---> http://stackoverflow.com/questions/8654517/creating-client-for-web-service/8654927#8654927 – Anuj Balan Apr 05 '13 at 08:47
  • @Anuj — Thank you, but this does not fit my generated Java classes. But [this other answer](http://stackoverflow.com/a/4149405/1824094) is promising. Hey, Eclipse and Axis people, the generated Java classes miss Javadoc ! – Nicolas Barbulesco Apr 05 '13 at 13:15
  • Exactly the same. The one I suggested does the same, only thing is that I haven't explained them well :P – Anuj Balan Apr 05 '13 at 13:24
  • Answer : [this other answer](http://stackoverflow.com/a/4149405/1824094) works ! And the code is simple. :-) – Nicolas Barbulesco Apr 05 '13 at 16:35