KSOAP永不超时

发布于 2024-10-28 08:07:08 字数 1502 浏览 8 评论 0原文

我正在使用支持超时的 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

我什至尝试使用计时器在预定义的超时后取消该线程,但它不起作用。线程仍然存在并等待 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 工作或改进计时器以在预定义的超时后中断该线程? 感谢您的回答或任何想法尝试什么!

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

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.

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

伏妖词 2024-11-04 08:07:08

使用 ksoap2 API 版本 2.5.2 或更高版本。

您可以通过单击此处下载

并使用创建 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);
}

Use ksoap2 API version 2.5.2 or greater.

You can download that by clicking here

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);
}
暗恋未遂 2024-11-04 08:07:08

你下载了源码然后编译了吗?或者您使用的是已完成的 JAR 文件吗?
今晚或明天清晨将对此进行测试。

Have you downloaded the source and then compiled it? Or did you use a finished JAR file?
Will test this tonight or early in the morning tomorrow.

年少掌心 2024-11-04 08:07:08

我在运行 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“操作超时”。我的服务器正在运行,只是没有响应请求。

I'm having the same problem running ksoap2-android-assembly-2.5.6-jar-with-dependencies. I would have assumed the ksoap timeout value that appears on HttpTransportSE would be equivalent to what you can accomplish using org.apache.http.client.HttpClient with connection timeout and socket timeout pamameters:

HttpClient client = new DefaultHttpClient();
HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);

I finally get a SocketException "the operation timed out" after ~3 minutes no matter what value I put in the timout parameter on HttpTransportSE. My server is running, its just not responding to the request.

揽月 2024-11-04 08:07:08

这似乎仍然是 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

This still seems to be an open issue with HttpTransportSE ignoring the timeout value in some situations. See related:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文