WebService之soap协议

WebService 是一种基于SOAP协议的远程调用标准。通过WebService可以将不同操作系统平台,不同语言、不同技术整合到一起.

需要使用ksoap2.jar。

 开启工作线程去执行webServiceConnection();  aysntask,  或者   handler


 public static String webUrl =“”;                                                          // 网址

 public static String namespace=“”;                                               // webservice的命名空间

 

public String webServiceConnection(String methname, String[] keys, Object[] Values) {
      do {
             SoapObject request = new SoapObject(namespace, methname);   //参数: 命名空间      方法名

              for (int i = 0; i < Values.length; i++) {  
                     request.addProperty(keys[i], Values[i]);                               //为soapObject添加属性  

              }

                      //为webservice设置版本
              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11);

              envelope.bodyOut = request;                                                  //将soapobject对象输出
              envelope.dotNet=false;                                                         //设置与.Net提供web service保持良好的兼容性

              HttpTransportSE http = new HttpTransportSE(webUrl);            //将网址传入

              try {
                       http.call(  (namespace + methname), envelope  );          // 呼叫
                       if (envelope.getResponse() != null) {
                            String result = envelope.getResponse().toString();    //得到返回的数据
                                    return result;
                        }
                         return "返回数据为空";
                } catch (Exception e) {
                         e.printStackTrace();
                         break;
                 }
          } while (true);
               return "获取数据失败";
 }

 

你可能感兴趣的:(WebService之soap协议)