我能够从我的 android 应用程序成功调用 .net webservice。用模拟器(2.2 apilevel 8 到 4.0.3 api level 15)对其进行了测试,效果很好。
我现在正在尝试使用摩托罗拉 razr MAZZ 设备测试相同的代码。它已连接,能够打断点并且能够执行所有功能,除了调用 web 服务。我收到“java.net.SocketTimeoutException:连接超时”。我的代码写在下面。它适用于模拟器,但不适用于设备。
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();
}
我尝试了各种文章中给出的所有技巧,包括
HttpConnectionParams.setConnectionTimeout(params, timeout);
HttpConnectionParams.setSoTimeout(params, timeout);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setConnectTimeout(timeout);
urlConnection.setReadTimeout(timeout);
感谢帮助。谢谢!