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

5

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

Ventriculus answered 3/2, 2012 at 7:14 Comment(10)
Did you succeeded generating files from WSDL for android?Peat
@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. :)Ventriculus
Thank you, sure if I found something I'll share.. :)Peat
Actually now I am able to get the classes in eclipse converting the wsdl url, using the eclipse webservice client in the project menu.Peat
@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?Tonality
@Tonality 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.Peat
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 classesMacrae
@BjarkeFreund-Hansen any updates on this? any advice you can give?Gudrun
@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.Ventriculus
i am getting problem, during getting soap header in android: #23285140Latta
V
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.

Ventriculus answered 14/2, 2012 at 7:59 Comment(6)
@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.Tonality
is this still so bothersome to do? or is there some nice tools now that we are in 2017Sharla
@Sharla 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?Ventriculus
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?Machree
@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?Machree
@Machree It may. Probably ksoup2 was not around when I worked on it. If it works for you, great.Ventriculus
E
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);
}
Eaglestone answered 2/8, 2012 at 12:1 Comment(5)
but this is only for .net web servicesPolymath
it works great also with other web services, beside minor changes like soap method nameEaglestone
That tool is pretty incredible and saved me a ton of time. I am a fan.Confucianism
It isn't available nowWentworth
@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?Pika
V
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.

Ventriculus answered 14/2, 2012 at 7:59 Comment(6)
@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.Tonality
is this still so bothersome to do? or is there some nice tools now that we are in 2017Sharla
@Sharla 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?Ventriculus
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?Machree
@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?Machree
@Machree It may. Probably ksoup2 was not around when I worked on it. If it works for you, great.Ventriculus
T
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

Trauner answered 9/3, 2012 at 13:46 Comment(0)
H
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/

Hereupon answered 18/4, 2012 at 16:17 Comment(7)
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.Attah
It does not seem to be available anymore.Freeliving
@Freeliving just tested it and works, both the downloadable and the online version.Attah
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"Freeliving
@Freeliving 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=navbarAttah
I have a problem in using the downloaded version, the same as described here: #5937718Freeliving
@none If you also read the comments, you can see that the download location has been moved to sourceforge.net/projects/ksoap2genstub/files/?source=navbarAttah
B
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.

Bringingup answered 21/10, 2013 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.