I am able to successfully make call to a .net webservice from my android app. tested it with Emulator (2.2 apilevel 8 to 4.0.3 api level 15) and it worked great.
I am now trying to test the same code with a Motorola razr MAZZ device. It is connected, able to hit break points and able to do all the functionality EXCEPT making a call to the webservice. I am getting “java.net.SocketTimeoutException: Connection timed out”.
My code is written below. It worked with emulator but not with a device.
URL = UtilsAct.Instance().GetSettingString(ctx, "sett_url");
String str="";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("IsEncrypted",false);
request.addProperty("routes", "EAST");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);
try
{
androidHttpTransport.call(SOAP_ACTION, envelope); // java.net.SocketTimeoutException: Connection timed out
Object receivedObj = envelope.getResponse();
str = receivedObj.toString();
}
catch(Exception e)
{
//e.printStackTrace();
String errmsg = "Exception:";
if(e.getMessage() != null)
errmsg = errmsg + e.getMessage();
}
I tried all tricks given in various articles including
HttpConnectionParams.setConnectionTimeout(params, timeout);
HttpConnectionParams.setSoTimeout(params, timeout);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(timeout);
urlConnection.setReadTimeout(timeout);
Appreciate help .
thanks!
I am updating it real late. I found that the server hosting the webservice was using a security policy and was not allowing a call from any device using a wifi. Emulator worked because it worked within the network and therefore does not interfere with the security. My code written above is now working after I got the server security changed to allow call from a device using my wifi.