{{ !articles[0].partner.isSponsoringArticle ? "Platinum" : "Portal" }} Partner

Android development tutorial: reading SOAP services!

I have found that in a lot of cases, applications need data ! What a discovery :-) . The next question of course is: Where do i get my data from. Most of the time you can gather your data from a existing source and in a lot of cases you can manipulate the data because you also control that side of the application. More often than you think you can get useful (free) data from existing sources that you don't own. Thats where webservices come in. Webservices can give you usefull data in a lot of formats.

In previous posts is explained how to make you own webservice in PHP and how to read and parse JSON or XML, but another (pretty big) format is SOAP. In this post we will see how you make a application that reads and parses SOAP data into a Android application!

So to sum up what we will do:

  1. Make a call to a SOAP webservice ( this one , yes hello world!)
  2. Read and parse the output
  3. Display the webserver message in the Activity

Well that's more then enough for 1 tutorial i guess :-) Lets get started.


First we will have to download the android SOAP client. ( called ksoap )

Note: At the time of writing this the most recent version is 2.5.4 .

  • Just click the most recent version
  • search for the jar file with dependencies.
  • download it by right clicking the link "Raw file"
  • then clicking "Save as ...".
  • Save it inside your project folder so you can link it easily.

Next: add the jar file to the project. ( Project properties -> Java build path -> Add JAR's )

Note: if you dont see the JAR file, click on your project in the Package explorer and press F5 to refresh your workspace.

Modifications in AndroidManifest.xml
In order to make soap calls on a web service exposed on the internet, additional permissions need to be added.

<uses-permission android:name="android.permission.INTERNET" />

 So now lets dive into the code! I commented the code to make sure you understand it.

private static String SOAP_ACTION = "http://tempuri.org/HelloWorld";

private static String NAMESPACE = "http://tempuri.org/";
private static String METHOD_NAME = "HelloWorld";

private static String URL = "http://bimbim.in/Sample/TestService.asmx?WSDL";

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

//Initialize soap request + add parameters
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

//Use this to add parameters

//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

//Needed to make the internet call
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
//this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
} catch (Exception e) {

// Get the SoapResult from the envelope body.
SoapObject result = (SoapObject)envelope.bodyIn;

if(result != null){
TextView t = (TextView)this.findViewById(R.id.resultbox);

//Get the first property and change the label text
t.setText("SOAP response:\n\n" + result.getProperty(0).toString());


Source code

Other info and examples

Here are some more examples that show the implementation of the ksoap library in combination with Android.




Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks