John S
John S

Reputation: 71

Can't access localhost from Android Windows Emulator (Visual Studio 2015 / Xamarin)

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

Upvotes: 1

Views: 1971

Answers (2)

John S
John S

Reputation: 71

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.

Upvotes: 0

John S
John S

Reputation: 71

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.

Upvotes: 2

Related Questions