3

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)
user370305
  • 108,599
  • 23
  • 164
  • 151
Ammu
  • 97
  • 1
  • 10

1 Answers1

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.

Community
  • 1
  • 1
Parth Doshi
  • 4,200
  • 15
  • 79
  • 129
  • Yes . Your solution helped me. As u said, i changed to new version of ksoap now. Now that java.net.ConnectException is not coming . But i am getting java.net.SocketTimeOutException now. – Ammu Jul 19 '12 at 11:16
  • yes that will come, see [this](http://stackoverflow.com/questions/4408955/ksoap-request-timeout)...try to catch it and that should solve the problem. Also, you can try: HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000);HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000); – Parth Doshi Jul 19 '12 at 11:21
  • Yes i am using the same already, HttpTransportSE androidHttpTransport = new HttpTransportSE(Constants.URL,30000); But only 30 ms. whether 60 ms will help me – Ammu Jul 19 '12 at 11:58
  • yes. difference is there. previously it will come 7 out of 10 times . Now 4 out of 10 times. If u find any other solution , Pls share with me . – Ammu Jul 19 '12 at 12:20