我有一个Android应用程序,我使用ksoap2连接到Web服务,但有时我从客户端收到错误。当我在我的设备上测试自己时,一切都很好,所以我不确定哪里出了问题。
我得到以下例外:
java.net.ConnectException: failed to connect to example.com/91.10.10.10 (port 443) after 1800000ms: isConnected failed: ECONNREFUSED (Connection refused)
java.net.ConnectException: failed to connect to example.com/91.10.10.10 (port 443) after 1800000ms: connect failed: ENETUNREACH (Network is unreachable)
java.net.SocketException: failed to connect to example.com/91.10.10.10 (port 443) after 1800000ms: isConnected failed: EHOSTUNREACH (No route to host)
或
java.net.SocketException: Socket is closed
或
javax.net.ssl.SSLException: SSL handshake aborted: ssl=0x5cb6d638: I/O error during system call, Connection timed out
我使用此函数调用webservice函数:
private SoapObject makeCallToWebService(String soapAction, String method, PropertyInfo[] properties, boolean runInBackground) {
int retry = RETRY_COUNT;
int count = 0;
if (mShouldRetryWhenError == false) {
retry = 1;
}
while (count < retry) {
count++;
SoapObject request = new SoapObject(NAMESPACE, method);
if (properties != null) {
for (PropertyInfo property : properties) {
request.addProperty(property);
}
}
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);;
HttpsTransportSE transport = new HttpsTransportSE(HOST, PORT, FILE, TIMEOUT);
transport.debug = true;
transport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
try {
transport.call(NAMESPACE + "#" + soapAction, envelope);
SoapObject res = (SoapObject)envelope.bodyIn;
return res;
} catch (SocketTimeoutException e) {
if (count == retry) {
if (!runInBackground) {
handleError(method);
}
}
} catch (Exception e) {
Log.e(TAG, e.toString());
if (!runInBackground) {
handleError(null);
}
return null;
}
}
return null;
}
答案 0 :(得分:0)
你在使用wifi进行测试吗?也许你的问题只是使用3G。如果是这样,你应该检查一下: