I' am developing a WebApi with the latest ASP.Net 5 RC1. The data provider is a third-party WCF service. I only have the contract (shipped as a dll which contains the service interface) and I want to call service operation asynchronously but that wcf service does not provide async operations. So I just try to figure out the right pattern I should use. So currently, the service client class looks like this (MyServiceClient : IMyServiceClient):
ChannelFactory<IServiceInterface> channelFactory;
...
public IResult DoAServiceCall(object param)
{
var channel = channelFactory.CreateChannel();
return channel.DoSomething(new Request() {Param = param});
}
public async Task<IResult> DoAServiceCallAsync(object param)
{
var result = await Task.Run(() => DoAServiceCall(param));
return result;
}
And the WebApi controller is like this:
public class SampleController : Controller
{
private IMyServiceClient serviceClient;
public SampleController(IMyServiceClient serviceClient)
{
this.serviceClient = serviceClient
}
[HttpGet]
[Route("api/getsomething")]
public async Task<IResult> Get(int p)
{
return await serviceClient.DoAServiceCallAsync(p);
}
}
Is this a good pattern to do an asynchronous service call? Or what is the good and effective implementation of this case?
Thank you in advance.