Android ksoap2 tutorial

Android-ksoap-tutorial-featured.jpg

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

package com.android.ws
public class PrintMsg

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

package com.androidclient.ws

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 = “http://ws.android.com/sayHello”
private static final String METHOD_Title = “sayHello”
private static final String NAMESPACE = “http://ws.android.com/”
private static final String URL = “http://175.157.229.119:8080/AndroidWSTest/services/PrintMsg?wsdl”
/** Known as once the activity is first produced. */
@Override
public void onCreate(Bundle savedInstanceState) primary)

SoapObject request = new SoapObject(NAMESPACE, METHOD_Title)

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11)

envelope.setOutputSoapObject(request)

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())
setContentView(tv)

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>