0

I am calling ASP.NET web API in android(Java). I have deployed web API on localhost and using localhost URL in API call.

I'm getting connection refused error. I've tried the following:

  • Called API using local host URL.
  • Called API using 10.0.2.2 IP.
  • Called API with my IP address.
  • Called API using 127.7.0.0

Kindly suggest what should be done in this scenario.

P.s: I've tested on both emulator and android device. Everything is on same network. Still I get the same error.

Update: Issue is resolved. I have done the following:

  1. open chrome://inspect/#devices
  2. select port forwarding.
  3. forward the port at which web API is deployed on IIS to localhost:8081.
  4. web api is accessible to emulator and device both.
ekad
  • 14,436
  • 26
  • 44
  • 46
geons
  • 43
  • 7
  • which server u used for run your Web services. use this link for reference https://stackoverflow.com/questions/6176609/connect-an-android-device-to-a-web-service-on-local-host – Kevan Aghera Sep 12 '17 at 10:51
  • first Check your Web services In SOAP UI. Second Link For Reference https://stackoverflow.com/questions/4456921/consuming-a-web-service-in-an-android-application-in-localhost – Kevan Aghera Sep 12 '17 at 10:54
  • 2
    I'm using windows 10 OS and I have deployed it on IIS. I can access the service using localhost URL on the browser. – geons Sep 12 '17 at 10:58
  • ya u can able to access but u want to search About IIS. and get info about how to access in browser – Kevan Aghera Sep 12 '17 at 10:59
  • Did you add the `android.permission.INTERNET` permission in your app manifest? – Nicolas Zawada Sep 12 '17 at 11:51
  • yes i have the permission. – geons Sep 13 '17 at 07:28
  • If you use `localhost` and if you test in a real device, it is considering the itself (the device) as the `localhost`. This is not a problem if you are using an emulator or if you are accessing the URL from the browser. There are some settings that you should change in order for the API to be accessed from external devices. I have used [this method](https://stackoverflow.com/a/44534890/7196681) and it's working for me. Hope you can resolve it. :) – Curiosity Sep 27 '17 at 08:23
  • @curiosity thank you for your reply. I've tried doing port forwarding using chrome://inspect/#devices and forwarded localhost:6061(port at which API is deployed on IIS) to localhost:8081. It worked for me, I can access web API from emulator and device both. – geons Sep 27 '17 at 09:15

0 Answers0