【问题标题】:Handling timeout while using Ksoap2 in android在android中使用Ksoap2时处理超时
【发布时间】:2012-07-05 15:54:30
【问题描述】:

我正在从我的活动中调用另一个类的方法,该方法使用 ksoap2 调用 Web 服务。我想为此处理超时。如果该方法的执行时间超过 10 秒,那么我需要显示一个警告对话框,指示该过程不成功。

我尝试使用超时值如下:

HttpsTransportSE transport = new HttpsTransportSE(URL,TIMEOUT);

但 ksoap2 出于某种原因忽略了超时。我正在使用 ksoap2 2.6.5。

有什么方法可以让我执行该方法 10 秒,然后在 android 中显示指示成功或失败的相应对话框?

【问题讨论】:

  • 什么是 TIMEOUT 值?是10000吗?

标签: android timeout ksoap2 handlers


【解决方案1】:

在某些情况下,HttpTransportSE 忽略超时值似乎仍然存在问题。 看到这个相关的link

但是,解决此问题的方法是修改现有的 ksoap2 API

感谢Lightsoftai 的开发人员,您现在可以使用以下代码为HttpTransportSE 添加超时:

注意您可以为此使用 ksoap2 API 2.5.2 或更高版本

       /**
       * 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);
          }

您可以从here下载相同的jar文件。

另请参阅ksoap never timeout

希望对你有帮助。

【讨论】:

  • 你能帮忙说一下,ParthDoshi 的最小和最大超时是多少。
  • @Parth Doshi 下载链接现在已损坏..!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-08
  • 2016-08-06
  • 1970-01-01
相关资源
最近更新 更多