soap2-android
官网地址
https://simpligility.github.io/ksoap2-android/index.html
发行版本
https://oss.sonatype.org/content/repositories/ksoap2-android-releases/
- 切记所需要的文件是在
com>google>code>ksoap2-android>ksoap2-android-assembly
- 选择最新版本,然后使用-with-dependencies.jar包
最新版本
调用WebService取得数据
初使化soap
private final String serviceNameSapce = "http://192.168.20.135:8090/";
private final String serviceUrl = "http://192.168.20.135:8090/TestService.asmx";
private final String serviceMethod = "HelloWorld";
private final String serviceAction = "http://192.168.20.135:8090/HelloWorld";
private String strResult = "";
调用
new Thread(new Runnable() {
@Override
public void run() {
//创建HttpTransportSE传输对象,serviceUrl是webservice提供服务的url
HttpTransportSE httpTransportSE = new HttpTransportSE(serviceUrl);
//使用SOAP1.1协议创建Envelop对象,根据服务端WebService的版本号设置SOAP协议的版本号
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//实例化SoapObject对象,第一个参数表示命名空间,第二个参数表示要调用的WebService方法名
SoapObject soapObject= new SoapObject(serviceNameSapce, serviceMethod);
//设置调用方法的参数值,如果没有参数,可以省略
//soapObject.addProperty("theCityCode", cityName);
envelope.bodyOut = soapObject;
envelope.dotNet = true;
try {
//调用webservice
httpTransportSE.call(serviceAction, envelope);
//获取服务器响应返回的SOAP消息
if(envelope.getResponse() != null){
SoapObject resultSoap = (SoapObject)envelope.bodyIn;
strResult = resultSoap.getProperty(0).toString();
mHandler.sendEmptyMessage(0x002);
}
} catch (IOException | XmlPullParserException e) {
e.printStackTrace();
}
}
}).start();
来源:oschina
链接:https://my.oschina.net/u/4265622/blog/4315615