dev_android
dev_android

Reputation: 8818

KSoap soapEnvelope bodyIn and getResponse() problem

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", "[email protected]");
        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()?

Upvotes: 1

Views: 7568

Answers (2)

dev_android
dev_android

Reputation: 8818

I used the following code to solve this prob

try{
                result = (SoapObject) soapEnvelope.getResponse();
            }catch (ClassCastException e) {
                result = (SoapObject)soapEnvelope.bodyIn; 
            }

But still it is not clear for me why it is happening.

Upvotes: 2

PedroAGSantos
PedroAGSantos

Reputation: 2346

If you go there you see the body in is not serialized while get respose give you soapobject already serilized. Is what I undertand on that i'm sorry if i'm wrong. http://ksoap2.sourceforge.net/doc/api/org/ksoap2/SoapEnvelope.html#bodyIn

I had same problem because my webservice was giving me html inside if is that your problem too i recomend you to encode the anser on the webservice side.

add try and catch

catch (SoapFault e) { SoapObject result = soapEnvelope.BodyIn; }

Upvotes: 0

Related Questions