Android WebService(基於SOAP協議)個人記錄總結

這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述

  new Thread(){
                    @Override
                    public void run() {
                        try {
                            netWork();
                        } catch (SoapFault soapFault) {
                            soapFault.printStackTrace();
                        }
                    }
                }.start();

   // 命名空間
    String nameSpace = "http://WebXml.com.cn/";
    // 調用的方法名稱
    String methodName = "getSupportCity";
    // EndPoint
    String endPoint = "http://www.webxml.com.cn/webservices/weatherwebservice.asmx";
    // SOAP Action
    String soapAction = "http://WebXml.com.cn/getSupportCity";
   private void netWork() throws SoapFault {
        List<Map<String,String>> listItems = new ArrayList<>();
        // 指定WebService的命名空間和調用的方法名
        SoapObject rpc = new SoapObject(nameSpace, methodName);
        // 設置需調用WebService接口需要傳入的兩個參數mobileCode、userId
        rpc.addProperty("byProvinceName", "貴州");

        // 生成調用WebService方法調用的soap信息,並且指定Soap版本
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
        envelope.bodyOut = rpc;
        // 設置是否調用的是dotNet開發的WebService
        envelope.dotNet = true;
        // 等價於envelope.bodyOut = rpc;
        envelope.setOutputSoapObject(rpc);

        HttpTransportSE transport = new HttpTransportSE(endPoint);

        try {
            // 調用WebService
            transport.call(soapAction, envelope);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 獲取返回的數據
        //SoapObject object = (SoapObject) envelope.bodyIn;

        SoapObject resultObj = (SoapObject) envelope.getResponse();
        int count = resultObj.getPropertyCount();
        Log.e(TAG, "result  count :" + count);

        for (int i = 0; i < count; i++) {
            Map<String, String> listItem = new HashMap<String, String>();
            listItem.put("province", resultObj.getProperty(i).toString());
            listItems.add(listItem);
        }


        for (int i = 0; i < count; i++) {
            Log.e(TAG, "province  :" + listItems.get(i).get("province"));
        }


    }

        // 獲取返回的結果
      //  String result = object.getProperty(0).toString();

      //  Log.e(TAG,"result :"+result);

}

參考文獻:
http://blog.csdn.net/lyq8479/article/details/6420398
http://blog.csdn.net/zd_1471278687/article/details/11925349
http://blog.csdn.net/etttttss/article/details/17303315

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章