我使用基于任务的操作生成了代理.
如何使用async/await 正确调用此服务(处理ServiceClient和OperationContext之后)?
我的第一次尝试是:
public async Task<HomeInfo> GetHomeInfoAsync(DateTime timestamp)
{
using (var helper = new ServiceHelper<ServiceClient, ServiceContract>())
{
return await helper.Proxy.GetHomeInfoAsync(timestamp);
}
}
Run Code Online (Sandbox Code Playgroud)
作为ServiceHelper一个创造ServiceClient和OperationContextScope后来处理它们的类:
try
{
if (_operationContextScope != null)
{
_operationContextScope.Dispose();
}
if (_serviceClient != null)
{
if (_serviceClient.State != CommunicationState.Faulted)
{
_serviceClient.Close();
}
else
{
_serviceClient.Abort();
}
}
}
catch (CommunicationException)
{
_serviceClient.Abort();
}
catch (TimeoutException)
{
_serviceClient.Abort();
}
catch (Exception)
{
_serviceClient.Abort();
throw;
}
finally …Run Code Online (Sandbox Code Playgroud) 我有一个WCF服务,我从Windows服务调用.
WCF服务运行一个SSIS包,该包可能需要一段时间才能完成,我不希望我的Windows服务必须等待它完成.
如何使我的WCF服务调用异步?(或者它是默认的异步?)