My application connects to the web-service using ksoap2. The application enables the user to change the IP address/URL of the server which gives the web-service (in settings).
The problem is that when the user changes the IP address/URL to an invalid location, the application hangs for a long time and the LogCat shows that the application was unable to connect to the Socket description provided.
How do I fix this ? How do I stop the application from hanging if the Web-service is not found ?
I want the app UI to remain as it is if the web-service is not found. Is there any way to avoid the application from hanging ?
This is my code. Please suggest any means to avoid the application from hanging.
private void getControlFromServer() {
// TODO Auto-generated method stub
SoapObject request = new SoapObject(NAMESPACE, METHOD_GET_CONTROL);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION_GET_CONTROL, envelope);
SoapObject result=(SoapObject)envelope.getResponse(); //To get the data.
tvTemp.setText("Received :" + result.getProperty(0).toString()+ " : " + result.getProperty(1).toString() + " : " + result.getProperty(2).toString() + " : " + result.getProperty(3).toString() + " : " + result.getProperty(4).toString() + " : " + result.getProperty(5).toString() + " : " + result.getProperty(6).toString());
} catch (Exception e) {
tvTemp.setText("Error");
e.printStackTrace();
}
}
Set ConnectionTimeOut to your
HttpTransportSEobject..Use latest Use ksoap2 API version 2.5.7 or greater,