soap2-android
官網(wǎng)地址
https://simpligility./ksoap2-android/index.html
發(fā)行版本
https://oss./content/repositories/ksoap2-android-releases/
com>google>code>ksoap2-android>ksoap2-android-assembly
- 選擇最新版本,然后使用-with-dependencies.jar包

最新版本
https://oss./content/repositories/ksoap2-android-releases/com/google/code/ksoap2-android/ksoap2-android-assembly/3.6.4/ksoap2-android-assembly-3.6.4-jar-with-dependencies.jar

調(diào)用WebService取得數(shù)據(jù)
初使化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 = "";
調(diào)用
new Thread(new Runnable() {
@Override
public void run() {
//創(chuàng)建HttpTransportSE傳輸對象,serviceUrl是webservice提供服務(wù)的url
HttpTransportSE httpTransportSE = new HttpTransportSE(serviceUrl);
//使用SOAP1.1協(xié)議創(chuàng)建Envelop對象,根據(jù)服務(wù)端WebService的版本號設(shè)置SOAP協(xié)議的版本號
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//實例化SoapObject對象,第一個參數(shù)表示命名空間,第二個參數(shù)表示要調(diào)用的WebService方法名
SoapObject soapObject= new SoapObject(serviceNameSapce, serviceMethod);
//設(shè)置調(diào)用方法的參數(shù)值,如果沒有參數(shù),可以省略
//soapObject.addProperty("theCityCode", cityName);
envelope.bodyOut = soapObject;
envelope.dotNet = true;
try {
//調(diào)用webservice
httpTransportSE.call(serviceAction, envelope);
//獲取服務(wù)器響應(yīng)返回的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();
|