Android Wsdl/Soap Service Client

Android WSDL/SOAP service client

Android doesn't come with SOAP library. However, you can download 3rd party library here:

https://github.com/simpligility/ksoap2-android

If you need help using it, you might find this thread helpful:

How to call a .NET Webservice from Android using KSOAP2?

Call a soap webservice in android

You can do any UI related operations in doInBackGround, So move them in onPostExecute methnod.

Because doInBackGround is not a UI thread. Please read AsyncTask Document carefully. Whatever is the data you are returning from doInBackGround, it is being taken as input to onPostExecute.

So change your code as follows,

    private class AsyncCallWS extends AsyncTask<Void, Void, Void> {

@Override
protected void onPreExecute() {
Log.i(TAG, "onPreExecute");
}

@Override
protected String[] doInBackground(Void... params) {
Log.i(TAG, "doInBackground");
String[] data = sendRequest();
return data;
}

@Override
protected void onPostExecute(String[] result) {
Log.i(TAG, "onPostExecute");
if(result != null && result.length > 0){
textResult.setText( results[0]);
}
}

}

private String[] sendRequest(){
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

//SoapObject
request.addProperty("@CountryName", "SPAIN");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);

androidHttpTransport = new HttpTransportSE(URL);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope);
resultsRequestSOAP = envelope.getResponse();
String[] results = (String[]) resultsRequestSOAP;
}
catch (Exception aE)
{
aE.printStackTrace ();
}
}

Store WSDL file in Android Project and Parse this to create Retrofit API

The WSDL file is a webservice file, therefore it should seat on your server, you can deploy such webservices using Tomcat or JBoss applications. So you don't want to 'store' the wsdl file in your application, it should seat on your server. And you shouldn't 'parse' a wsdl file, its function is moving data from your client to server and viceversa. If doing what you are suggesting was possible(parsing with ksoap to create my api with retrofit), then it would be a bad programming practise due to redudancy. Retrofit works similarly to soap difference being retrofit makes use of JSON while SOAP makes use of XML. Try looking at my answer here Call a soap webservice in android to understand how android interacts with soap webservice

Implementing SOAP api in Android

SOAP is XML protocol for describing objects. While it works over many different protocols, using it over HTTP is basically XML over HTTP with a few extras settings required (usually HTTP Headers) to make it work.

WSDL is metadata that is used to describe the web services hosted on a given endpoint well enough that it is machine readable. Many client generation libraries for Web Services exist that can create a client that can call the web services.

If you can already call the web service endpoint and get a response using the apache client, then you can more or less ignore WSDL and all that stuff. You are doing enough SOAP to invoke the Web Service.

Once you get the response, deserialise / parse the XML using your favourite XML library.

Android has a couple built in, you can do it the old fashioned way with the DOM, use a library built on top of the DOM like dom4j or even the really old fashioned way with SAX.

For really big XML messages you want to use a streaming parser like Stax, but generally the DOM is easier to get going.

Finally write your own and make sure you add an answer to this SO Question :)

How to call a SOAP web service on Android

Android does not provide any sort of SOAP library. You can either write your own, or use something like kSOAP 2. As you note, others have been able to compile and use kSOAP2 in their own projects, but I haven't had to.

Google has shown, to date, little interest in adding a SOAP library to Android. My suspicion for this is that they'd rather support the current trends in Web Services toward REST-based services, and using JSON as a data encapsulation format. Or, using XMPP for messaging. But that is just conjecture.

XML-based web services are a slightly non-trivial task on Android at this time. Not knowing NetBeans, I can't speak to the tools available there, but I agree that a better library should be available. It is possible that the XmlPullParser will save you from using SAX, but I don't know much about that.

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

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.



Related Topics



Leave a reply



Submit