而在Android的使用Ksoap2处理超时(Handling timeout while usin

2019-09-19 03:57发布

我打电话另一个类的从我的活动使用kso​​ap2调用web服务的方法。 我想处理超时此。 如果该方法需要10秒以上来执行,然后我需要显示一个警告对话框,表明该过程不成功。

我尝试使用的超时值如下:

HttpsTransportSE transport = new HttpsTransportSE(URL,TIMEOUT);

但ksoap2是忽略了某些原因超时。 我使用kso​​ap2 2.6.5。

有没有办法在那里我可以执行的方法,持续10秒,然后显示相应的对话框显示在android系统是成功还是失败?

Answer 1:

目前似乎仍然是一个悬而未决的问题与HttpTransportSE忽略了在某些情况下超时值。 请参阅此相关的链接 。

然而,对于现有的这种变形例涉及的溶液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);
          }

您可以从下载同一个jar文件在这里 。

另请参阅KSOAP从不超时 。

希望能帮助到你。



文章来源: Handling timeout while using Ksoap2 in android