This is my code:
1 HttpClient client = new HttpClient();
2 client.BaseAddress = new Uri("http://localhost/");
3 HttpResponseMessage message = client.GetAsync("api/MyAPI").Result;
4 IEnumerable<string> supplies =
message.Content.ReadAsAsync<IEnumerable<string>>().Result;
5 return View(supplies);
And the error occurs on line 3 Error:404
But When I use Visual Studio 2010 development server, no errors occur.
Essentially you have to take care of the cases yourself here.
For development the path to your API is :
And for production on IIS it is:
The simplest way, which is what we do in fact at my company, is, put the base path into a configuration (Application Settings maybe) and then do this:
When you deploy to IIS change
Settings.BaseUrltohttp://localhost/WebAPITest/.Ideally you could also drop the VS development server and debug on IIS. (This requires VS running with administrator rights)