KSoap SoapEnvelope bodyIn 和 getResponse() 问题
我正在使用以下代码通过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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用以下代码来解决这个问题
,但我仍然不清楚为什么会发生这种情况。
I used the following code to solve this prob
But still it is not clear for me why it is happening.
如果你去那里,你会看到主体没有序列化,而 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;
}