在Android中使用Ksoap2时处理超时 [英] Handling timeout while using Ksoap2 in android

查看:226
本文介绍了在Android中使用Ksoap2时处理超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am calling a method of another class from my activity that calls a webservice using ksoap2. I want to handle timeout for this. If the method takes more than 10 seconds to execute, then I need to show an alert dialog indicating that the process was not successful.

我尝试使用超时值,如下所示:

I tried using the timeout value as follows:

HttpsTransportSE transport = new HttpsTransportSE(URL,TIMEOUT);

但是ksoap2由于某种原因忽略了超时.我正在使用kso​​ap2 2.6.5.

but ksoap2 is ignoring the timeout for some reason. I'm using ksoap2 2.6.5.

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

Is there any way where in I can execute the method for 10 seconds and then display the appropriate dialog box indicating a success or failure in android?

推荐答案

在某些情况下,HttpTransportSE似乎仍然忽略了超时值,这是一个未解决的问题. 请参阅与此相关的链接

There still seems to be an open issue with HttpTransportSE ignoring the timeout value in some situations. See this related link.

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

However, a solution for this involved modification of the existing ksoap2 API.

由于开发人员位于 Lightsoftai ,您现在可以使用以下方法向HttpTransportSE添加超时以下代码:

Thanks to the developers at Lightsoftai you can now add timeout to HttpTransportSE using the following code:

注意:您可以为此使用kso​​ap2 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);
          }

您可以从此处.

还请参考 ksoap永不超时.

希望有帮助.

这篇关于在Android中使用Ksoap2时处理超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆