IContextManager 介面

定義

定義可讓您取得和設定通道內容的介面。Defines an interface that allows you to get and set the context on the channel.

public interface class IContextManager
public interface IContextManager
type IContextManager = interface
Public Interface IContextManager

備註

針對使用 WSHttpContextBinding 且設定 NotAllowed 值的通道,在使用 IContextManager 的用戶端上會無法擷取內容,因為每次呼叫 GetProperty 時,就會建立新的通道來建立工作階段,強制在通道上執行 NotAllowed 語意。For channels that use WSHttpContextBinding with the NotAllowed value set, the context cannot be retrieved on the client using IContextManager because a new channel that establishes a session is created each time GetProperty is called to enforce NotAllowed semantics on a channel. 這表示,在這個例子中,即使內容已適當傳播回用戶端,也無法使用 IContextManager 加以擷取。This means that even though the context is properly propagated back to the client in this case, it cannot be retrieved using IContextManager. 您仍然可以使用 ContextMessageProperty 來擷取它,如下列程式碼所示。You can still retrieve it using ContextMessageProperty as shown in the following code.

using (new OperationContextScope((IContextChannel)channel))  
{  
    channel.MyChannel("Test");  
    ContextMessageProperty context;  
    if (ContextMessageProperty.TryGet(OperationContext.Current.IncomingMessageProperties, out context))  
    {  
        Console.WriteLine(context.Count);  
    }  
}  
  

屬性

Enabled

取得或設定值,這個值表示內容管理是否已啟用。Gets or sets a value that indicates whether the context management is enabled.

方法

GetContext()

取得內容。Gets the context.

SetContext(IDictionary<String,String>)

設定內容。Sets the context.

適用於