2

I am getting connection refused error when trying to connect to webservice using soapui. When I tried using 127.0.0.1 in the URL, the error is ECONNREFUSED but when I tried 10.0.2.2, the error is connection timed out. Please can someone help. Thanks. Here is my code on Main Activity.

private static final String SOAP_ACTION = "http://tempuri.org/GetSMSOutgoing";
    private static final String INSERT_INCOMING_SMS = "SaveSMSIncoming";
    private static final String GET_OUTGOING_SMS = "GetSMSOutgoing";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String URL = "http://127.0.0.1:62499/WSsmsandroid.asmx?wsdl";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Thread thread = new Thread(new Runnable() {
    @Override
    public void run() {
        try {
            getOutgoingSMS();
        } catch (Exception e) {
            Log.d("NOT CONNECTED: IOException", "NOT CONNECTED");
            e.printStackTrace();
        }

    }
});

thread.start();

}

public String getOutgoingSMS() {
        String outgoingSMS = null;

        SoapObject request = new SoapObject(NAMESPACE, GET_OUTGOING_SMS);
        request.addProperty("sentBy", "+639209100000");

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE ht = new HttpTransportSE(URL);
        try {
            ht.call(SOAP_ACTION, envelope);

            SoapObject response2 = (SoapObject) envelope.getResponse();
            denemeList = new String[response2.getPropertyCount()];

            for (int i = 0; i < response2.getPropertyCount(); i++) {
                denemeList[i] = response2.getProperty(i).toString();
            }
            outgoingSMS = response2.toString();

        } catch (Exception e) {
            e.printStackTrace();
        }
        return outgoingSMS;
    }
user3055923
  • 195
  • 2
  • 3
  • 9
  • Please check your server IP address. if you are using local server check the address by simply putting the IP in the web browser. If the error still after these solutions check the firewall option on your PC. Firewall do not permit local server. – Farshan May 06 '18 at 06:17

3 Answers3

11

To access your PC localhost from Android emulator, use 10.0.2.2 instead of 127.0.0.1. localhost or 127.0.0.1 refers to the emulated device itself, not the host the emulator is running on.

For Genymotion use: 10.0.3.2 instead of 10.0.2.2

Reference: http://developer.android.com/tools/devices/emulator.html#networkaddresses

PS.: it's already been answered in connect failed: ECONNREFUSED

Community
  • 1
  • 1
Diego Souza
  • 548
  • 5
  • 10
0

Your ip is wrong. 127.0.0.1 is loopback. Unless you're running a webservice on your local phone, that isn't likely to be what you want. 10.0.2.2 is a random ip on an unassigned network used for NATs, so unless you're on a wifi connection that has the service on that IP its unlikely to be right. So where are you really trying to connect to?

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I am trying run in a localhost. I run the webservice from c# and the url is http://localhost:62499/WSsmsandroid.asmx. – user3055923 Aug 17 '14 at 23:59
  • 1
    You're running a webservice on your local phone and accessing it via your local phone? Whatever you're really trying to do, that's the absolute wrong way to do it. – Gabe Sechan Aug 18 '14 at 00:11
  • I am running the webservice in the localhost web server. – user3055923 Aug 18 '14 at 00:14
  • And you're doing that why? You're local. Use a regular Service. The webservice does nothing but make you less secure, adds additional vectors for bugs (like this), and complicates things. There's no reason for it. Unless you're planning on allowing other devices to access the service eventually, which will be a major problem since both wifi and cellular are heavily NATed. – Gabe Sechan Aug 18 '14 at 00:20
  • I am using the webservice to get values from the server. I am really confused. – user3055923 Aug 18 '14 at 00:29
  • You don't run a local webservice to get values from a remote service. You use an HttpRequest to that server. You don't use a webservice to contact a local service- you just use direct function calls on the binder. If you're always going to be running the webservice and the client on the same machine, there' no reason to use a webservice. – Gabe Sechan Aug 18 '14 at 00:33
-2

Check your ip address,i think port number not required. Once try by removing port number in URL.