Android个人学习笔记-使用myeclipse快速创建webservice并在Android中调用(续)
2、Android端webservice的调用
package net.zmqc.service; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; public class InfoWebService { public static String soapCallWebService(double p_x,double p_y) { String result = "无数据出现!!!!!!!!"; String url = "http://127.0.0.1:8080/InfoGpsService/InfoServicePort"; String nameSpace = "http://service.zmqc.net/"; //调用的方法 String methodName = "getInfoList"; //创建httpTransportSE传输对象 HttpTransportSE ht = new HttpTransportSE(url); ht.debug = true; //使用soap1.1协议创建Envelop对象 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //实例化SoapObject对象 SoapObject request = new SoapObject(nameSpace, methodName); //设置参数,参数名不一定需要跟调用的服务器端的参数名相同,只需要对应的顺序相同即可 request.addProperty("arg0", p_x+""); request.addProperty("arg1", p_y+""); envelope.bodyOut = request; try { // web service请求 ht.call(null, envelope); // 获取返回的数据 result = envelope.getResponse().toString(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); result = "连接出错了"; } return result; } }
调用采用的是ksoap,下图是ksoap2-...jar包,可以百度下载
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。