1

I want to consume the C# web service from android application.. In my project I'm using SOAP in request for taking data back, with kSOAP 2 library, but when I'm doing "invoke" on my ......asmx , C# backend, with this code

     SoapObject getWeather(String customerNumber) throws Exception {
    PropertyInfo property = new PropertyInfo();
    property.setName("LicenseId");
    property.setValue("8BEBFB9F-D9C9-4880-9225-AB50976F2975");
    property.setType(String.class);

    SoapObject request = new SoapObject("http://mobilesuite365.com",
            "GetCustomers");
    request.addProperty(property);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    // It seems that it is a .NET Web service because it doesn't work
    // without next line


    HttpTransportSE transport = new HttpTransportSE(
            "http://www.mobilesuite365.net/app2/getdata.asmx");
    transport.debug = true;
    transport.call("http://mobilesuite365.com/GetCustomers", envelope);



    return (SoapObject) envelope.getResponse();

I'm getting this error "XmlPullParserException: Unexpected token (position:TEXT" , because response comes like JSON, but ksoap can handle xml format..

how to take response and handle information from response and use it in my app?

Thanks for help

android.dk
  • 19
  • 1
  • 8

1 Answers1

0

Try using a SoapPrimitive in stead of a SoapObject and convert it to String type

String response = "";
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
if (result != null)
    response = result.toString();

return response;

After that you should use something like Gson to parse the JSON you received.

the-ginger-geek
  • 7,041
  • 4
  • 27
  • 45