Android里ksoap2调用WebService

之前jax-ws写的WebService的时候,Android下通过ksoap2调用的时候,

定义了soap_action=http://192.168.1.111:8080/hy/webservice/HyDataWrapperWSService

和soap_url = :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));

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/f654471f9ba4b1f4d78c6af4e5f1b5c7.html