Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a web service using the new async/await syntax

Can anyone point me to an example of calling a web service (not WCF) from C# using the new async/await syntax? Something like this:

public async Task<List<Widgets>> GetWidgetsAsync()
{
    var proxy = new Service1();
    var response = await proxy.GetWidgetsAsync();
    return response.Result;
}
like image 403
Sisiutl Avatar asked Mar 13 '14 17:03

Sisiutl


1 Answers

For a WCF service, when you add a reference and generate a proxy, there are options to generate either Task-based async methods or APM-based BeginXXX/EndXXX async methods.

I'm not sure about referencing the old-style XML Web service (asmx), but I think at least the second option should be there for it. In which case, you may wrap BeginXXX/EndXXX with Task.Factory.FromAsync, as described here.

like image 181
noseratio Avatar answered Sep 24 '22 02:09

noseratio