36

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

Community
  • 1
  • 1
Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135
  • Did you succeeded generating files from WSDL for android? – Jashan PJ May 08 '13 at 09:10
  • @Jashan: In the end we converted the 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, please let me know. :) – Bjarke Freund-Hansen May 08 '13 at 11:11
  • Thank you, sure if I found something I'll share.. :) – Jashan PJ May 08 '13 at 11:56
  • Actually now I am able to get the classes in eclipse converting the wsdl url, using the eclipse webservice client in the project menu. – Jashan PJ Aug 20 '13 at 12:00
  • @JashanPJ, i tried to use the eclipse convert menu, but it use some classes that Android dont have. Have you used it in a Android Project? – Marckaraujo Aug 20 '13 at 19:56
  • @Marckaraujo I too face the same issue some inconsistency error in the generated class files while using eclipse to convert. So I use the wsdl2code generator. It is working fine. – Jashan PJ Aug 21 '13 at 05:45
  • 1
    Hope is coming soon. We are working on a code generator for Android that uses the ksoap library. Right now it works against WCF services and we have written an easy to use Eclipse plugin + hotkeys that allow easy refreshing. We have had no issues with it so far and it saves hours upon hours of writing ksoap classes – Steven Combs Dec 01 '13 at 18:32
  • @BjarkeFreund-Hansen any updates on this? any advice you can give? – user1851212 Jan 02 '14 at 09:14
  • @user1851212: No, sorry, it currently seems to be a black whole. We are using some horror of thrown together scripts to generate some java code that is working for us, but it is nothing useful in general. Look at some of the newer answers perhaps, but I would not get my hopes up. – Bjarke Freund-Hansen Jan 06 '14 at 09:30
  • i am getting problem, during getting soap header in android: http://stackoverflow.com/questions/23284640/how-to-get-custom-message-headers-of-wcf-service-in-android – Horrorgoogle Apr 25 '14 at 10:58

5 Answers5

14

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);
}
dakshbhatt21
  • 3,558
  • 3
  • 31
  • 40
Bennya
  • 554
  • 5
  • 10
11

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.

Bjarke Freund-Hansen
  • 28,728
  • 25
  • 92
  • 135
  • @Bjarke, I am trying to implement wsdl on Android, do you pretend to sell your wsclient++`s license? I want to give it a try, wsdl2ksoap is not very good. – Marckaraujo Aug 20 '13 at 19:19
  • 1
    is this still so bothersome to do? or is there some nice tools now that we are in 2017 – sliders_alpha Aug 17 '17 at 08:32
  • @sliders_alpha No idea, I do not work on that project anymore. You could open a bonus on the question asking for a better solution given that some years have passed perhaps? – Bjarke Freund-Hansen Aug 17 '17 at 09:05
  • I'm sorry to bring such an old topic up. Have you tried using ksoup2 library? Does it do the job instead having to generate all these classes using a stub generator like the ones mentioned in the question? – Rany Sep 24 '20 at 16:31
  • @BjarkeFreund-Hansen I know you do not work on the project anymore but I have a question if you can answer it, please. Why you needed to generate java files from the WSDL files? Doesn't the ksoup2 library do the job? – Rany Sep 24 '20 at 16:50
  • @Rany It may. Probably ksoup2 was not around when I worked on it. If it works for you, great. – Bjarke Freund-Hansen Sep 25 '20 at 18:59
0

A bit late on this, but there is a ksoap2 stub generator under development, and I successfully used it to create the stubs.

http://ksoap2-stub-gen.sourceforge.net/

Also someone made it availabe as an online service (i.e. you give your WSDL's URL and the service will return a zip file containing the stubs).

http://www.davidgouveia.net/2011/04/online-stub-generator-for-android-applications-using-ksoap2/

András Szepesházi
  • 6,483
  • 5
  • 45
  • 59
  • 1
    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. – András Szepesházi Apr 23 '12 at 15:22
  • It does not seem to be available anymore. – Hong Apr 07 '13 at 22:16
  • @Hong just tested it and works, both the downloadable and the online version. – András Szepesházi Apr 09 '13 at 08:32
  • 2
    thanks for checking it. I am wondering if I am looking at a wrong page. I followed the first link and landed at: http://sourceforge.net/projects/ksoap2-stub-gen/files/ The page shows: "This project has no files" – Hong Apr 09 '13 at 12:25
  • 1
    @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: http://sourceforge.net/projects/ksoap2genstub/files/?source=navbar – András Szepesházi Apr 10 '13 at 14:40
  • I have a problem in using the downloaded version, the same as described here: http://stackoverflow.com/questions/5937218/web-services-stub-generation-android – Hong May 16 '13 at 11:50
  • @none If you also read the comments, you can see that the download location has been moved to http://sourceforge.net/projects/ksoap2genstub/files/?source=navbar – András Szepesházi Nov 29 '13 at 13:09
0

I have used for iPhone too some auto-generated classes I wanted to see here too.

wsdl2code is one of the similar what I have used at iPhone. Give an url with wsdl file you will get some classes to download. For me the hardest part it was to download the required parts. It took more than 2 minutes of searching :) ksoap2-android-assembly-3.0.0-jar-with-dependencies.jar needed to download ad drag-and-drop to ADT ( Eclipse) . It is super easy, especially if you have used the counterpart at iPhone. - a similar tool I have used.

However in my case I am not happy at all with the solution, because I see I am using cannon, a set of cannons to shot a sparrow. In my case it should be used a HTTP Post and not including dependencies from other libraries.

To be honest I don't care to much, because once the server side believe we have unlimited battery power and unlimited data plan, than I close my eyes and I don't care about marshaling-unmarshaling overheads, which use the CPU ( battery ) increase the data transmitted over network.

In worse case it should be a JSON + HTTP POST not SOAP for mobiles...

I would suggest to talk at server side guys and explain for they why it will not good if they do 2 click on wizards and we do other click on forms to get the generated code. At least while the application is not a huge one, even than should be budget to optimise for mobile a few interfaces implementations.

0

I use Apache CXF tool just to create dto, and i wrote a class to perform a basic unmarshalling based on name of elements

zime
  • 171
  • 1
  • 5