连接失败:几个Anfroid设备上的ECONNREFUSED问题

时间:2016-11-10 11:08:18

标签: java android web-services android-ksoap2 ksoap

我开发了一个消费Web服务的Android应用程序。我已经在不同的设备上测试了该应用程序,并且它在我的客户端的平板电脑上工作得很好,但却抛出异常。测试应用程序的所有设备都运行Android 6.0.1 Marshmallow.Following是例外

java.net.ConnectException: failed to connect to web.abc.com(port 80):connect failed: ECONNREFUSED (Connection refused)

以下是我使用Webservice的代码

String namespace = "http://web.abc.com/";
private static final String url = "http://web.abc.com/WebService/ServiceFileName.asmx";

String SOAP_ACTION;
SoapObject request = null, objMessages = null;
SoapSerializationEnvelope envelope;
HttpTransportSE androidHttpTransport;

/**
 * Set Envelope
 */
protected void SetEnvelope() {

    try {

        // Creating SOAP envelope
        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        //You can comment that line if your web service is not .NET one.
        envelope.dotNet = true;

        envelope.setOutputSoapObject(request);
        //envelope.addMapping(namespace, "ProductStausResponse",new ProductStausResponse().getClass());
        androidHttpTransport = new HttpTransportSE(url);
        androidHttpTransport.debug = true;

    } catch (Exception e) {
        e.printStackTrace();
        Log.v("Soap Exception", e.toString());
        System.out.println("Soap Exception---->>>" + e.toString());
    }
}

// MethodName variable is define for which webservice function  will call
public String getProductStatus(String MethodName, String Parameter)
{

    try {
        ProductCode = ProductCode.trim();
        SOAP_ACTION = namespace + MethodName;

        //Adding values to request object
        request = new SoapObject(namespace, MethodName);
        /// Code for setting properties

        SetEnvelope();

        try {

            //SOAP calling webservice
            androidHttpTransport.call(SOAP_ACTION, envelope);

            //Got Webservice response
            String result = envelope.getResponse().toString();
            return result;

        } catch (Exception e) {
            // TODO: handle exception
            //e.printStackTrace();
            //return "Exception";
            return e.toString();
        }
    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
        Log.v("Soap Exception", e.toString());
        //return "Exception";
        return e.toString();
    }

}

0 个答案:

没有答案