Allow for non-asynchronous calls to the Web API
It looks like the synchronous code was removed or not ported from WCF Web API to the new ASP.NET Web API. It would be nice to have that back while we're still on .NET 4 without the 4.5 async features. My code went from 5 lines to 16, just to make a request and get a response.
You can now use the Async Targeting Pack for Visual Studio 2012 to use the new await keyword when targeting .NET 4, so we don’t believe adding sync APIs is needed:
http://www.microsoft.com/en-us/download/details.aspx?id=29576
5 comments
-
tugberk
commented
@skippyfire it has go-live license, my friend. I am not a lawyer but it means official support.
Best way of making both sides happy here is to provide extensions library for sync methods. I cannot stand to see `GetSync` method.
BTW, see this blog post: http://www.tugberkugurlu.com/archive/my-take-on-task-base-asynchronous-programming-in-c-sharp-5-0-and-asp-net-mvc-web-applications
There is a benchmark there composed by a load test. Take a look at the result and see how evil sync methods are for a website which gets lots of traffic and deals with long running I/O operations.
-
skippyfire
commented
@Piers Yeah, I did get a way of doing this, but it's a little roundabout. I think it would be nice to have a GetSync version of the method, at least for now while the async code is still ugly.
@tugberk I don't consider a CTP to be "support".
-
tugberk
commented
this's an awful idea. Please do not make this happen!
If you are on .NET 4.0, you already have the async support. Just go and get the Visual Studio Async CTP.
If you must support this, please do not do this out of the box. Make a new extensions library (HttpClientSync maybe) and provide extensions. I do not wanna see the sync versions of those methods.
-
There are cases where .Result and .Wait() can be dangerous, so we are considering making safe synchronous versions of the HttpClient APIs available. In general, blocking the thread is a bad thing, but writting correct async code on .NET 4 is still very difficult. Vote this one up if you think this is important.
-
Piers
commented
Looks like you got an answer at:
http://forums.asp.net/t/1772530.aspx/1?Making+a+request+synchronously