ContextBindingElement 类
定义
提供作为绑定元素上下文一部分的保护级别和交换机制以及用于生成通道侦听器和工厂的功能。Provides a protection level and an exchange mechanism as part of the context of a binding element and the functionality to build the channel listeners and factories.
public ref class ContextBindingElement : System::ServiceModel::Channels::BindingElement, System::ServiceModel::Channels::IContextBindingElement, System::ServiceModel::Description::IPolicyExportExtension
public class ContextBindingElement : System.ServiceModel.Channels.BindingElement, System.ServiceModel.Channels.IContextBindingElement, System.ServiceModel.Description.IPolicyExportExtension
type ContextBindingElement = class
inherit BindingElement
interface IPolicyExportExtension
interface IContextBindingElement
Public Class ContextBindingElement
Inherits BindingElement
Implements IContextBindingElement, IPolicyExportExtension
- 继承
- 实现
注解
ContextBindingElement 允许用户向服务的绑定中添加元素以管理其上下文交换协议。The ContextBindingElement allows the user to add an element to the binding of a service for managing its context exchange protocol. ContextBindingElement 通常堆叠在可靠性、安全性和传输绑定元素上。The ContextBindingElement is typically stacked on top of reliability, security, and transport binding elements. ContextBindingElement 不需要任何配置选项并且可以为 IRequestChannel、IRequestSessionChannel 和 IDuplexSessionChannel 创建通道工厂。A ContextBindingElement does not require any configuration options and can create channel factories for IRequestChannel, IRequestSessionChannel, and IDuplexSessionChannel. 它还可以为 IReplyChannel、IReplySessionChannel 和 IDuplexSessionChannel 创建通道侦听器。It can also create channel listeners for IReplyChannel, IReplySessionChannel, and IDuplexSessionChannel. 上下文通道不更改通道接口,基础通道堆栈必须支持请求的通道形状和会话功能。A context channel does not change the channel interface - the underlying channel stack must support the requested channel shape and session capability.
使用通道侦听器和工厂可以构造用于处理传入和传出消息的通道堆栈部分。The channel listeners and factories are used to construct the part of the channel stacks used to process incoming and outgoing messages.
备注
如果基于会话的绑定是使用创建的 ContextBindingElement ,并且与指定的协定一起使用 SessionMode = NotAllowed ,则 InvalidOperationException 在创建通道时将引发,其中包含以下文本: "通道打开后,无法启用或禁用通道上下文管理"。If a session-based binding is created with a ContextBindingElement and used with a contract that specifies SessionMode = NotAllowed, an InvalidOperationException is thrown when the channel is created with the following text: "Channel context management cannot be enabled or disabled after the channel is opened." 必须将 SessionMode 设置为 Allowed 或 Required,或不使用基于会话的通道。You must set SessionMode to Allowed or Required or not use a session-based channel.
在创建自定义绑定时,建议你在添加任何可靠性和安全性绑定元素(如果有)之前,将 ContextBindingElement 添加到自定义绑定的 BindingElementCollection。When creating a custom binding, it is recommended that you add the ContextBindingElement to the BindingElementCollection of the custom binding before adding any reliability and security binding elements, if present. 否则,服务可能会引发 ProtocolException 并显示以下消息:If you do not, your service may throw a ProtocolException with the following message:
“上下文通道收到一个消息,该消息包含的上下文与缓存在此通道的当前上下文不匹配。"Context channel received a message with context which does not match the current context cached at the channel. 请确保在对上下文进行了初始设置或者通过将通道属性‘IContextManager.Enabled’设置为 false 禁用了其上下文管理之后,服务没有更改此上下文。”Ensure service does not change context after it was originally set or disable context management by setting channel property 'IContextManager.Enabled' to false."
构造函数
| ContextBindingElement() |
初始化 ContextBindingElement 类的新实例。Initializes a new instance of the ContextBindingElement class. |
| ContextBindingElement(ProtectionLevel) |
使用指定的保护级别初始化 ContextBindingElement 类的新实例。Initializes a new instance of the ContextBindingElement class with a specified level of protection. |
| ContextBindingElement(ProtectionLevel, ContextExchangeMechanism) |
使用指定的保护级别和交换机制初始化 ContextBindingElement 类的新实例。Initializes a new instance of the ContextBindingElement class with a specified level of protection and exchange mechanism. |
| ContextBindingElement(ProtectionLevel, ContextExchangeMechanism, Uri) |
使用指定的保护级别、上下文交换机制和客户端回调地址初始化 ContextBindingElement 类的新实例。Initializes a new instance of the ContextBindingElement class with the specified protection level, context exchange mechanism, and client callback address. |
| ContextBindingElement(ProtectionLevel, ContextExchangeMechanism, Uri, Boolean) |
使用指定的保护级别、上下文交换机制、客户端回调地址和一个用于指定是否启用上下文管理的值,初始化 ContextBindingElement 类的新实例。Initializes a new instance of the ContextBindingElement class with the specified protection level, context exchange mechanism, client callback address, and a value that specifies whether context management is enabled. |
属性
| ClientCallbackAddress |
获取或设置绑定元素的客户端回调地址。Gets or sets the client callback address for the binding element. |
| ContextExchangeMechanism |
获取或设置用于传递绑定元素上下文的交换机制。Gets or sets the exchange mechanism used to communicate context for the binding element. |
| ContextManagementEnabled |
获取或设置一个指定是否已启用上下文管理的值。Gets or sets a value that specifies whether context management is enabled. |
| ProtectionLevel |
获取或设置上下文中绑定元素的安全级别。Gets or sets the level of protection for the binding element from the context. |
方法
| BuildChannelFactory<TChannel>(BindingContext) |
在客户端上生成通道工厂堆栈,该通道工厂堆栈可为指定上下文创建指定类型的通道。Builds the channel factory stack on the client that creates a specified type of channel for a specified context. |
| BuildChannelListener<TChannel>(BindingContext) |
在客户端生成通道侦听器堆栈,该通道侦听器堆栈接受针对指定上下文的具有指定类型的通道。Builds the channel listener stack on the client that accepts a specified type of channel for a specified context. |
| CanBuildChannelFactory<TChannel>(BindingContext) |
返回一个值,该值指示当前绑定元素是否可以为指定的通道类型和上下文生成工厂。Returns a value that indicates whether the current binding element can build a factory for a specified type of channel and context. |
| CanBuildChannelListener<TChannel>(BindingContext) |
返回一个值,该值指示当前绑定是否可以为指定的通道类型和上下文生成侦听器。Returns a value that indicates whether the current binding can build a listener for a specified type of channel and context. |
| Clone() |
创建一个从当前对象初始化的新 ContextBindingElement 对象。Creates a new ContextBindingElement object initialized from the current one. |
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| ExportPolicy(MetadataExporter, PolicyConversionContext) |
将自定义策略断言写入到绑定元素的上下文中。Writes custom policy assertions into the context of the binding element. |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetProperty<T>(BindingContext) |
从通道堆栈的适当层返回具有指定上下文的类型化对象。Returns the typed object with the specified context from the appropriate layer in the channel stack. |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |