相关疑难解决方法(0)

使用async/await调用WCF服务的模式

我使用基于任务的操作生成了代理.

如何使用async/await 正确调用此服务(处理ServiceClientOperationContext之后)?

我的第一次尝试是:

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一个创造ServiceClientOperationContextScope后来处理它们的类:

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)

.net c# asp.net wcf async-await

59
推荐指数
2
解决办法
5万
查看次数

如何异步调用我的WCF服务?

我有一个WCF服务,我从Windows服务调用.

WCF服务运行一个SSIS包,该包可能需要一段时间才能完成,我不希望我的Windows服务必须等待它完成.

如何使我的WCF服务调用异步?(或者它是默认的异步?)

.net c# wcf windows-services

25
推荐指数
3
解决办法
6万
查看次数

标签 统计

.net ×2

c# ×2

wcf ×2

asp.net ×1

async-await ×1

windows-services ×1