Search code examples
androidksoap2

ANDROID using ksop2 not getting the data


I have a problem while calling a webservice. I have a .NET web service on the server and the data is in Xml format i need to retreive value from there, and I am using KSOAP2 (2.5.4 jar file)in android 2.2 galaxy add-on. While running the program it is showing force close alert message.here is my code below please check it...

    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.app.Activity;
     import android.os.Bundle;
         import android.widget.TextView;

          public class SoapActivity extends Activity
   {
         private static String SOAP_ACTION = "http://tempuri.org/GetLabResults";

private static String NAMESPACE = "http://tempuri.org/ ";
private static String METHOD_NAME = "GetLabResults";

private static String URL = "http://192.168.1.19/MOBILETEST/service1.asmx?op=GetLabResults";


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    //Initialize soap request + add parameters
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
    request.addProperty("ReportDate","10-11-2011 10:10");


    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);

    // Make the soap call.
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    try {

        //this is the actual part that will call the webservice
        androidHttpTransport.call(SOAP_ACTION, envelope);        
    } catch (Exception e) {
        e.printStackTrace(); 
    }

    // Get the SoapResult from the envelope body.       
    SoapObject result = (SoapObject)envelope.bodyIn;
   // SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
   // String strRes = result.toString();


    if(result != null){
        TextView t = (TextView)this.findViewById(R.id.resultbox);
        t.setText("SOAP response:\n\n" + result.getProperty(0).toString());
    }

}

}


Solution

  • I have a few blog entries on this stuff. It may be of help to you as you try to work with kSOAP2 and Android.

    http://roderickbarnes.com/blog/category/technology/web-services-technology

    I hope this helps.