0

I'm developing a Xamarin.Forms 4 application with Visual Studio 2015 update 3 on Windows 10. Now I've setup an ASP.net web API and I'm trying to connect to it when it's been run on localhost with VS Andorid emulator 1.1 for Kitkat 4.4 (Andorid 4.4 API 19). Although my app works with the Windows Phone emulator, it doesn't with the Android emulator.

I've tried to connect to the 10.0.2.2 or 169.254.80.80 like it was suggested here but it doesn't work neither from the emulator nor the device itself. I've also enabled IIS express to accept request from external devices with the second solution provided here so I'm out of ideas.

Please elaborate on your answers as it seems that a lot of people are running into the same issue.

Thanks a lot in advance!

Community
  • 1
  • 1
Alir Kahi
  • 1,264
  • 2
  • 15
  • 27
  • does your app have INTERNET permissions enabled in the manifest? Have you checked if you can connect to the server from the browser on the device/emulator? – Jason Mar 05 '17 at 18:08
  • It's good that you said it because I'm quite new to Xamarin and I hadn't had INTERNET enabled. But now I do and it still doesn't work. Though I can access https://jsonplaceholder.typicode.com/posts face rest service from my PCL project. – Alir Kahi Mar 05 '17 at 19:55
  • That's an Android issue, nothing to do with Xamarin. And did you test if you can connect to your local server via the device browser? – Jason Mar 05 '17 at 20:16
  • If you mean connecting to http://localhost:portnumber from device, no I can't access it nor can I from the emulator – Alir Kahi Mar 05 '17 at 20:30
  • 1
    then the problem is a networking issue, not a programming one – Jason Mar 05 '17 at 20:45
  • Could you be as kind as telling me how I can fix it? Do I have to configure something in Visual Studio or Hyper-V? – Alir Kahi Mar 05 '17 at 21:22
  • if your physical device on the same network can't connect, then either something is wrong with your IIS setup or you possibly have a firewall setting that is blocking it. – Jason Mar 05 '17 at 21:25
  • I have documented the detailed steps and the reasons behind, https://blog.lextudio.com/how-to-let-android-emulator-access-iis-express-f6530a02b1d3 So on your machine, you can do some troubleshooting and see what exactly was the culprit. – Lex Li Jan 29 '18 at 22:09

2 Answers2

1

Don't forget to run Visual Studio as Administrator. I had similar problem until I ran it as Administrator.

Also, I like more how the solution is described here: http://briannoyesblog.azurewebsites.net/2016/03/06/calling-localhost-web-apis-from-visual-studio-android-emulator/

Maxim Alexeyev
  • 1,021
  • 11
  • 24
1

I had been on a mission for days trying to solve this. Screwing with ports and the iis bindings. But I found this

https://marketplace.visualstudio.com/items?itemName=vs-publisher-1448185.ConveyorbyKeyoti

This package creates a psuedo URL that exposes the localhost:[port] to the emulator.

Troubles be gone.

tlagreca
  • 358
  • 1
  • 6
  • 20
  • A link to a solution is welcome, but please ensure your answer is useful without it: Add [context around the link](https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers/8259#8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](https://stackoverflow.com/help/deleted-answers) – Noel Widmer Aug 15 '17 at 10:43