2011-03-30 25 views
2

我使用支持超時的ksoap2 2.5.4(在Android 2.2上)。我使用Apache 2.2.16來處理我的請求。一切工作正常,但是當我關閉我的Apache(或斷開運行Apache的遠程PC)時,調用永遠不會超時。我使用單獨的線程來調用我的WS,並且在這種情況下,此線程停止工作/響應/停頓約2分鐘。KSOAP永不超時

int MSG_TIMEOUT = 15000; 
HttpTransportSE httpTransport; 
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.setOutputSoapObject(request); 
httpTransport = new HttpTransportSE(URL, MSG_TIMEOUT); 
httpTransport.debug = true; 
httpTransport.call(SOAP_ACTION, envelope);//thread stops responding here 

我甚至試圖用預定義的超時後取消該線程,但它沒有工作。線程仍在那裏,正在等待2分鐘。

TimerTask task; 
Timer mTimer; 
task = new TimerTask() { 
    public void run() {    
    mThread.interrupt(); 
    } 
}; 
mTimer = new Timer(); 
mTimer.schedule(task, MSG_TIMEOUT); 

我也得到這樣的警告,可能有一些做它(我不知道怎麼用它做):

Dx warning: Ignoring InnerClasses attribute for an anonymous inner class 
(org.ksoap2.transport.KeepAliveHttpsTransportSE$1) that doesn't come with an 
associated EnclosingMethod attribute. This class was probably produced by a 
compiler that did not target the modern .class file format. The recommended 
solution is to recompile the class from source, using an up-to-date compiler 
and without specifying any "-target" type options. The consequence of ignoring 
this warning is that reflective operations on this class will incorrectly 
indicate that it is *not* an inner class. 

是否有任何機會,使KSOAP工作或改進定時器以在預定義超時後中斷該線程? 謝謝你的回答或任何想法試試!

+0

另一個問題,你嘗試沒有httpTransport.debug = true; ? (試圖找到錯誤) – 2011-04-15 08:32:25

回答

0

你有沒有下載源碼,然後編譯它?或者你使用完成的JAR文件? 明天將會測試今晚或明早。

+0

即使沒有httpTransport.debug = true連接「永不」超時。我從官方KSOAP2網站下載了JAR文件。我甚至檢查過JAR文件的確切大小,一切都很正常。 – Warlock 2011-04-16 09:54:59

+0

我想你也試過我在我的頁面上的那個? 「ksoap2-機器人組裝-2.5.2-JAR-與-dependencies_timeout.jar」。從我的分支合併到主分支後,我還沒有測試官方的Jar。只顯示代碼。但是我看到拋出的異常是不正確的。 – 2011-04-21 09:23:30

+0

也應該使用真正的TimeOutException時拋出IOException。 我試着用我編譯的Jar,如果服務器(Webservice)關閉,超時將發生。 如果我試圖阻止web服務(等待10秒的計時器),超時也會發生。測試超時6秒。 如果服務器正在響應某些數據,然後關閉,則偵聽數據(在調試模式下)將停止並等待無限。 這個我猜一定是固定的,但我不能重現你得到的錯誤。 – 2011-04-21 09:24:18

0

我有同樣的問題運行ksoap2-android-assembly-2.5.6-jar-with-dependencies。我會認爲在HttpTransportSE出現就相當於你可以完成使用org.apache.http.client.HttpClient與連接超時和套接字超時pamameters的KSOAP超時值:

HttpClient的客戶端=新DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params,CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_TIMEOUT);

無論我在HttpTransportSE的timout參數中放置了什麼值,我終於在〜3分鐘後得到一個SocketException「操作超時」。我的服務器正在運行,它只是沒有響應請求。

6

使用kso​​ap2 API版本2.5.2或更高。

您可以下載由clicking here

,並使用下面的代碼,同時使HTTPTransport的對象。

/** 
* Creates instance of HttpTransportSE with set url 
* 
* @param url 
*   the destination to POST SOAP data 
*/ 
public HttpTransportSE(String url) { 
    super(url); 
} 

/** 
* Creates instance of HttpTransportSE with set url 
* 
* @param url 
*   the destination to POST SOAP data 
* @param timeout 
*   timeout for connection and Read Timeouts (milliseconds) 
*/ 
public HttpTransportSE(String url, int timeout) { 
    super(url, timeout); 
}