问题
I am using kSoap2 for accessing soap web services. I am getting java.net.connectException while executing the below line
androidHttpTransport.call(Constants.SOAP_ACTION_GET_METHOD_NAME, envelope)
This is not happening always, but some of the times. Is this the problem with connection time out to the server? How to increase the connection time out in kSoap ? I googled, but can't find out the solution . Can anyone suggest me the solution to fix this error.
Logcat details follows:
07-17 14:46:24.800: W/System.err(8103): java.net.ConnectException: failed to connect to www.yahoo.com/175.41.138.237 (port 80) after 20000ms: isConnected failed: ENETUNREACH (Network is unreachable)
07-17 14:46:24.800: W/System.err(8103): at libcore.io.IoBridge.isConnected(IoBridge.java:214)
07-17 14:46:24.800: W/System.err(8103): at libcore.io.IoBridge.connectErrno(IoBridge.java:152)
07-17 14:46:24.800: W/System.err(8103): at libcore.io.IoBridge.connect(IoBridge.java:112)
07-17 14:46:24.800: W/System.err(8103): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
07-17 14:46:24.800: W/System.err(8103): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
07-17 14:46:24.800: W/System.err(8103): at java.net.Socket.connect(Socket.java:842)
07-17 14:46:24.800: W/System.err(8103): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
07-17 14:46:24.800: W/System.err(8103): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
07-17 14:46:24.800: W/System.err(8103): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
07-17 14:46:24.800: W/System.err(8103): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
07-17 14:46:24.810: W/System.err(8103): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
07-17 14:46:24.810: W/System.err(8103): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
07-17 14:46:24.810: W/System.err(8103): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
07-17 14:46:24.810: W/System.err(8103): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
07-17 14:46:24.810: W/System.err(8103): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
07-17 14:46:24.810: W/System.err(8103): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
07-17 14:46:24.810: W/System.err(8103): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:80)
回答1:
How to increase the connection time out in kSoap ?
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.
来源:https://stackoverflow.com/questions/11541896/ksoap2-issue-java-net-connectexception