Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 666
Bjarke Freund-Hansen Avatar asked Feb 03 '12 07:02

Bjarke Freund-Hansen


2 Answers

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);
}
like image 77
Bennya Avatar answered Nov 11 '22 18:11

Bennya


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.

like image 11
robocik Avatar answered Nov 11 '22 18:11

robocik