ContextBindingElement 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在绑定元素的上下文中提供保护级别和交换机制,以及构建通道侦听器和工厂的功能。
public ref class ContextBindingElement : System::ServiceModel::Channels::BindingElement, System::ServiceModel::Channels::IContextBindingElement, System::ServiceModel::Description::IPolicyExportExtensionpublic class ContextBindingElement : System.ServiceModel.Channels.BindingElement, System.ServiceModel.Channels.IContextBindingElement, System.ServiceModel.Description.IPolicyExportExtensiontype ContextBindingElement = class
    inherit BindingElement
    interface IPolicyExportExtension
    interface IContextBindingElementPublic Class ContextBindingElement
Inherits BindingElement
Implements IContextBindingElement, IPolicyExportExtension- 继承
- 实现
注解
ContextBindingElement 允许用户将元素添加到服务的绑定,以管理其上下文交换协议。 ContextBindingElement 通常堆叠在可靠性、安全性和传输绑定元素之上。 ContextBindingElement 不需要任何配置选项,并且可以为 IRequestChannel、IRequestSessionChannel和 IDuplexSessionChannel创建通道工厂。 它还可以为 IReplyChannel、IReplySessionChannel和 IDuplexSessionChannel创建通道侦听器。 上下文通道不会更改通道接口 - 基础通道堆栈必须支持请求的通道形状和会话功能。
通道侦听器和工厂用于构造用于处理传入和传出消息的通道堆栈的一部分。
注意
如果使用 ContextBindingElement 创建基于会话的绑定,并与指定 SessionMode = NotAllowed的协定一起使用,则当使用以下文本创建通道时,将引发 InvalidOperationException:“打开通道后无法启用或禁用通道上下文管理。必须将 SessionMode 设置为 Allowed 或 Required 或使用基于会话的通道。
创建自定义绑定时,建议在添加任何可靠性和安全绑定元素之前将 ContextBindingElement 添加到自定义绑定的 BindingElementCollection(如果存在)。 否则,服务可能会引发 ProtocolException,并显示以下消息:
“上下文通道收到一条消息,该消息的上下文与通道中缓存的当前上下文不匹配。 通过将通道属性“IContextManager.Enabled”设置为 false,确保服务在最初设置或禁用上下文管理后不会更改上下文。
构造函数
| ContextBindingElement() | 初始化 ContextBindingElement 类的新实例。 | 
| ContextBindingElement(ProtectionLevel, ContextExchangeMechanism, Uri, Boolean) | 使用指定的保护级别、上下文交换机制、客户端回调地址和指定是否启用上下文管理的值初始化 ContextBindingElement 类的新实例。 | 
| ContextBindingElement(ProtectionLevel, ContextExchangeMechanism, Uri) | 使用指定的保护级别、上下文交换机制和客户端回调地址初始化 ContextBindingElement 类的新实例。 | 
| ContextBindingElement(ProtectionLevel, ContextExchangeMechanism) | 使用指定的保护和交换机制级别初始化 ContextBindingElement 类的新实例。 | 
| ContextBindingElement(ProtectionLevel) | 使用指定的保护级别初始化 ContextBindingElement 类的新实例。 | 
属性
| ClientCallbackAddress | 获取或设置绑定元素的客户端回调地址。 | 
| ContextExchangeMechanism | 获取或设置用于通信绑定元素上下文的交换机制。 | 
| ContextManagementEnabled | 获取或设置一个值,该值指定是否启用上下文管理。 | 
| ProtectionLevel | 获取或设置上下文中绑定元素的保护级别。 | 
方法
| BuildChannelFactory<TChannel>(BindingContext) | 在客户端上生成通道工厂堆栈,该堆栈为指定的上下文创建指定类型的通道。 | 
| BuildChannelListener<TChannel>(BindingContext) | 在客户端上生成通道侦听器堆栈,该堆栈接受指定上下文的指定通道类型。 | 
| CanBuildChannelFactory<TChannel>(BindingContext) | 返回一个值,该值指示当前绑定元素是否可以为指定的通道和上下文类型生成工厂。 | 
| CanBuildChannelListener<TChannel>(BindingContext) | 返回一个值,该值指示当前绑定是否可以为指定的通道和上下文类型生成侦听器。 | 
| Clone() | 创建从当前对象初始化的新 ContextBindingElement 对象。 | 
| Equals(Object) | 确定指定的对象是否等于当前对象。(继承自 Object) | 
| ExportPolicy(MetadataExporter, PolicyConversionContext) | 将自定义策略断言写入绑定元素的上下文中。 | 
| GetHashCode() | 用作默认哈希函数。(继承自 Object) | 
| GetProperty<T>(BindingContext) | 从通道堆栈中的相应层返回具有指定上下文的类型化对象。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object的浅表副本。(继承自 Object) | 
| ToString() | 返回一个表示当前对象的字符串。(继承自 Object) |