wcf - OperationContext.Current 为 null,所有其他上下文也是如此

标签 wcf httpcontext

我有一个 WCF 服务定义如下:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.PerCall)]
public partial class FrontEndService : IFrontEndService

但是,大多数时候(但并非总是)InstanceContext.Current 为 null,HttpContext.CurrentOperationContext.Current 也是如此> 也为空。

我错过了什么?我想要做的是将一些数据存储在 HttpContext.Current.Items 或请求长度内存在的类似集合中。

最佳答案

该服务只是从另一个线程调用,而不是通过 HTTP,这就是所有上下文都为 null 的原因。

关于wcf - OperationContext.Current 为 null,所有其他上下文也是如此,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2862366/

相关文章:

wcf - 使用 WCF 的 basicHttpBinding 进行 Windows 身份验证

WCF:每次调用 session 超时

asp.net-mvc - MVC 属性中的 HttpContext - 线程问题?

c# - Url Referrer 在 WebApi 2 MVC 项目中不可用

c# - 在 Parallel.For 内部调用的方法中 HttpContext 为 null

c# - WCF - 通过 HTTP 抛出客户端和服务绑定(bind)不匹配异常的二进制编码

wcf - WCF 的开源替代方案

c# - WCF - Visual Studio 不会生成 SVC 文件

c# - 测试使用 HttpContext.Current.Request.Files 的 Web API 方法?

c# - 为什么我的抽象基 Controller 中的 User(如 User.Identity.Name)为 null?