开发者

CallContext in WCF

Is is safe to use CallContext when request arrives to WCF servic开发者_Python百科e, initialize it with some call specific data (for instance using hook at the beginning of call: Inspector/ContextBoundObject), and then reuse it in the call, and be guarantied that data I access is all the time the same data?

Thanks, Pawel


If you aren't using it from inspectors then it should be safe, but if you are not using Remoting or crossing an AppDomain boundary then it is probably simpler to just use a thread static field. Put a ThreadStaticAttribute on a static field and it will be a separate storage location in each thread.

If you are trying to set values in an IDispatchMessageInspector, for example, then it won't work since those will run in a separate thread from the request. Take a look at OperationContext, which will provide call-specific information about a WCF request. You can add extensions to it that can store custom data by implementing IExtension<OperationContext> and adding them to the Extensions property. Here is a blog post that describes how to add custom data to the OperationContext.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜