0

我有一个 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;
}
4

1 回答 1

0

你是用wifi测试的吗?也许您的问题只是使用 3G。如果是这样,您应该检查一下:

Android 应用程序在 WIFI 和 3G(无代理)上工作,但在 3G 上不工作(如果分配了代理和端口)

于 2013-09-12T09:06:43.203 回答