Forum Xamarin Xamarin.Android

Hitting a WebAPI Endpoint on my Dev Machine from the Visual Studio Android Emulator

I have a WebAPI end point running on my dev machine. I've configured it to run on the following IP addresses:

.UseUrls("http://localhost:57971", "", "", "", "http://*:57971")

where: is Desktop Adapter #2 on the emulator Networks settings tab is the special address for the Android emulator, as set out in Google's doco (possibly not relevant to Xamarin) and is my local IP address for my dev machine.

I have created a firewall rule permitting connections on TCP port 57971.

This is failing silently. There is no exception and the output just basically shows the different threads exiting with code 0. And the application keeps running i.e. the debugging session is not returning the IDE to a "code entry" state. This may suggest that something else is at play here.

The code which actually calls the API is:

    protected async Task<T> GetAsync<T>(string url)
        where T : new()
        HttpClient httpClient = CreateHttpClient();
        T result;

            var response = await httpClient.GetStringAsync(url);
            result = await Task.Run(() => JsonConvert.DeserializeObject<T>(response));
            result = new T();

        return result;

and I have tried all of the IP addresses above for the string url.

I'm using Visual Studio 2015.
I'm using the Visual Studio emulator

Any idea how I can get the emulator hitting the end point on my dev machine?
Is there a way to Ping my machine from the emulator?


Best Answer


Sign In or Register to comment.