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 http://faxregistration.com/sfaxws/sfaxapi.asmx

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 http://www.tempuri.org and no luck


package com.android.sfaxservice;

import android.app.Activity;
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. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
private static final String SOAP_ACTION = "http://faxregistration.com/sfaxws/SayHello";
private static final String SOAP_METHOD = "SayHello";
private static final String NAMESPACE = "http://faxregistration.com/sfaxws/";
private static final String URL = "http://faxregistration.com/SfaxWS/sfaxapi.asmx";
public void GetData()
{
SoapObject request = new SoapObject(NAMESPACE, SOAP_METHOD);

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

AndroidHttpTransport aht = new AndroidHttpTransport(URL);
@SuppressWarnings("unused")
Object result;
try
{
aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

aht.call(SOAP_ACTION, envelope);
result = (Object)envelope.getResponse();

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


}

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

Top

Re: calling web service with Ksoap2

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

Hi,

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 = ""+ MyLocationListener.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;
      envelope.setOutputSoapObject(request);
      AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);   
         
      try {
         httpTransport.call(SOAP_ACTION, envelope); // Parse Response
         SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
      } catch (Exception e){
         e.printStackTrace();
      }   
   }

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

Top

Return to Other Coding-Problems

Who is online

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