Question

I am using the following code to call a method by soap. It is working perfectly.

private static final String SOAP_ACTION = "http://tempuri.org/GetAuthenticateUser";
    private static final String METHOD_NAME = "GetAuthenticateUser";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://stage.mysite.com/FinancialSnapshotService/Service.asmx?WSDL";
   // I have tried http://stage.mysite.com/FinancialSnapshotService/Service.asmx also

    public void getResults() {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("vstrUserID", "vk@gmail.com");
        request.addProperty("vstrPassword", "password");

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


        HttpTransportSE aht = new HttpTransportSE(URL);

        try {
            aht.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            aht.call(SOAP_ACTION, soapEnvelope);

            SoapObject result = (SoapObject) soapEnvelope.getResponse();


            Log.d("WS", String.valueOf(result));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

But when I tried the same code to use in some other methods in the same server, it gives ClassCastException: org.ksoap2.SoapFault. If I change the line SoapObject result = (SoapObject) soapEnvelope.getResponse(); to SoapObject result = (SoapObject)soapEnvelope.bodyIn;, it works perfectly. Can aanyone tell me what is basic of this code, where to use bodyIn and where to use getResponse()?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top