I am now on Windows 8.1 and using VS 2012. I am using a Web api backend for all the heavy lifting in my Windows Phone app. However when I ran my app through the emulator all requests to my locally running web api where rejected.
I found that the emulator was unable to resolve localhost. After doing something very simulator in this article I was able to the Windows 8 emulator no problems.
However I need to now test it on my actual device to use the camera but I am running into the same problem as I did with the emulator. I can't communicate with my local web api.
I had no problems when I was on Windows 7 and on VS 2010. I just used the steps in the article and had no problems.
I get this error when I try to do a request to my web api from my device(the device is hooked in by usb through the 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 setup to get this to work?
Edit
I still have this problem. I been able to get the Windows Phone 8 emulator to work but still can't get my WP7 device to be able to talk to a local Web Api.
Sample Code 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
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
- I tried localhost (knew it would not work from what I read)
- tried my computer ip address
tried to put in IIS Express in the app config an ip address to use
< bindings> < binding protocol="http" bindingInformation=":55210:localhost" /> < binding protocol="http" bindingInformation=":55210:169.254.80.80" /> < /bindings>