我使用的是ksoap2 2.5.4 (在Android2.2上),它支持超时。我正在使用Apache 2.2.16来处理我的请求。一切正常,但当我关闭Apache (或断开运行Apache的远程PC )时,调用永远不会超时。我使用单独的线程来调用我的WS,在这种情况下,这个线程停止工作/响应/停顿大约2分钟。
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工作,或者改进计时器,以便在预定义的超时后中断该线程?感谢您的回答或任何想法来尝试!
发布于 2011-08-30 13:03:11
使用2.5.2版或更高版本的ksoap2应用编程接口。
你可以通过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);
}发布于 2011-04-15 16:11:37
你下载源代码并编译了吗?或者您使用的是已完成的JAR文件?会在今晚或明天一大早测试一下。
发布于 2011-07-01 23:05:13
我在运行ksoap2-android-assembly-2.5.6-jar-with-dependencies.时遇到了同样的问题我假设HttpTransportSE上显示的ksoap超时值等同于使用带有连接超时和套接字超时参数的org.apache.http.client.HttpClient可以完成的操作:
新建客户端= HttpConnectionParams.setConnectionTimeout(params,DefaultHttpClient();HttpParams参数= client.getParams();HttpClient CONNECTION_TIMEOUT);HttpConnectionParams.setSoTimeout( params,SOCKET_TIMEOUT);
不管我在HttpTransportSE的SocketException参数中设置了什么值,大约3分钟后,我终于得到了一个timout "the operation timed out“。我的服务器正在运行,只是没有响应请求。
https://stackoverflow.com/questions/5489671
复制相似问题