在Android中訪問WebService接口的方法
更新時(shí)間:2013年05月27日 10:29:33 作者:
最近公司有個(gè)項(xiàng)目需要從Android平臺(tái)訪問WebService接口,實(shí)現(xiàn)向發(fā)布的函數(shù)傳遞對(duì)象。在網(wǎng)上找了一些資料,發(fā)現(xiàn)使用ksoap2可以調(diào)用WebService傳遞對(duì)象。
需要引入ksoap2-android-assembly-2.5.2-jar-with-dependencies.jar
//WebService的命名空間
static final String namespace = "http://impl.service.suncreate.com";
//服務(wù)器發(fā)布的url
static final String url = http://10.100.3.41/axis2/services/UploadService;
final String methodName = "upload"; // 函數(shù)名
final int sessionID = "111111"; //sessionID
//創(chuàng)建HttpTransportSE對(duì)象,通過HttpTransportSE類的構(gòu)造方法可以指定WebService的url
HttpTransportSE transport = new HttpTransportSE(url);
transport.debug = true;
//指定WebService的命名空間和函數(shù)名
SoapObject soapObject = new SoapObject(namespace, methodName);
//設(shè)置調(diào)用方法參數(shù)的值
soapObject.addProperty("sessionID", sessionID); //sessionID
soapObject.addProperty("data", cds); //cds是需要傳遞的對(duì)象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.bodyOut = transport;
envelope.setOutputSoapObject(soapObject);
//使用call方法調(diào)用WebService方法
transport.call(null, envelope);
SoapObject sb = (SoapObject) envelope.bodyIn;
String xmlMessage = sb.toString(); // 獲取從服務(wù)器端返回的XML字符串
復(fù)制代碼 代碼如下:
//WebService的命名空間
static final String namespace = "http://impl.service.suncreate.com";
//服務(wù)器發(fā)布的url
static final String url = http://10.100.3.41/axis2/services/UploadService;
final String methodName = "upload"; // 函數(shù)名
final int sessionID = "111111"; //sessionID
//創(chuàng)建HttpTransportSE對(duì)象,通過HttpTransportSE類的構(gòu)造方法可以指定WebService的url
HttpTransportSE transport = new HttpTransportSE(url);
transport.debug = true;
//指定WebService的命名空間和函數(shù)名
SoapObject soapObject = new SoapObject(namespace, methodName);
//設(shè)置調(diào)用方法參數(shù)的值
soapObject.addProperty("sessionID", sessionID); //sessionID
soapObject.addProperty("data", cds); //cds是需要傳遞的對(duì)象
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
envelope.bodyOut = transport;
envelope.setOutputSoapObject(soapObject);
//使用call方法調(diào)用WebService方法
transport.call(null, envelope);
SoapObject sb = (SoapObject) envelope.bodyIn;
String xmlMessage = sb.toString(); // 獲取從服務(wù)器端返回的XML字符串
您可能感興趣的文章:
- Android開發(fā)調(diào)用WebService的方法示例
- Android 中利用 ksoap2 調(diào)用 WebService的示例代碼
- Android ksoap調(diào)用webservice批量上傳多張圖片詳解
- Android 通過webservice上傳多張圖片到指定服務(wù)器詳解
- Android通過ksoap2傳遞復(fù)雜數(shù)據(jù)類型及CXF發(fā)布的webservice詳細(xì)介紹
- 在Android中調(diào)用WebService實(shí)例
- Android通過Webservice操作sqlserver數(shù)據(jù)庫(kù)實(shí)例代碼
- android調(diào)用WebService實(shí)例分析
- android中soap協(xié)議使用(ksoap調(diào)用webservice)
- android調(diào)用webservice接口獲取信息
相關(guān)文章
Android高仿QQ6.0側(cè)滑刪除實(shí)例代碼
先給大家分享一下,側(cè)滑刪除,布局也就是前面一個(gè)item,然后有兩個(gè)隱藏的按鈕(TextView也可以),然后我們可以向左側(cè)滑動(dòng),然后顯示出來,然后對(duì)delete(刪除鍵)實(shí)現(xiàn)監(jiān)聽,就可以了哈。好了那就來看看代碼怎么實(shí)現(xiàn)的吧2016-02-02
Android 添加系統(tǒng)設(shè)置屬性的實(shí)現(xiàn)及步驟
這篇文章主要介紹了Android 添加系統(tǒng)設(shè)置屬性的實(shí)現(xiàn)及步驟的相關(guān)資料,需要的朋友可以參考下2017-07-07
Android中使用ContentProvider管理系統(tǒng)資源的實(shí)例
這篇文章主要介紹了Android中使用ContentProvider管理系統(tǒng)資源的實(shí)例,講解了ContentProvider對(duì)系統(tǒng)中聯(lián)系人及多媒體資源的管理例子,需要的朋友可以參考下2016-04-04
Android Kotlin開發(fā)實(shí)例(Hello World!)及語(yǔ)法詳解
這篇文章主要介紹了Android Kotlin開發(fā)實(shí)例及語(yǔ)法詳解的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android關(guān)于WebView中無法定位的問題解決
本篇文章主要介紹了Android關(guān)于WebView中無法定位的問題解決,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-10-10
Android導(dǎo)入現(xiàn)有的數(shù)據(jù)庫(kù)方法示例
這篇文章主要介紹了Android導(dǎo)入現(xiàn)有的數(shù)據(jù)庫(kù)方法,文中通過示例代碼介紹的很詳細(xì),相信對(duì)大家具有一定的參考價(jià)值,需要的朋友們下面來一起看看吧。2017-02-02
玩轉(zhuǎn)AppBarLayout實(shí)現(xiàn)更酷炫的頂部欄
玩轉(zhuǎn)AppBarLayout,實(shí)現(xiàn)更酷炫的頂部欄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09

