calling web service with Ksoap2

Put your problem here if it does not fit any of the other categories.

calling web service with Ksoap2

Postby efrylink » Mon Feb 07, 2011 10:13 pm

Have reviewed the forum but have not been able to get this code to work properly. New to this and was wondering if someone can help. Thanks in advance

we have a dotNet web service located at

The SayHello method requires a request response in xml that also has the userid and password passed

I have the following code trying to make work on the Android
I have also added the permissions in the manifest file and added the ksoap2 jar files as an external jar in the build paths.

I have also tried changing the soap definitions to the and no luck


import android.os.Bundle;
import android.widget.TextView;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;

public class app extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
private static final String SOAP_ACTION = "";
private static final String SOAP_METHOD = "SayHello";
private static final String NAMESPACE = "";
private static final String URL = "";
public void GetData()
SoapObject request = new SoapObject(NAMESPACE, SOAP_METHOD);

request.addProperty("UserId", "gfry");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;

AndroidHttpTransport aht = new AndroidHttpTransport(URL);
Object result;
aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");, envelope);
result = (Object)envelope.getResponse();

java.lang.String receivedString = (String)envelope.getResponse();
if (receivedString == "Hello From Sfax Web Service");
TextView tv = (TextView)findViewById(;
tv.setText("Hello from Sfax Web Service");
} catch (Exception ex) {
result = null;


Posts: 2
Joined: Sat Feb 05, 2011 12:34 am


Re: calling web service with Ksoap2

Postby Chitra » Tue Feb 08, 2011 1:59 pm


Just try on this,

Code: Select all
private static final String NAMESPACE = "urn:...............";
private static final String UPDATE_VERSION = "tns:updateversion";

//Here is my UpdateProfileLocation with KSOAP
public void updateProfileLocation() {
      String lat = ""+;
      String lon = ""+ MyLocationListener.lon;
      SoapObject request = new SoapObject(NAMESPACE,UPDATELOCATION_METHOD_NAME);      
      Cell cell = DeviceUtil.getCellInfo();
                //Here,If u want to pass any params
      String startTime = DateTimeUtil.DateTime();
      request.addProperty("latitude", lat);
      request.addProperty("longitude", lon);
      request.addProperty("mcc", "" + cell.getMcc());
      request.addProperty("mnc", "" + cell.getMnc());
      request.addProperty("lac", "" + cell.getCellLAC());
      request.addProperty("cellid", "" + cell.getCellID());
      request.addProperty("startTime", startTime);
      request.addProperty("token", code);

      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
      envelope.dotNet = true;
      AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);   
      try {, envelope); // Parse Response
         SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
      } catch (Exception e){

User avatar
Master Developer
Master Developer
Posts: 213
Joined: Mon Mar 01, 2010 7:59 am
Location: Bangalore


Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 6 guests