Editare

Partajați prin


IContextManager.Enabled Property

Definition

Gets or sets a value that indicates whether the context management is enabled.

public:
 property bool Enabled { bool get(); void set(bool value); };
public bool Enabled { get; set; }
member this.Enabled : bool with get, set
Public Property Enabled As Boolean

Property Value

true if the context is enabled; otherwise, false.

Remarks

When context management is enabled the context channel caches the context in its lifetime. Context can be retrieved from the channel through the IContextManager channel property by calling GetContext method on it. The channel can also be pre-initialized with context before being opened by calling the SetContext method on the channel property. Once the channel is initialized with context it cannot be reset.

The following are invariants in this mode:

  • Any call to SetContext after the channel is open throws an InvalidOperationException.

  • Any attempt to send context through the ContextMessageProperty in an outgoing message throws InvalidOperationException.

  • If a message is received from the server with context, when the channel is already initialized with a context a ProtocolException is thrown. Note that you can receive initial context from a server if the channel is opened without explicitly setting the context.

  • The ContextMessageProperty on an incoming message is always null.

When context management is not enabled, the context channel does not manage context. It is the application's responsibility to retrieve, manage and apply context through the ContextMessageProperty. Any attempt to call GetContext or SetContext using through the IContextManager channel property results in InvalidOperationException.

All HTTP cookies, except for context HTTP cookies, are handled at the channel level. Context HTTP cookies are managed at the application level. This can have unexpected consequences when channels are shared to talk to different instances targeted by ContextMessageProperty. The following table shows how HTTP cookies are affected when Enabled is set to either true or false.

Binding IContextManager.Enabled Value Context HTTP Cookie Scope Other HTTP Cookies Scope
BasicHttpBinding n/a ChannelFactory ChannelFactory
BasicHttpContextBinding true Channel Channel
BasicHttpContextBinding false For each message (explicitly managed by application) Channel

Applies to