我正在使用以下代码调用 webservice。我对在 android 中使用 Ksoap 非常陌生。我已经设法调用 1 个 web 服务并解析数据。但是当我使用相同的代码时(我已经更改了参数 soapaction、命名空间......)解析另一个 web 服务我得到以下错误。我设置了 Soapaction、命名空间..的参数都设置正确。我做了一个调用网络服务的方法;
public void showdetails()
{
String result = "";
SoapObject resultRequestSOAP = null;
SoapObject resultRequestSOAPbody =null;
SoapObject request = new SoapObject(NAMESPACE_Transaction, METHOD_NAME_Transaction);
request.addProperty("TransactionType","payment");
request.addProperty("MerchantId","543");
request.addProperty("amount","0.02");
request.addProperty("CCNo","4111111111111111");
request.addProperty("CCExpMonth","11");
request.addProperty("CCExpYear","22");
request.addProperty("Source","aa");
request.addProperty("profileId","788");
//request.addProperty("ClientIPAddress","120.138.99.2");
//request.addProperty("GEOCode","0.000000,0.000000");
//Some more fields that are not mandatory
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_Transaction);
androidHttpTransport.debug = true;
try
{
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding= \"UTF-8\"?>");
androidHttpTransport.call(SOAP_ACTION_Transaction, envelope);
String requestDumpString = androidHttpTransport.requestDump;
System.out.println("requestDump : " + requestDumpString);
resultRequestSOAP = (SoapObject) envelope.bodyIn;
// resultRequestSOAP = (SoapObject) envelope.getResponse(); // Output received
result = resultRequestSOAP.toString(); // Result string
System.out.println("OUTPUT : " + result);
if (envelope.bodyIn instanceof SoapFault)
{
String str= ((SoapFault) envelope.bodyIn).faultstring;
Log.i("TAG", str);
} else {
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
Log.d("WS", String.valueOf(resultsRequestSOAP));
}
} catch (Exception e) {
e.printStackTrace();
}
}
我在以下声明中遇到了问题:
resultRequestSOAP = (SoapObject) envelope.bodyIn;
错误如下:
java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject
有人可以在这个问题上帮助我吗?我已经搜索了很多但无法解决它。当我调用其他网络服务时,它会返回我的信封.bodyIn。