1
votes

I understand I can access localhost from Windows Android Emulator via 10.0.2.2 :portnumber (I will need to access these Web API's service running on localhost from a Xamarin app I am developing in VS2015).

I can verify Web API's service is running OK via localhost but not from the Android emulator, this screenshot summarises the problem:

https://s23.postimg.org/calomedq3/localhost.jpg

According to my research, this should work. What am I missing? Many thanks.

screenshot

2
is the port open in the firewall? - Dawood Awan
can you access the API in your browser using IP (10.0.2.2) instead of 127.0.0.1 - Dawood Awan
I am not sure you understand the problem or maybe I have not expressed it clearly. 10.0.2.2 is special alias implemented by Google's Android team to access localhost (i.e. my development machine) from within the Android VM. So I won't be able to access the API from a browser running in a localhost (like in the screenshot) with 10.0.2.2, only with 'localhost' or 127.0.0.1. The reverse is true from running a browser from within the Aandroid VM - 'localhost' or 127.0.0.1 is meaningless there as the instance is running inside the emulator and has access to the virtual router, not local network. - John S
Run adb shell ifconfig and check the subnet, in my case it is 10.0.3.xxx not 10.0.2.xxx - SushiHangover
In your screenshot, it looks like you are connecting to a different url. In particular the last characters are: systemtype=I while your localhost browser shows systemtype=D - hopia

2 Answers

2
votes

OK, I managed to access the Web API with 'ngrok' (ngrok lets you expose a web server running on the local machine to the internet).

https://ngrok.com/docs#expose

This is probably not the ideal solution, but it seems to work well. As a reminder: I am not using IIS on my development machine to host the Web API's, I use Kestrel running in default localhost:5000

As a side note, http://169.254.80.80/ does seem to work too but it goes to default ISS website. So I may be able to make it work via setting up a new IIS site that redirects to Kestrel or simply suck it up and run Web API's o ISS (although the whole point of Kestrel is to avoid ISS, as Kestrel is heavily optimized). Anyway, the ngrok seems to work well so I will probably leave it at that until I've more time do look at alternatives.

0
votes

Final solution update:

I managed to make it work via 169.254.80.80 on the (MS) Android Emulator.

I could not make it work via Kestrel only (these are .NET Core API's), had to run Kestrel inside IIS on port 80 and that did the trick.