0

I need to access a .NET webservice in my android application. I did it using the ksoap2 library. I set up the connection and everything but I am not able to get the data back from the service. The service is supposed to send back a set of values. How do I catch those values ?

This is my java code to access the web-service.

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope = 
        new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);


    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

    try {
        androidHttpTransport.call(SOAP_ACTION, envelope);

        //code to get back the values here. This is my doubt. 
                    //What code do I write here to get the values from the service ?

    } catch (Exception e) {
        e.printStackTrace();
    }

And this is the format of the response from the service.

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetControlResponse xmlns="http://tempuri.org/">
      <GetControlResult>
    <Id>int</Id>
    <Belt>boolean</Belt>
    <Lighting>boolean</Lighting>
    <AutoSpeed>boolean</AutoSpeed>
    <ManualSpeed>short</ManualSpeed>
    <Projector>boolean</Projector>
    <ProjecterPattern>short</ProjecterPattern>
  </GetControlResult>
</GetControlResponse>
 </soap:Body>
</soap:Envelope>
Swayam
  • 16,294
  • 14
  • 64
  • 102

2 Answers2

2

Check this one. Its a good tutorial for access ksoap2 web service in android.

Chrishan
  • 4,076
  • 7
  • 48
  • 67
  • This tutorial uses a service that returns only ONE value. I need to receive multiple values from my service. I cant do response.toString() as my response would consists of various values. – Swayam Jun 07 '12 at 10:16
0

You can done this work by using this code:

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
System.out.println(request);
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE httpTransportSE = new HttpTransportSE(URL);
httpTransportSE.debug = true;
try {
    httpTransportSE.call(SOAP_ACTION, envelope);

} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (XmlPullParserException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

String ss = httpTransportSE.requestDump;
Log.d("Result", ss);
System.out.println(ss);
Alex K
  • 22,315
  • 19
  • 108
  • 236