【问题标题】:KSOAP never timeoutKSOAP 永不超时
【发布时间】:2011-07-26 06:28:50
【问题描述】:

我正在使用支持超时的 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 工作或改进计时器以在预定义的超时后中断该线程? 感谢您的回答或任何想法尝试什么!

【问题讨论】:

  • 另一个问题,你试过没有 httpTransport.debug = true; ? (试图定位错误)

标签: android timeout ksoap2 android-ksoap2 ksoap


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    • 即使没有 httpTransport.debug = true 连接“从不”超时。我从官方 KSOAP2 网站下载了 JAR 文件。我什至检查了 JAR 文件的确切大小,一切看起来都很好。
    • 我猜你也尝试过我页面上的那个? “ksoap2-android-assembly-2.5.2-jar-with-dependencies_timeout.jar”。从我的分支到主分支完成合并后,我还没有测试过官方 Jar。仅将代码可视化。但是我看到抛出的异常是不正确的。
    • IOException 在应该使用实际 TimeOutException 的地方被抛出。我尝试使用我编译的 Jar,如果服务器(Webservice)关闭,则会发生超时。如果我尝试停止 web 服务中的踏板(等待 10 秒的计时器),也会发生超时。测试超时 6 秒。如果服务器响应一些数据然后关闭,则侦听数据的线程(在调试模式下)将停止并无限等待。我想无论如何都必须解决这个问题,但我无法重现您遇到的错误。
    • 如果警告实际上会以某种方式影响超时,您是否还使用 jdk 重新编译以修复警告?
    • 感谢您的回答。我现在正在使用自己的解决方案来发送肥皂消息。所以在你的网页上用jar再次测试(或者重新编译官方源代码)并不是那么容易。但我希望他们能修复你在下一个版本中提到的异常错误。我总是试图关闭服务器(停止命令)或在连接之前使服务器在 LAN 上物理断开。但我在“慢速/廉价”手机上看到了一些奇怪的行为(连接有时永远不会超时),即使服务器在线也是如此。
    【解决方案3】:

    我在运行 ksoap2-android-assembly-2.5.6-jar-with-dependencies 时遇到了同样的问题。我会假设 HttpTransportSE 上出现的 ksoap 超时值等同于使用 org.apache.http.client.HttpClient 与连接超时和套接字超时参数可以完成的值:

    HttpClient 客户端 = new DefaultHttpClient(); HttpParams 参数 = client.getParams(); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);

    无论我在 HttpTransportSE 的 timout 参数中输入什么值,大约 3 分钟后我终于得到了 SocketException“操作超时”。我的服务器正在运行,只是没有响应请求。

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-21
        • 1970-01-01
        • 2019-02-25
        • 2020-09-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多