2012-07-18 93 views
2

我正在使用kSoap2來訪問soap web服務。我得到java.net.connectException在執行以下線ksoap2問題java.net.ConnectException

androidHttpTransport.call(Constants.SOAP_ACTION_GET_METHOD_NAME, envelope) 

,這並不總是發生,但一些時代。這是連接超時到服務器的問題嗎?如何增加kSoap中的連接時間?我GOOGLE了,但無法找到解決方案。 任何人都可以建議我解決這個錯誤的解決方案。

logcat的細節如下:

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

如何增加連接超時的KSOAP?

在某些情況下,HttpTransportSE似乎仍然存在一個未解決超時值的問題。 看到這個相關的link

但是,解決方案涉及修改現有的ksoap2 API

由於在Lightsoftai您現在可以使用下面的代碼添加超時HttpTransportSE開發商:

注意您可以使用kso​​ap2 API版本2.5.2或更高此

 /** 
     * 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); 
      } 

您可以從here下載相同的jar文件。

另請參閱ksoap never timeout

希望它有幫助。

+0

是的。你的解決方案幫了我。正如你所說,我現在改爲新版本的ksoap。現在java.net.ConnectException不會來。但我現在正在獲取java.net.SocketTimeOutException。 – Ammu 2012-07-19 11:16:00

+0

是的,會來,請參閱[this](http://stackoverflow.com/questions/4408955/ksoap-request-timeout)...試圖捕捉它,並應該解決問題。此外,您可以嘗試:HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,60000); – 2012-07-19 11:21:09

+0

是的,我已經使用相同的,HttpTransportSE androidHttpTransport =新的HttpTransportSE(Constants.URL,30000);但只有30毫秒。是否60毫秒會幫助我 – Ammu 2012-07-19 11:58:32