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://10.0.2.2:57971", "http://192.168.44.1:57971", "http://192.168.1.48:57971", "http://*:57971")

where:

192.168.44.1 is Desktop Adapter #2 on the emulator Networks settings tab

10.0.2.2 is the special address for the Android emulator, as set out in Google's doco (possibly not relevant to Xamarin) and

192.168.1.48 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;

        try
        {
            var response = await httpClient.GetStringAsync(url);
            result = await Task.Run(() => JsonConvert.DeserializeObject<T>(response));
        }
        catch
        {
            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 https://www.visualstudio.com/vs/msft-android-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?

Thanks

Best Answer

Answers

Sign In or Register to comment.