Saturday, April 05, 2014

Synchronous call to ASP.NET WebAPI

Being on older technology stack I was unable to use the Async based code sample for webAPI
so this is my current work around. I am using VS 2010 .NET framework 4.0

public string testapi()
 {
using (var client = new HttpClient())
{
var response = client.GetAsync("http://localhost:3507/api/course").Result;
var result = response.Content.ReadAsStringAsync().Result;
return result;
}
}