首先引入ksoap2-android-assembly-2.5.2-jar-with-dependencies.jar
此处附上链接两个版本的:
1.ksoap2-android-assembly-2.5.4-jar-with-dependencies.jar链接: http://pan.baidu.com/s/1o89vKO6 密码: 8gbi
2.ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar 链接: http://pan.baidu.com/s/1boAhTBx 密码: kz3t
// 1.NameSpace
String namespace = "http://WebXml.com.cn/";
// 2.MethodName
String methodname = "getWeather";
// 3.endPoint
String endpoint = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx";
// 4.assign
SoapObject rws = new SoapObject(namespace, methodname);
// 5.assign params
rws.addProperty("theCityName", "江门");
// 6.assign Soap protocol version
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut = rws;
// dotNET webservice ?
envelope.dotNet = true;
// 7.generate Soap request
envelope.setOutputSoapObject(rws);
// soap action
String SOAP_ACTION = "http://WebXml.com.cn/getWeather";
HttpTransportSE transport = new HttpTransportSE(endpoint);
try {
transport.call(SOAP_ACTION, envelope);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// 8.get response
SoapObject result = null;
try {
result = (SoapObject) envelope.getResponse();
} catch (SoapFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.e("DBA",result.toString());