我一直试图通过Android从Axis2 Web服务请求数据时阻止KSOAP2调用超时,但一直未能这样做。如何在Android中防止可怕的KSOAP2连接超时
Web服务的背景。
我的Web服务正在Apache Tomcat服务器上运行,用于为站点返回实时信息。当我尝试通过浏览器时,它按预期工作,并在网站上也按预期工作。
的问题
然而,当我试图用同样的方法在我的Android应用程序,有时我会得到下面的堆栈跟踪误差。其他时候请求会成功。有时候,请求会立即超时,而其他时间会在超时前等待一分钟左右。
设备
我走过了三星Galaxy SII(平台2.3.3),并使用WiFi和3G使用具有相同结果的三星Galaxy SI(平台2.2.2)试了一下。但是,通过仿真器(Platform 2.2)使用它时,它永远不会超时。
我的代码
String NAMESPACE = "http://service.domain.ie";
String URL = "http://www.myhost.com/axis2/services/RealTime?wsdl";
String METHOD_NAME = "getStationData";
String SOAP_ACTION = "RealTime";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("stationType", getStationType());
request.addProperty("stationApiCode", getApiCode());
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport;
SoapObject response = null;
try {
androidHttpTransport = new HttpTransportSE(URL,60000); // Tried Setting the Timeout to 1 Minute
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION,envelope);
response = (SoapObject)envelope.bodyIn;
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
堆栈跟踪错误
04-13 13:07:18.015: W/System.err(9249): java.net.SocketTimeoutException
04-13 13:07:18.015: W/System.err(9249): at org.apache.harmony.luni.net.PlainSocketImpl.read(PlainSocketImpl.java:461)
04-13 13:07:18.015: W/System.err(9249): at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:85)
04-13 13:07:18.015: W/System.err(9249): at org.apache.harmony.luni.net.SocketInputStream.read(SocketInputStream.java:65)
04-13 13:07:18.015: W/System.err(9249): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:140)
04-13 13:07:18.015: W/System.err(9249): at java.io.BufferedInputStream.read(BufferedInputStream.java:225)
04-13 13:07:18.020: W/System.err(9249): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.readLine(HttpURLConnectionImpl.java:660)
04-13 13:07:18.020: W/System.err(9249): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.readResponseHeaders(HttpURLConnectionImpl.java:690)
04-13 13:07:18.020: W/System.err(9249): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1040)
04-13 13:07:18.020: W/System.err(9249): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512)
04-13 13:07:18.020: W/System.err(9249): at org.ksoap2.transport.ServiceConnectionSE.openInputStream(ServiceConnectionSE.java:113)
04-13 13:07:18.020: W/System.err(9249): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:160)
04-13 13:07:18.050: W/System.err(9249): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
04-13 13:07:18.050: W/System.err(9249): at ie.smartcommuter.models.Station.getRealTimeData(Station.java:123)
04-13 13:07:18.050: W/System.err(9249): at ie.smartcommuter.controllers.tabcontents.StationRealtimeActivity$1.run(StationRealtimeActivity.java:95)
04-13 13:07:18.050: W/System.err(9249): at java.lang.Thread.run(Thread.java:1019)
我已经更新KSOAP2从2.4到2.5.7,并试图设置超时限制,但我一直不成功如此远。所以要得到我的问题:
有其他人有这个问题,如果是的话,他们如何解决它?
不得不尝试超时用'TIMEOUT = 20000;'在'新HttpTransportSE(URL,60000); ' – Herry 2012-04-13 12:24:53