开发者

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.o开发者_高级运维rg/";
    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()?


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.


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; }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜