Working With SOAP Web Service Through Android

This article will help you call a SOAP web service in the simplest way. We will pass a parameter to the web service and will receive the result. In this tutorial, I have used w3school’s TempConvert web service. It’s publicly available to everyone to use this web service.

Before we begin with the code, we would have to download the KSOAP library for our android project. The library used in this article is ksoap2-android-assembly-2.6.1-jar-with-dependencies.jar.

To include this library in your project – Right Click on the project> Select Properties> Java Build Path> Libraries Tab> Add External JARs and then select your downloaded library. Now, on the Order and Export Tab checkmark the checkbox for this library.

The Code

The web service has two methods i.e CelsiusToFahrenheit and FahrenheitToCelsius so we have to design a simple android activity for the same.

Layout – main.xml

android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >

<TextView
android:id=”@+id/textView1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”TempConvert”
android:layout_gravity=”center”
android:layout_marginBottom=”20dp”
android:textAppearance=”?android:attr/textAppearanceLarge” />

<TextView
android:id=”@+id/textView2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Input:” />

<EditText
android:id=”@+id/editText1″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:inputType=”text”
android:layout_marginBottom=”5dp”
android:ems=”10″ >

<TextView
android:id=”@+id/textView3″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Convert To:” />

android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>

<RadioButton
android:id=”@+id/radioButton1″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Celsius” />

<RadioButton
android:id=”@+id/radioButton2″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_marginBottom=”5dp”
android:text=”Fahrenheit” />

<TextView
android:id=”@+id/textView4″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”Result:” />

<EditText
android:id=”@+id/editText2″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:inputType=”text”
android:editable=”false”
android:ems=”10″ />

Follow me!
Latest posts by Imran Saifi (see all)

Leave a Comment