Handling timeout while using Ksoap2 in android

耗尽温柔 提交于 2019-12-10 23:57:08

问题


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);

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

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?


回答1:


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

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

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

Note : You can use ksoap2 API version 2.5.2 or greater for this

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

You can download the jar file for the same from here.

Also refer ksoap never timeout.

Hope it helps.



来源:https://stackoverflow.com/questions/11348100/handling-timeout-while-using-ksoap2-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!