我正在使用支持超时的ksoap2 2.5.4(在Android 2.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
我甚至尝试使用Timer在预定义的超时后取消该线程,但它没有用。线程仍在那里,等待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 :(得分:6)
使用ksoap2 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);
}
答案 1 :(得分:0)
您下载了源代码然后编译了吗?或者你使用完成的JAR文件? 将在今晚或明天清晨进行测试。
答案 2 :(得分:0)
我在运行ksoap2-android-assembly-2.5.6-jar-with-dependencies时遇到同样的问题。我假设HttpTransportSE上出现的ksoap超时值与使用带有连接超时和套接字超时参数的org.apache.http.client.HttpClient可以完成的操作相当:
HttpClient client = new DefaultHttpClient(); HttpParams params = client.getParams(); HttpConnectionParams.setConnectionTimeout(params,CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params,SOCKET_TIMEOUT);
无论我在HttpTransportSE的timout参数中放入什么值,我终于在~3分钟后得到一个SocketException“操作超时”。我的服务器正在运行,它只是没有响应请求。
答案 3 :(得分:0)
这仍然是HttpTransportSE在某些情况下忽略超时值的一个悬而未决的问题。见相关:
http://code.google.com/p/ksoap2-android/issues/detail?id=52
http://code.google.com/p/ksoap2-android/issues/detail?id=60&q=httpTransportse%20timeout