OperationContext.Current 为 null,所有其他上下文也是如此
我有一个 WCF 服务定义如下:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.PerCall)]
public partial class FrontEndService : IFrontEndService
但是,大多数时候(但并非总是)InstanceContext.Current
为 null,以及 HttpContext.Current
和 OperationContext.Current
也是 null。
我缺少什么?我想要做的是将一些数据存储在 HttpContext.Current.Items 或在请求长度内存在的类似集合中。
I have a WCF service defined as following:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(IncludeExceptionDetailInFaults = true, InstanceContextMode = InstanceContextMode.PerCall)]
public partial class FrontEndService : IFrontEndService
However, most of the time (but not always) InstanceContext.Current
is null, as well as HttpContext.Current
and OperationContext.Current
is also null.
What am I missing? What I want to do is store some data in HttpContext.Current.Items
or a similar collection that exists for the length of the request.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该服务只是从另一个线程调用,而不是通过 HTTP,这就是所有上下文都为空的原因。
The service was just being called from another thread, and not via HTTP, that's why all Contexts were null.