I am now on Windows 8.1 and using VS 2012. I use the backend for web applications for all the hard work in my Windows Phone application. However, when I ran the application through the emulator, all requests for a locally executed web api were rejected.
I found that the emulator was unable to resolve localhost. Having done something very simulator in this article, I could not solve the problem with the Windows 8 emulator.
However, I need to test it on my device itself in order to use the camera, but I ran into the same problem as the emulator. I cannot communicate with my local web airline.
I had no problems when I was in Windows 7 and VS 2010. I just used the steps in this article and had no problems.
I get this error when I try to execute a request for my web api from my device (the device is connected via usb via computer)
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\"http://www.w3.org/TR/html4/strict.dtd\">
<HTML>
<HEAD>
<TITLE>Bad Request</TITLE>
<META HTTP-EQUIV=\"Content-Type\" Content=\"text/html; charset=us-ascii\">
</HEAD>
<BODY>
<h2>Bad Request - Invalid Hostname</h2>
<hr>
<p>HTTP Error 400. The request hostname is invalid.</p>
</BODY>
</HTML>
What do I need to configure in order to make this work?
Edit
I still have this problem. I was able to get the Windows Phone 8 emulator to work, but still can't get my WP7 device to be able to talk to the local web api.
Code sample
I will do something like this
public class CourseService
{
public const string webApiUrl = "http://localhost:4372/api/values";
RestClient client = new RestClient(webApiUrl);
public void GetCourses(Action successCallback, Action<string> errorCallBack, bool forceError = false)
{
var request = new RestRequest(Method.GET);
client.ExecuteAsync(request, response =>
{
if (forceError)
{
errorCallBack("Failed");
}
else
{
if (response.StatusCode == HttpStatusCode.OK)
{
successCallback();
}
else
{
errorCallBack("Failed");
}
}
});
}
}
public class ValuesController : ApiController
{
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
- I tried localhost (knew that this would not work with what I read)
- tried the IP address of my computer.
tried to set ip address application in IIS Express to use
< > < binding protocol = "http" bindingInformation = ": 55210: localhost" /" > < binding protocol = "http" bindingInformation = ": 55210: 169.254.80.80 "/" > </ >