Android ksoap2 tutorial


Android Web Service Access Using ksoap2.

Within this tutorial I am likely to demonstrate the way we can access an easy java web service utilizing an Android application. To accomplish this tutorial you’ll need some understanding about dynamic web service projects in Eclipse & about ksoap2.

Following may be the sample java code for web service class. Deploy this web service on Tomcat server at local host. To apply this web service follow both of these posts Publish 1 Publish 2

public class PrintMsg

Following may be the code which we are able to use within Android application to invoke used web service.


import org.ksoap2.SoapEnvelope
import org.ksoap2.serialization.SoapObject
import org.ksoap2.serialization.SoapPrimitive
import org.ksoap2.serialization.SoapSerializationEnvelope
import org.ksoap2.transport.HttpTransportSE
import android.widget.TextView

import android.application.Activity
import android.os.Bundle

public class WSClientActivity stretches Activity Cleaning soap_ACTION = “”
private static final String METHOD_Title = “sayHello”
private static final String NAMESPACE = “”
private static final String URL = “”
/** Known as once the activity is first produced. */
public void onCreate(Bundle savedInstanceState) primary)

SoapObject request = new SoapObject(NAMESPACE, METHOD_Title)

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11)


HttpTransportSE ht = new HttpTransportSE(URL)
try Cleaning soap_ACTION, envelope)
SoapPrimitive response = (SoapPrimitive)envelope.getResponse()

TextView tv = new TextView(this)
tv.setText(“Message :”+response.toString())

catch (Exception e)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>