之前jax-ws写的WebService的时候,android下通过ksoap2调用的时候,
定义了soap_action=http://192.168.1.111:8080/hy/webservice/HyDataWrapperWSService
和soap_url = http://192.168.1.111:8080/hy/webservice/HyDataWrapperWSService?wsdl
call的时候androidHttpTransport.call(soap_action, envelope);要把soap_action传进去。
后来用cxf改写了WebService了,android一直报错。
java.lang.ClassCastException: org.ksoap2.SoapFault。不知道愿意。
然后看到网上有人call的时候,soap_action用的是null。
androidHttpTransport.call(null, envelope);
结果却正常调用下去了。不知道为什么。
SoapObject request = new SoapObject(NAMESPACE, methodname);
// 调用的参数
Iterator it = parameter.keySet().iterator();
while (it.hasNext()) {
String key = it.next().toString();
request.addProperty(key, parameter.get(key));
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
try {
// 调用SOAP
HttpTransportSE androidHttpTransport = new HttpTransportSE(url,
10000);
androidHttpTransport.debug = true;
//
//androidHttpTransport.call(soap_action, envelope);
androidHttpTransport.call(null, envelope);
Log.d("invoke", "0");
// 获得SOAP调用的结果
SoapObject result = (SoapObject) envelope.bodyIn;
Log.d("invoke", "1");
if (result != null) {
response = result.getProperty(0).toString();
}
Log.d("invoke", "2");
return response;
} catch (Exception e) {
e.printStackTrace();
Log.d("Exception", "timeout");
throw new ApplicationException(e,
context.getString(R.string.soap_error));
}

本文探讨了使用KSOAP2在Android环境下调用由JAX-WS和CXF编写的WebService时遇到的问题。特别是针对SOAP_ACTION设置为null能够成功调用的情况进行了分析。
21万+

被折叠的 条评论
为什么被折叠?



