Android基于SOAP協(xié)議向WebService交互數(shù)據(jù),修改請(qǐng)求超_第1頁(yè)
Android基于SOAP協(xié)議向WebService交互數(shù)據(jù),修改請(qǐng)求超_第2頁(yè)
Android基于SOAP協(xié)議向WebService交互數(shù)據(jù),修改請(qǐng)求超_第3頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、soap :簡(jiǎn)單對(duì)象訪問(wèn)協(xié)議,簡(jiǎn)單對(duì)象訪問(wèn)協(xié)議(soap )是一種輕量的、簡(jiǎn)單的、基于xml 的協(xié)議。諦力泰克網(wǎng):app 定制 通過(guò)第三方提供的架包 ksoap2-android-assembly-2.4-jar-with-dependencies.jar,我們可以向服務(wù)器進(jìn)行請(qǐng)求調(diào)用自己需要的服務(wù)。下面以供的天氣預(yù)報(bào)web服務(wù)為例。下面是向遠(yuǎn)處服務(wù)器進(jìn)行請(qǐng)求的詳細(xì)操作類webserviceutilpublic class webserviceutil 命名空間private static final string/*/需要調(diào)用的方法名ngetsupportprovincem;* return

2、省份列表allprovince = new arraylist();soapobject 對(duì)象namespace = "http:/webxah; /webservice 地址 private static final string url = uavebservices/weatherwebservice.asmx?wsdlm; private static final string getsupportprovince = * desc獲得洲、國(guó)內(nèi)外省份和城市信息 public list getallprovince() listtry 1.實(shí)例化soapobject reque

3、st = new soapobject(namespace,getsupportprovince);2.如果方法需要參數(shù),設(shè)置參數(shù)/rcqucst.sctpropcrty(n參數(shù)名稱“,”參數(shù)值“);3.設(shè)置soap的請(qǐng)求信息,參數(shù)部分為soap協(xié)議的版本號(hào)soapserializationenvelopeenvelope=newsoapserializationenvelope(soapenvelope.ver 11);envelope.bodyout = request;/4.構(gòu)建傳輸對(duì)象androidhttptransporttransport=newandroidhttptranspo

4、rt(url);transport.dcbug = true;5.訪問(wèn) wcbscrvicc,第一個(gè)參數(shù)為命6.解析返回的數(shù)據(jù)int count =count; i+)名空間+方法名,第二個(gè)參數(shù)為envelope對(duì)象transport.call(namespace +getsupportprovince, envelope);soapobject result = (soapobject) envelope.getresponse(); result.getpropertycount();for (int i = 0; i)catchallprovince.add(result.getprop

5、erty(i).tostring(); catch (ioexception e) e.printstacktrace();(xmlpullparserexception e) e.printstacktrace();return diprovince;)使用述是比較簡(jiǎn)單的,在這我只以天氣預(yù)報(bào)服務(wù)中提供的獲取省份信息的方法 getsupportprovince為例,詳細(xì)的解特了基于soap協(xié)議的訪問(wèn)操作。在訪問(wèn)遠(yuǎn)程服務(wù)器提供的服務(wù)時(shí),有時(shí)會(huì)因?yàn)榫W(wǎng)絡(luò)問(wèn)題或者是服務(wù)器端問(wèn)題,而導(dǎo)致客八 端側(cè)一直處于請(qǐng)求連接狀態(tài),此時(shí)我們希望町以控制請(qǐng)求得不到響應(yīng)的超時(shí)時(shí)間timeout.想要控制請(qǐng)求的超時(shí)時(shí)間,我

6、們需要根據(jù) ksoap2-android-assembly-2.4-jar-with-dependencies.jar 包,修改一些訪問(wèn)的控制類。1.首先重寫架包屮的serviceconnectionse.java,添加設(shè)置超時(shí)時(shí)間的方法,可以在你的t程里重寫這個(gè)類package com.ahutzh.weather;import java.io.ioexccption; import java.io.inputstrcain;import java.io.outputstream;import .httpurlconncction;import .url;import org.ksoap2.

7、transport.serviceconnection;public class serviceconnectionseimplements serviceconnection private httpurlconnection connection;publicserviceconnectionse(string url)throws ioexception this.connection =(httpurlconnection)newurl(url).openconnection();this.connection.sctusccachcs(falsc);this.connection.s

8、ctdooutput(truc);this.connection.setdoinput(true);)public void connect() throws ioexceptionthis.connection.connect();public void disconnect()this.connection.disconnect(); public void setrequestproperty(string string,string soapaction) this.connection.setrequestproperty(string, soapaction); public vo

9、id setrequestmethod(string requestmethod) throws ioexception this.connection.setrequestmethod(requestmethod); public outputstreamopenoutputstream() throws ioexception return this.connection.getoutputstream();public inputstream openinputstream() throws ioexception returnthis.connection.getinputstream

10、();public inputstream geterrorstream()return this.connection.geterrorstream(); 設(shè)置連接服務(wù)器的超吋吋間,毫秒級(jí),此為自己添加的方法public void setconnectiontimeout(inttimeout)this.connection.setconnecttimeout(timeout); 再自 己寫一個(gè)傳輸對(duì)象類,類似于架包屮的 androidhttptransport 類,命名為 myandroidhttptransport.java package com.ahutzh. weather;imp

11、ort java.io.ioexception;importorg.ksoap2.transport.httptransportse;import org.ksoap2.transport.scrviccconncction;public ckiss myandroidhttptransport extends httptransportse private int timeout =30000; 默認(rèn)超時(shí)時(shí)間為 30spublic myandroidhttptransport(string url)super(url);public myandroidhttptransport(string

12、 url, inttimeout) super(url);this.timeout = timeout;)protectedscrviccconncction gctscrviccconncction(string url) throws ioexception serviceconnectionse serviceconnection = new serviceconnectionse(url);sendceconnection.setconnectiontimeout(timeout);return newserviceconnectionse(url);)完成這之后,在前面的第四步構(gòu)建傳輸對(duì)象小,就不要使用架包中的 androidhttptransport,而使用我們自己的寫的這個(gè)類。/4.構(gòu)建傳輸對(duì)象 /androidhttptransport transport = newa ndro

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論