Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate java classes from WSDL file

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?

like image 616
Farhan Avatar asked Aug 03 '11 00:08

Farhan


People also ask

How do I create a Java class using WSDL?

Using OEPE, you can generate a WSDL file from a Java class for your project by following this procedure: Create new or use an existing Web service project. Right-click a Java class in your Web service project in the Project Explorer, and select WebLogic Web Service > Generate WSDL from the drop-down menu.

Which Java tool is used to generate Java artefacts from WSDL?

You can use the JAX-WS tool, wsimport, to process a WSDL file and generate portable Java artifacts that are used to create a web service. The portable Java artifacts created using the wsimport tool are: Service endpoint interface (SEI) Service class.

How do I generate a class from WSDL using Apache CXF?

You will have to make sure that you create an appropriate directory structure for your project and add the earlier shown hello. wsdl file to the specified folder. The wsdl2java plugin will compile this wsdl and create Apache CXF classes in a pre-defined folder.


3 Answers

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.

like image 64
Oscar Gomez Avatar answered Oct 27 '22 15:10

Oscar Gomez


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.

like image 12
Asraful Haque Avatar answered Oct 27 '22 14:10

Asraful Haque


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

like image 8
Patrick P Avatar answered Oct 27 '22 13:10

Patrick P