On my web server (ASP.NET MVC 4) I am calling web services (asmx) on another server. I have generated client from WSDL. There are sync methods and async methods (callbacks, not Tasks).
I transform it to task oriented call (with TaskCompletionSource
) and then i call await
like this:
public async Task<DataObject> GetData()
{
var tcs = new TaskCompletionSource<DataObject>();
var client = new WebServiceClient();
client.GetDataCompleted += (sender, args) => tcs.SetResult(args.Result);
client.GetDataAsync();
return await tcs.Task;
}
After that I use async
/await
everywhere. Does this make any sense? I think that when the web service is being called I save one thread with this aproach - am I right? Does the web service client block a thread when async loading? If so I could use sync methoad instead:
public DataObject GetData()
{
var client = new WebServiceClient();
return client.GetData();
}
Thanks
BTW: I am using ASP.NET MVC 4, targeting .NET 4 (because I have to). For async
/await
compatibility I am using Microsoft.Bcl.Async library.