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

38,742

Solution 1

My conclusion after quite a bit of researching is that there is no such (mature) tool available, unfortunately. Neither AXIS2 or JAX-WS will work on Android, and WSDL2ksoap is simply too immature for any real use.

However there is a proprietary tool called wsclient++ that will do the job really well. (Read update below, when put to real use, it does not stand the distance at all.) It does not use the ksoap2-android client library, it has it's own.

The client library is a bit crude as it has a hard dependency on the http transport, making (unit) testing a bit complicated. But it can be modified quite easily to allow DI, as the source is available in the distributed jar file.

The wsdl to java generator however works just perfect, and will save us tons of time.

Update After working with wsclient++ for a while, it is clear that the generated classes are really crude, and does not handle error cases at all. (Every method declares throws Exception).

We are no longer using wsclient++, and I would not recommend anyone to use it! We have not really found any working alternative, unfortunately. :/

In the end we converted our WSDL files using AXIS2, and then wrote a bunch of custom script to strip and transform the generated java files to something that will build on android using ksoap2-android library. Very hackish, and needs tons of manual labor to run. Unfortunately. If you find a better way, or one comes up, please provide a new answer.

Solution 2

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);
}

Solution 3

I had similar situation (I had only wsdl file without working webservice). I've used

http://easywsdl.com/

to generate classes for android without any problem. This tool uses ksoap library. The great thing with this tool is that it supports WCF extensions and types like data contract with IsReference attribute or Guid.

Share:
38,742
Bjarke Freund-Hansen
Author by

Bjarke Freund-Hansen

Updated on December 11, 2020

Comments

  • Bjarke Freund-Hansen
    Bjarke Freund-Hansen over 3 years

    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.)

  • András Szepesházi
    András Szepesházi about 12 years
    I do have to admit, the current version (as of 2012.04.23), is quite lame - it won't be able to properly generate stubs for some complex types and arrays.
  • Hong
    Hong about 11 years
    It does not seem to be available anymore.
  • András Szepesházi
    András Szepesházi about 11 years
    @Hong just tested it and works, both the downloadable and the online version.
  • Hong
    Hong about 11 years
    thanks for checking it. I am wondering if I am looking at a wrong page. I followed the first link and landed at: sourceforge.net/projects/ksoap2-stub-gen/files The page shows: "This project has no files"
  • András Szepesházi
    András Szepesházi about 11 years
    @Hong You're right, the files are gone (I just checked the project main page). The online stub generator accessible via the second link still works (I tested that one yesterday). Also, downloadable version seems to be moved to here: sourceforge.net/projects/ksoap2genstub/files/?source=navbar
  • mutkan
    mutkan about 11 years
    but this is only for .net web services
  • Bennya
    Bennya about 11 years
    it works great also with other web services, beside minor changes like soap method name
  • Hong
    Hong about 11 years
    I have a problem in using the downloaded version, the same as described here: stackoverflow.com/questions/5937218/…
  • MikeS
    MikeS almost 11 years
    That tool is pretty incredible and saved me a ton of time. I am a fan.
  • András Szepesházi
    András Szepesházi over 10 years
    @none If you also read the comments, you can see that the download location has been moved to sourceforge.net/projects/ksoap2genstub/files/?source=navbar
  • SergeyYu
    SergeyYu over 5 years
    It isn't available now
  • Alex
    Alex over 5 years
    @SergeyUr That's what's bothering me as well. Changed the WebService and would need to regenerate the Android classes. Did you find a good alternative yet?
  • Arefe
    Arefe about 4 years
    I second that they provide the quality code for the Java client in our project.