Android利用soap WSDL與Webservice通訊

來源:互聯網
上載者:User

 

需要6個步驟,關於下面代碼中的NAME_SPACE等,可以通過一個軟體SoapUI,來串連伺服器獲得。

 

/** 命名空間. */      private final static String NAME_SPACE = urn:soap;        /** 方法. */      private final static String METHOD_NAME = Add;        /** WSDL檔案的URL. */      private final static String WSDL_URL = http://192.168.1.112:80/index.php/service?wsdl;  


 

 

//1. 指定WebService的命名空間和調用的方法名    SoapObject  request=new SoapObject(NAME_SPACE, METHOD_NAME);

 //2. 設定調用方法的參數值,這一步是可選的,如果方法沒有參數,可以省略這一步    request.addProperty(a,123);    request.addProperty(b,12);

//3. 產生調用WebService方法的SOAP請求資訊。該資訊由SoapSerializationEnvelope對象描述        SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER10);        envelope.bodyOut = request;

 //4. 建立HttpTransportSE對象。通過HttpTransportSE類的構造方法可以指定WebService的WSDL文檔的URL        HttpTransportSE ht = new HttpTransportSE(WSDL_URL);              ht.debug = true;

//5. 使用call方法調用WebService方法
List headerList =ht.call(null, envelope,null);
注意,如果不需要標頭檔,只需要傳遞前兩個參數即可

 

 

//6. 使用getResponse方法獲得WebService方法的返回結果            SoapObject result=(SoapObject)envelope.bodyIn;            Log.i(========,result.getProperty(Add).toString());



 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.