Generating Java from WSDL for use on Android with ksoap2-android SOAP client?

Bjarke Freund-Hansen picture Bjarke Freund-Hansen · Feb 3, 2012 · Viewed 38.3k times · Source

I have to access a existing SOAP webservice from an Android application. I have been provided some WSDL files describing the webservice. Reading some other answers here on SO, it seems ksoap2-android is the way to go, with respect to which SOAP client to use.

The next issue is then how to generate the Java classes needed from the WSDL files, and this is where I am coming up short. As far as I can see there are the following options:

  1. AXIS2 code generator
  2. WSDL2ksoap
  3. JAX-WS wsimport tool

I initially tried #1, with the AXIS2 eclipse plugin for wsdl2code generator. The wizard did successfully generate a lot of Java code, however it also changed my android project to some kind of webservice project, and I was never able to get anything that was generated to compile, let alone work with ksoap2-android. Has anybody has success with this?

I am not able to run wsdl2ksoap successfully, as it seems to require a running webservice, and all I have at the current point in time is WSDL files. Likewise from reading the webpage, it seems to be a project in its initial stages, and not really ready for prime time.

JAX-WS wsimport I have not had a chance to try yet. However I am unsure if what it generates will work with ksoap2-android?

Question: How can I generate Java files from WSDL files, for use on Android with ksoap2-android SOAP client library?

Thanks a lot in advance.

(PS: Yes, the choice is SOAP, it is suboptimal for Android use, but I cannot change that.)

Answer

Bennya picture Bennya · Aug 2, 2012

I found this tool to auto generate wsdl to android code,

http://www.wsdl2code.com/example.aspx

Here is the code:

public void callWebService()    {
    SampleService srv1 = new SampleService();
    Request req = new Request();
    req.companyId = "1";
    req.userName = "userName";
    req.password = "pas";
    Response response =  srv1.ServiceSample(req);
}