2011-03-30 62 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); 
}