c# - 使用 .net 4.6.2 的异步方法后 OperationContext 为 null

标签 c# wcf operationcontext

在调用async 操作(并且我的 threadid 更改)后,OperationContext 变为 null 时遇到问题。

我知道这是一个已知问题,我已经针对该问题提出了一些 StackOverflow 问题。

.net 4.6.2 中有一个问题的修复,您可以阅读 here .

OperationContext.Current Async Improvements

WCF now has the ability to include OperationContext.Current with ExecutionContext so that the OperationContext flows through asynchronous continuations. With this improvement, WCF allows CurrentContext to propagate from one thread to another thread. This means that even if there’s a context switch between calls to OperationContext.Current, it’s value will flow correctly throughout the execution of the method.

为了在我这边获得支持,我需要做什么特别的事情吗?我正在使用 VS 2013,将框架更新为 4.6.2 并安装了开发包。 我已将我的项目更改为使用 Framework 4.6.2,但在异步调用后我仍然得到一个空的 OperationContext

最佳答案

根据 Tomasz 的回答,确保您的应用配置中包含以下内容:

<appSettings>
    <add key="wcf:disableOperationContextAsyncFlow" value="false" />
</appSettings>

有关更多信息,请查看 https://github.com/Microsoft/dotnet/issues/403微软承认这实际上是一个重大变化。看起来这可以很容易地在该领域打破很多应用程序。

关于c# - 使用 .net 4.6.2 的异步方法后 OperationContext 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39702557/

相关文章:

c# - 将 async/await 与 void 方法一起使用

wcf - 将 OperationContext.Current 存储在 WCF 服务实例的实例变量中

c# - 连接字符串中的初始目录与 AttachDbFilename

entity-framework - 使用 Entity Framework 在 Silverlight4 Datagrid 中显示图像

c# - 更新面板抛出 javascript 错误 : "Microsoft JScript runtime error: Member not found"

wcf - Set-WebConfigurationProperty失败

WCF:使用 OperationContext 区分 REST 和 SOAP 请求

c# - 将 OperationContext 传播到异步 WCF 调用中

c# - 在c#中的字符串数组中添加唯一字符串

c# - 添加参数的问题