title: Cannot connect to webservice hosted on localhost from UWP app
body: <p>I was playing around with web services with Xamarin Forms. I made a simple web service that's hosted on IIS Express (that comes with VS 2015). The Web service deals with employee information.</p>
  
  <p>This worked fine initially with the Windows Emulator. But I had problems to get it to work with the Android emulator.Upon seeking help I got the following instructions from a person,</p>
  
  <p><img src="https://i.stack.imgur.com/y5HjD.png" alt="Instructions to make webservice work on android emulator"></p>
  
  <p>After following the instructions, not only did it not work in the android emulator, but the UWP app stopped working as well.</p>
  
  <p>following is where it fails</p>
  
  <pre><code>public class RestClient&lt;T&gt;
      {
          private const string WebServiceUrl = "http://localhost:52792/api/Employees/";
          //private const string WebServiceUrl = "http://services.groupkt.com/country/get/all/";
  
          public async Task&lt;List&lt;T&gt;&gt; GetAsync()
          {
              var httpClient = new HttpClient();
              httpClient.DefaultRequestHeaders.ExpectContinue = false;
              var json = "";
              try
              {
  
                 **json = await httpClient.GetStringAsync(WebServiceUrl);
              }
              catch (HttpRequestException e)
              {
                  var error = "";
                  error=e.StackTrace;
                  error = e.Source;
                  error = e.HelpLink;
                  error = e.ToString();
  
  
              }
  
              var taskModels = JsonConvert.DeserializeObject&lt;List&lt;T&gt;&gt;(json);
  
              return taskModels;
          }
  </code></pre>
  
  <p>And following is the error thrown,</p>
  
  <pre><code>System.Net.Http.HttpRequestException: An error occurred while sending the request. ---&gt; System.Runtime.InteropServices.COMException: The text associated with this error code could not be found.
  
  A connection with the server could not be established
  
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Net.Http.HttpHandlerToFilter.&lt;SendAsync&gt;d__4.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Net.Http.HttpClientHandler.&lt;SendAsync&gt;d__86.MoveNext()
     --- End of inner exception stack trace ---
     at System.Net.Http.HttpClientHandler.&lt;SendAsync&gt;d__86.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Net.Http.HttpClient.&lt;FinishSendAsync&gt;d__58.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Net.Http.HttpClient.&lt;GetContentAsync&gt;d__32`1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Plugin.RestClient.RestClient`1.&lt;GetAsync&gt;d__1.MoveNext()
  </code></pre>
  
  <p>I have little idea what went wrong here.</p>
  
  <p>Update:</p>
  
  <p>This still works fine in the Windows and Windows Phone applications
  The UWP application fails.</p>