KSOAP从不超时KSOAP

2023-09-12 09:58:23 作者:ζ  菇凉

我用ksoap2 2.5.4(在Android 2.2),支持超时。我使用的Apache 2.2.16来处理我的请求。一切工作正常,但是当我关闭我的Apache(或断开远程计算机上的Apache正在运行)调用永远不会超时。我使用单独的线程来叫我的WS和这个线程停止工作/响应/摊位在这种情况下,约2分钟。

I'm using ksoap2 2.5.4 (on Android 2.2) which supports timeout. I'm using Apache 2.2.16 to handle my requests. Everything works fine, but when I shutdown my Apache (or disconnect remote PC on which Apache is running) the call never times out. I'm using separate thread to call my WS and this thread stop working/responding/stalls for about 2 minutes in this case.

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

我甚至试图用计时器来取消predefined超时后该线程,但没有奏效。螺纹仍然存在,等待2分钟。

I even tried to use Timer to cancel that thread after predefined timeout, but it didn't work. Thread is still there and is waiting for 2 minutes.

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

我还得到这样的警告,可能有什么关系呢(我不知道该怎么用它做):

I also get this warning that may have something to do with it (I don't know what to do with it):

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工作或改善定时器中断predefined超时后,该线程? 谢谢你的答案或者任何想法去尝试的!

Is there any chance to make KSOAP working or to improve the timer to interrupt that thread after predefined timeout? Thank you for answer or any idea what to try!

推荐答案

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

Use ksoap2 API version 2.5.2 or greater.

您也可以下载,通过clicking这里

和使用下面的code,同时使HTTPTransport的对象。

And use the following code while making object of 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);
}