今天学习了Android 如何调用WebService 方法如下:
通过第三方jar ksoap2-android-assembly-3.2.0-jar-with-dependencies
方法有三个参数:namespace:http://server.ws.com/
reqMethod 是要请求的webService 方法
callUrl:是webservice地址— http://192.168.2.104:8080/RABC/BusiServiceImplPort?wsdl
public static SoapObject sendRequest(String namespace,String reqMethod,String callURL){ //(1)指定 webservice的命名空间 和方法名称 SoapObject request = new SoapObject(namespace,reqMethod); //(2)设置方法的参数值 request.addProperty("arg0","123"); //(3)生成调用webserivce方法的soap信息 // SoapEnvelope.VER11协议版本号 SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut = request; //(4)创建httpTransportSE 对象,通过HttpTransportSE 类的构造方法指定WebService的WSDL 文档的URL // HttpTransportSE ht = new HttpTransportSE("http://127.0.0.1:8080/RABC/BusiServiceImplPort?wsdl"); HttpTransportSE ht = new HttpTransportSE(callURL); //(5)使用Call方法调用WebService try { ht.call(null, envelope); return (SoapObject) envelope.getResponse(); } catch (HttpResponseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } return null; }