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?
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.