Android调用Webservice

 1     public void GetHelloWord(){
 2         new Thread(new Runnable() {
 3             @Override
 4             public void run() {
 5                 String WSDL = "http://192.168.99.126:8066/FileUpload/FileUpload.asmx?wsdl";//WSDL
 6                 String targetNameSpace = "http://tempuri.org/";//namespace
 7                 String getSupportProvince = "HelloWorld";//要调用的方法名称
 8 
 9                 // 根据命名空间和方法得到SoapObject对象
10                 SoapObject soapObject = new SoapObject(targetNameSpace,getSupportProvince);
11 
12                 // 通过SOAP1.1协议得到envelop对象
13                 SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
14                 // 将soapObject对象设置为envelop对象,传出消息
15                 envelop.bodyOut = soapObject;
16                 // 设置是否调用的是dotNet开发的WebService  //指定webservice的类型的(java,PHP,dotNet)
17                 envelop.dotNet = true;
18                 // 等价于envelop.bodyOut = soapObject;
19                 envelop.setOutputSoapObject(soapObject);
20                 HttpTransportSE httpSE = new HttpTransportSE(WSDL);
21                 // 开始调用远程方法
22                 try {
23                     httpSE.call(targetNameSpace + getSupportProvince, envelop);
24                     // 得到远程方法返回的SOAP对象
25                     SoapObject resultObj = (SoapObject) envelop.bodyIn;
26                     // 得到服务器传回的数据
27                     int count = resultObj.getPropertyCount();
28                     Log.i("----------------TAG",  "count="+count+";"+resultObj.getProperty(0).toString());
29                     for (int i = 0; i < count; i++) {
30                         Map<String,String> listItem = new HashMap<String, String>();
31                         listItem.put("province", resultObj.getProperty(i).toString());
32                         Log.i("----------------TAG", resultObj.getProperty(i).toString());
33                     }
34                 } catch (IOException e) {
35                     e.printStackTrace();
36                 } catch (XmlPullParserException e) {
37                     e.printStackTrace();
38                 }
39             }
40         }).start();
41     }

 

Android调用Webservice

上一篇:Android命令行工具使用总结


下一篇:BIOS时间与系统时间(windows/linux时间同步问题)