When should I use OperationContextScope inside a WCF service?

I am currently working on a WCF service that calls on another service to send information in several of its operations. The proxy for the second service is generated through the strongly typed class ProxyFactory<T> . I had no problems, but I heard that when making a call I should do something like the following:

 using (new OperationContextScope((IContextChannel)_service)) _service.Send(message); 

So my question is: when is this new OperationContextScope appropriate created and why?

Thank!

+11
c # service wcf
Mar 18
source share
1 answer

If you use callbacks or want to change the message or headers, you need to use OperationContextScope . You may need to change the outgoing headers when calling this other service.

When you set OperationContextScope , you can:

  • Access and change incoming and outgoing message headers and other properties.
  • Access to the runtime, including dispatchers, host, channel, and extensions.
  • Access to other types of contexts, such as security, instance, and request contexts.
  • Access to the channel associated with the OperationContext object or (if the channel implements System.ServiceModel.Channels.ISession ) the corresponding channel session identifier.

Another service you are calling is the session service? You probably need to see a sample client code or documentation, if available.

+14
Apr 14 '10 at 5:08
source share



All Articles