Published On: August 3rd, 20164.8 min read

Contributor: Abidur Rahman

Though SOAP based web-services are rare in these days, but there are lots of old companies whose web-services are still SOAP-based. If anyone wants to consume those services from Android, it is very important to know the procedure of consuming SOAP-based webservice. There are lots of tutorials on consuming RESTful web-services with better explanation, but there are a few tutorials on consuming SOAP web-services with a clear explanation.

In this article, we will learn how to consume SOAP web services from Android. Before starting code, we have to collect some information:

  • URL
  • Parameter List
  • Request XML/ SOAP_BODY/ SOAP_MESSAGE (for Nested Parameters and Multiple Namespaces)

Now, the question is how can we get these information? if your client or service provider give you all the information, you won’t need anything. But if they don’t, then follow the process given below:

Suppose, you have to consume the data from this service:

This is the URL!!

Click on it, you can see a link named “Service Description” and a list of Method Name(s). So, we can get the METHOD_NAMEs from here.
Now, click on the “Service Description”.

abid's blog pic 1

You can see the NAME_SPACE there. For nested parameters, there can be multiple namespaces. So, a question may arise. “How can I find other namespaces?”. Okay!! I will discuss it later.

abid's blog pic 2

You can see the SOAP_ACTIONs here depending on the METHOD_NAME. So, be careful to choose the SOAP_ACTION!! You can also get the Parameter List here depending on the METHOD_NAME.

Okay we have got all (not all for the complex web services!!!) the information to consume soap web services from Android. Let’s code !!!

Sample Project

Start a new Android project and configure it as you please. Feel free to use your favorite IDE, but for this tutorial I’ll be using Android Studio.

In the project’s manifest file, you need to specify that the application is allowed to connect to the internet. So, add:

We will use a library named “kSOAP” which is an elegant, lightweight, and efficient SOAP client library. The library is open source, easy to use, and it will save you from the hassle of coding a custom parser.

To sync kSOAP library with your project, add these lines (bolded text) to your app’s build.gradle file:

apply plugin: ''

android {
 compileSdkVersion 23
 buildToolsVersion "23.0.2"

defaultConfig {
 applicationId "com.nascenia.soap"
 minSdkVersion 15
 targetSdkVersion 23
 versionCode 1
 versionName "1.0"
 buildTypes {
 release {
 minifyEnabled false
 proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
 repositories {
 maven { url '' }

dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 compile ''
 compile ''

Now, set SOAP_ACTION, METHOD_NAME and NAMESPACE variables in your activity class:


public class MainActivity extends AppCompatActivity {

   private static final String SOAP_ACTION = "";
   private static final String METHOD_NAME = "CelsiusToFahrenheit";
   private static final String NAMESPACE = "";

   protected void onCreate(Bundle savedInstanceState) {

Now, create an AsyncTask, and add these doInBackground()’s codes to your doInBackground() method.

private class myAsyncTask extends AsyncTask {

   protected Void doInBackground(Void... params) {

     String URL = "";

     //for linear parameter
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
     request.addProperty("Celsius", "48"); // adding method property here serially

     SoapSerializationEnvelope envelope = new      SoapSerializationEnvelope(SoapEnvelope.VER11);
     envelope.implicitTypes = true;
     envelope.dotNet = true;
     HttpTransportSE httpTransport = new HttpTransportSE(URL);
     httpTransport.debug = true;

     try {, envelope);
     } catch (HttpResponseException e) {
        // TODO Auto-generated catch block
        Log.e("HTTPLOG", e.getMessage());
     } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.e("IOLOG", e.getMessage());
     } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        Log.e("XMLLOG", e.getMessage());
     } //send request

     Object  result = null;
     try {
        result = (Object )envelope.getResponse();
        Log.i("RESPONSE",String.valueOf(result)); // see output in the console
     } catch (SoapFault e) {
        // TODO Auto-generated catch block
        Log.e("SOAPLOG", e.getMessage());
     return null;

Now execute your AsyncTask from onCreate method to see the output in the console.

protected void onCreate(Bundle savedInstanceState) {

   myAsyncTask myRequest = new myAsyncTask();

For Nested Parameters and Multiple Namespaces

For the complex web services, we need SOAP_BODY/ SOAP_MESSAGE/ REQUEST_XML.

There is an elegant and efficient SOAP browser online:

Copy the URL of your web service, and add “?wsdl” at the end of the URL and then browse.
You should see the METHOD_NAME on the left side. Click on one of the METHOD_NAMEs which you want. You will see REQUEST_XML there. It is the SOAP_BODY or SOAP_MESSGAE.

Consuming SOAP web services from Android

  • NAMESPACE name – Value of “xmlns:ns1”. If there are multiple namespaces, it will be indicated by ns1, ns2 and so on.
  • METHOD_NAME – indicated by the 1st arrow.
  • Parameter Name – indicated by the 2nd arrow.




// for nested parameters and multiple namespaces.
SoapObject request = new SoapObject(NAMESPACE1, METHOD_NAME);
PropertyInfo p = new PropertyInfo();

SoapObject selection = new SoapObject(NAMESPACE1,"selection");
PropertyInfo EndDate = new PropertyInfo();

PropertyInfo StartDate = new PropertyInfo();
StartDate .setType(PropertyInfo.STRING_CLASS);
StartDate .setValue("value");



I hope that helps. Please check some other blogs on web and mobile app development.

Share it, Choose Your Platform!

More to Explore

The Quest for Knowledge Continues. Fuel Your Curiosity.