ContextExchangeMechanism 枚举


指定 HTTP Cookie 或 SOAP 标头是否是交换客户端和服务之间对话的上下文所用的机制。Specifies whether an HTTP cookie or a SOAP header is the mechanism used to exchange context for a conversation between a client and service.

public enum class ContextExchangeMechanism
public enum ContextExchangeMechanism
type ContextExchangeMechanism = 
Public Enum ContextExchangeMechanism


ContextSoapHeader 0

使用 SOAP 标头来交换上下文。A SOAP header is used to exchange context. 这是默认的交换机制。This is the default exchange mechanism.

HttpCookie 1

使用 HTTP Cookie 来交换上下文。An HTTP cookie is used to exchange context.


使用 ContextExchangeMechanism 属性或 ContextBindingElement(ProtectionLevel, ContextExchangeMechanism) 构造函数可以为客户端和服务之间的对话指定 ContextExchangeMechanism 值。Use the ContextExchangeMechanism property or the ContextBindingElement(ProtectionLevel, ContextExchangeMechanism) constructor to specify the value of the ContextExchangeMechanism for a conversation between a client and service.

需求支持上下文交换协议的服务终结点可以在其发布的策略中明确此需求。Service endpoints that require support for the context exchange protocol can make this requirement explicit in their published policy. 表示要求客户端支持 SOAP 级上下文交换协议或表示要求启用 HTTP Cookie 支持的策略断言可以由终结点发布。Policy assertions that represent the requirement for the client to support the context exchange protocol at the SOAP level or that require the enabling of HTTP cookie support can be published by an endpoint. 如何将这些断言生成到服务策略中是由 ContextExchangeMechanism 属性的值控制的,如下所示:The generation of these assertions into the policy on the service is controlled by the value of the ContextExchangeMechanism property as follows:

  • 对于 HttpCookie, 将生成以下断言:For HttpCookie, the following assertion is generated:

    <HttpUseCookie xmlns=""/>  
  • 对于 ContextSoapHeader, 将生成以下断言:For ContextSoapHeader, the following assertion is generated:

    protectionLevel="Sign" />  

HttpCookie 枚举是在传输层实现的。The HttpCookie enumeration is implemented at the transport layer. 在客户端发出初始请求,然后由服务在响应答复时提供上下文的单工通信情况下,可以使用此枚举。This can be used in the case of simplex communication, where the client makes an initial request and the context is provided by the service on the corresponding reply. 在该对话的生存期内,客户端和服务之间的所有后续消息都将包含此上下文。All subsequent messages between the service and client for the lifetime of that conversation contain the context. 对于使用 HTTP 传输的服务终结点以及同意允许使用 HTTP cookie 的客户端, 可使用 HttpCookie 枚举来交换应用程序上下文。For service endpoints that use an HTTP transport and clients that agree to allow the use of HTTP cookies, the HttpCookie enumeration can be utilized to exchange the application context. 当使用 HTTP Cookie 来传播上下文时,应使用传输安全来保护 HTTP Cookie。When HTTP cookies are used to propagate context, they should be protected using transport security. 此机制不能与非 HTTP 传输一起使用。This mechanism cannot be used with non-HTTP transports.

ContextSoapHeader 枚举提供了一个替代方法, 该方法在自定义上下文通道中实现, 并且可用于非 HTTP 传输和其他消息交换模式, 如请求-答复和双工会话。The ContextSoapHeader enumeration provides an alternative that is implemented in a custom context channel and that can be used with non-HTTP transports and other message exchange pattern, such as request-reply, and a duplex session. 此上下文交换协议提供一种基于 SOAP 的功能,它等效于 HTTP Cookie 在传输层提供的功能。This context exchange protocol provides a SOAP-based equivalent of the feature offered by HTTP cookies at the transport layer. 它引入了新的 wsc:Context SOAP 标头来表示上下文信息。It introduces a new wsc:Context SOAP header to represent the context information. 和必须保护 WS-Addressing 标头一样,在传输过程中必须保护 wsc:Context 标头不被修改:到达后,这些标头用于将消息调度到正确的工作流实例。The wsc:Context header must be protected from modification while in transit for the same reason as the WS-Addressing headers must be protected: upon arrival, these headers are used to dispatch the message to the correct workflow instances. 因此,当绑定提供消息保护功能时,wsc:Context 标头必需在 SOAP 或传输级进行数字签名。The wsc:Context header is therefore required to be digitally signed at either SOAP or transport level when the binding offers message protection capability.

通道层使用 ContextMessageProperty 与应用程序层之间来回传递上下文。The channel layer communicates the context to and from the application layer using ContextMessageProperty.