I am working towards an android application. I need to use a web service. I have a wsdl file but I wan开发者_开发技巧t 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?
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.
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.
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
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
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);
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
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.
I have quite complex WCF web service and I've tried a few different tools, but in most cases I couldn't connect to my web service. Finally I've used this one:
http://easywsdl.com/
This is only one tool which generetes classes that works without ANY changes!
精彩评论