Android中调用WebService服务的主要步骤

首先引入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());


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值