I'm working on a proof of concept prototype.
I have Asp.Net C# web form (Visual Studio 2013, .Net 4.5) page. On a button click I do something like this:
List<Blog> blogs = null;
protected void btnLoadData_Click(object sender, EventArgs e)
{
//...;
switch (int.Parse(rblDataSource.SelectedValue))
{
//...;
case 4:
RunAsyncBlogs().Wait();
break;
default:
blogs = localGetter.GetBlogs();
break;
}
//...;
}
RunAsyncBlogs looks like this:
static async Task RunAsyncBlogs()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://localhost/wapiDemo/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// HTTP GET
HttpResponseMessage response = await client.GetAsync("api/Blogs");
if (response.IsSuccessStatusCode)
{
List<Blog> thisBlogList = await response.Content.ReadAsAsync<List<Blog>>();
var cnt = thisBlogList.Count();
}
}
}
The code stops at the response = await client.GetAsync call. When I say it stops, the debugger acts like the request has ended, but the browser is still waiting.
If I run a console app (I copy and paste the RunAsync() method into it) which calls the Web API the same way, I get my data. So, I believe the Web API app is responding as expected.