Mohamed
Mohamed

Reputation: 567

android SoapSerializationEnvelope KSoap issue

I have a C# webservice that is returning a JSON response. On IE my sample return is

{"102":{"customerName":"asfd","address":"","orderList":{"3":{"8":1,"6":1}}},"103":{"customerName":"hose","address":"Road Jamica Queens","orderList":{"4":{"15":1}}}}

However when access the same webservice from android I am getting a Java exception.

Unexpected token (position:TEXT {"102":{"custome...@1:194 in java.io.InputStreamReader@29041cbd)

Also the responsedump is adding XML to the end and thus causing the issue.

 responseDump:{"102":{"customerName":"asfd","address":"","orderList":{"3":{"8":1,"6":1}}},"103":{"customerName":"hose","address":"Road Jamica Queens","orderList":{"4":{"15":1}}}}<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><getInvoicesResponse xmlns="http://tempuri.org/" /></soap:Body></soap:Envelope>

public class webServiecHandler  extends AsyncTask<String, Void, String> {

    /**
     * Variable Decleration................
     *
     */
    String namespace = "http://tempuri.org/";
    private String url = "http://sample/WebService1.asmx";

    String SOAP_ACTION;
    SoapObject request = null, objMessages = null;
    SoapSerializationEnvelope envelope;




    /**
     * Set Envelope
     */
    protected void SetEnvelope() {

        try {

            // Creating SOAP envelope
            envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

            //You can comment that line if your web service is not .NET one.
            envelope.dotNet = true;


            envelope.setOutputSoapObject(request);


        } catch (Exception e) {
            System.out.println("Soap Exception---->>>" + e.toString());
        }
    }


    public String doInBackground(String ... params)
    {

        try {
            SOAP_ACTION = namespace + "getInvoices";

            //Adding values to request object
            request = new SoapObject(namespace, "getInvoices");
            HttpTransportSE androidHttpTransport = new HttpTransportSE(url);


            SetEnvelope();

            try {

                //SOAP calling webservice

                androidHttpTransport.call(SOAP_ACTION, envelope);

                SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
               String result = "";
                return result;

            } catch (Exception e) {
                Log.d("returnedClass", e.getMessage());
                return e.toString();
            }
        } catch (Exception e) {
            // TODO: handle exception
            return e.toString();
        }


    }


    /************************************/
}

Upvotes: 1

Views: 42

Answers (0)

Related Questions