KSoap SoapEnvelope bodyIn 和 getResponse() 问题

发布于 2024-11-06 01:54:50 字数 1755 浏览 0 评论 0原文

我正在使用以下代码通过soap 调用方法。它工作得很好。

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

但是,当我尝试在同一服务器中的其他一些方法中使用相同的代码时,它给出了 ClassCastException: org.ksoap2.SoapFault。如果我将行 SoapObject result = (SoapObject)soapEnvelope.getResponse(); 更改为 SoapObject result = (SoapObject)soapEnvelope.bodyIn;,则它可以正常工作。谁能告诉我这段代码的基本内容是什么,在哪里使用 bodyIn 以及在哪里使用 getResponse()

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()?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北座城市 2024-11-13 01:54:50

我使用以下代码来解决这个问题

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

,但我仍然不清楚为什么会发生这种情况。

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.

琉璃繁缕 2024-11-13 01:54:50

如果你去那里,你会看到主体没有序列化,而 get respose 给你的肥皂对象已经序列化。我的理解是,如果我错了,我很抱歉。 http://ksoap2.sourceforge.net/doc/api/org /ksoap2/SoapEnvelope.html#bodyIn

我遇到了同样的问题,因为我的网络服务给了我里面的 html,如果这也是你的问题,我建议你对 anser 进行编码网络服务端。

添加 try 和 catch

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文