系统提供的绑定System-provided bindings

绑定可指定在与终结点通话时所使用的通信机制,并指示如何连接到终结点。Bindings specify the communication mechanism to use when talking to an endpoint and indicate how to connect to an endpoint. 绑定包含以下元素:A binding contains the following elements:

  • 协议堆栈确定用于发送到终结点的消息的安全性、可靠性和上下文流设置。The protocol stack determines the security, reliability, and context flow settings to use for messages that are sent to the endpoint.

  • 传输确定将消息发送到终结点时使用的基础传输协议,例如 TCP 或 HTTP。The transport determines the underlying transport protocol to use when sending messages to the endpoint, for example, TCP or HTTP.

  • 编码确定用于发送到终结点的消息的连网编码。The encoding determines the wire encoding to use for messages that are sent to the endpoint. 例如,文本/XML、二进制或消息传输优化机制 (MTOM)。For example, text/XML, binary, or Message Transmission Optimization Mechanism (MTOM).

本文介绍了系统提供的所有 Windows Communication Foundation (WCF) 绑定。This article presents all of the system-provided Windows Communication Foundation (WCF) bindings. 如果这些绑定都不符合应用程序的确切标准,则可创建自定义绑定。If none of these bindings meets the exact criteria for your application, you can create a custom binding. 有关创建自定义绑定的详细信息,请参阅自定义绑定For more information about creating custom bindings, see Custom Bindings.

通过支持 WS-Federation 协议的安全的、可互操作的绑定,联盟中的组织可以高效地对用户进行身份验证和授权。A secure and interoperable binding that supports the WS-Federation protocol enables organizations that are in a federation to efficiently authenticate and authorize users.

重要

始终选择包括安全性的绑定。Always select a binding that includes security. 默认情况下,除 <basicHttpBinding> 元素外的所有绑定都已启用安全性。By default, all bindings except the <basicHttpBinding> element have security enabled. 如果不选择安全绑定或禁用安全性,请务必以某种其他方式保护数据,如将其存储在受保护的数据中心中或隔离网络上。If you do not select a secure binding or disable security, be sure to protect your data in some other manner, such as storing in a secured data center or on an isolated network.

重要

除非以某种其他方式保护数据,否则决不要将双工协定与不支持安全性或已禁用安全性的绑定一起使用。Never use duplex contracts with bindings that do not support security or that have security disabled unless you secure the data by some other means.

WCF 附带有以下绑定:The following bindings ship with WCF:

绑定Binding 配置元素Configuration Element 描述Description
BasicHttpBinding <basicHttpBinding><basicHttpBinding> 一个绑定,适用于与符合 WS-Basic Profile 的 Web 服务(例如基于 ASP.NET Web 服务 (ASMX) 的服务)进行的通信。A binding that is suitable for communicating with WS-Basic Profile-conformant Web services, for example, ASP.NET Web services (ASMX)-based services. 此绑定使用 HTTP 作为传输协议,并使用文本/XML 作为默认的消息编码。This binding uses HTTP as the transport and text/XML as the default message encoding.
WSHttpBinding <wsHttpBinding><wsHttpBinding> 一个安全且可互操作的绑定,适合于非双工服务约定。A secure and interoperable binding that is suitable for non-duplex service contracts.
WSDualHttpBinding <wsDualHttpBinding><wsDualHttpBinding> 一个安全且可互操作的绑定,适用于双工服务协定或通过 SOAP 媒介进行的通信。A secure and interoperable binding that is suitable for duplex service contracts or communication through SOAP intermediaries.
WSFederationHttpBinding <wsFederationHttpBinding><wsFederationHttpBinding> 一个支持 WS 联合身份验证协议的安全的、可互操作的绑定,使联盟中的组织可以高效地对用户进行身份验证和授权。A secure and interoperable binding that supports the WS-Federation protocol, which enables organizations that are in a federation to efficiently authenticate and authorize users.
NetHttpBinding <netHttpBinding><netHttpBinding> 为使用 HTTP 或 WebSocket 服务而设计且默认情况下使用二进制编码的绑定。A binding designed for consuming HTTP or WebSocket services that uses binary encoding by default.
NetHttpsBinding <netHttpsBinding><netHttpsBinding> 为使用 HTTP 或 WebSocket 服务而设计且默认情况下使用二进制编码的安全绑定。A secure binding designed for consuming HTTP or WebSocket services that uses binary encoding by default.
NetTcpBinding <netTcpBinding><netTcpBinding> 一个安全且经过优化的绑定,适用于 WCF 应用程序之间跨计算机的通信。A secure and optimized binding suitable for cross-machine communication between WCF applications.
NetNamedPipeBinding <netNamedPipeBinding><netNamedPipeBinding> 一个安全、可靠且经过优化的绑定,适用于 WCF 应用程序之间计算机上的通信。A secure, reliable, optimized binding that is suitable for on-machine communication between WCF applications.
NetMsmqBinding <netMsmqBinding><netMsmqBinding> 一个排队绑定,适用于 WCF 应用程序之间的计算机间的通信。A queued binding that is suitable for cross-machine communication between WCF applications.
NetPeerTcpBinding <netPeerTcpBinding><netPeerTcpBinding> 一个支持多计算机安全通信的绑定。A binding that enables secure, multiple machine communication.
MsmqIntegrationBinding <msmqIntegrationBinding><msmqIntegrationBinding> 一个适合于 WCF 应用程序和现有消息队列应用程序之间的跨计算机通信的绑定。A binding that is suitable for cross-machine communication between a WCF application and existing Message Queuing applications.
BasicHttpContextBinding <basicHttpContextBinding><basicHttpContextBinding> 一个绑定,适用于与符合 WS-Basic Profile 且允许使用 HTTP Cookie 交换上下文的 Web 服务进行的通信。A binding suitable for communicating with WS-Basic Profile conformant Web services that enables HTTP cookies to be used to exchange context.
NetTcpContextBinding <netTcpContextBinding><netTcpContextBinding> 一个安全且经过优化的绑定,适用于允许使用 SOAP 标头交换上下文的 WCF 应用程序之间跨计算机的通信。A secure and optimized binding suitable for cross-machine communication between WCF applications that enables SOAP headers to be used to exchange context.
WebHttpBinding <webHttpBinding><webHttpBinding> 一个绑定,可用于为通过 HTTP 请求(而不是 SOAP 消息)公开的 WCF Web 服务配置终结点。A binding used to configure endpoints for WCF Web services that are exposed through HTTP requests instead of SOAP messages.
WSHttpContextBinding <wsHttpContextBinding><wsHttpContextBinding> 一个安全且可互操作的绑定,适用于允许使用 SOAP 标头交换上下文的非双工服务协定。A secure and interoperable binding suitable for non-duplex service contracts that enables SOAP headers to be used to exchange context.
UdpBinding <udpBinding><udpBinding> 同时向大量客户端发送突然爆发出的简单消息时使用的绑定。A binding to use when sending a burst of simple messages to a large number of clients simultaneously.

下表显示系统提供的每个绑定的功能。The following table shows the features of each of the system-provided bindings. 在表列中可找到绑定;在行中列出了功能,在第二个表中描述了这些功能。The bindings are found in the table columns; the features are listed in the rows and described in a second table. 下表提供所用绑定缩写的概要。The following table provides a key for the binding abbreviations used. 若要选择绑定,应确定哪列能满足所需的所有行中的功能。To select a binding, determine which column satisfies all of the row features you need.

绑定Binding 互操作性Interoperability 安全性(默认)Security (Default) 会话Session
(默认)(Default)
事务Transactions 双工Duplex 编码(默认)Encoding (Default) 流式处理Streaming
(默认)(Default)
BasicHttpBinding Basic Profile 1.1(基本配置文件 1.1)Basic Profile 1.1 (无)、传输、消息、混合(None), Transport, Message, Mixed (无)(None) (无)(None) n/an/a 文本、(MTOM)Text, (MTOM) Yes
(缓冲式)(buffered)
WSHttpBinding WSWS 传输、(消息)、混合Transport, (Message), Mixed (无)、可靠会话、安全会话(None), Reliable Session, Security Session (无)、是(None), Yes n/an/a (文本)、MTOM(Text), MTOM No
WSDualHttpBinding WSWS (消息)、无(Message), None (可靠会话)、安全会话(Reliable Session), Security Session (无)、是(None), Yes Yes (文本)、MTOM(Text), MTOM No
WSFederationHttpBinding WS-FederationWS-Federation (消息)、混合、无(Message), Mixed, None (无)、可靠会话、安全会话(None), Reliable Session, Security Session (无)、是(None), Yes No (文本)、MTOM(Text), MTOM No
NetHttpBinding .NET.NET (无)、传输、消息、TransportWithMessageCredential、TransportCredentialOnly(None), Transport, Message, TransportWithMessageCredential, TransportCredentialOnly 请参见下面的注释See note below NoneNone 请参见下面的注释See note below (二进制)、文本、MTOM(Binary), Text, MTOM 是(缓冲式)Yes (buffered)
NetHttpsBinding .NET.NET (传输)、TransportWithMessageCredential(Transport), TransportWithMessageCredential 请参见下面的注释See note below NoneNone 请参见下面的注释See note below (二进制)、文本、MTOM(Binary), Text, MTOM Yes
(缓冲式)(buffered)
NetTcpBinding .NET.NET (传输)、消息、无、混合(Transport), Message, None, Mixed (传输)、可靠会话、安全会话(Transport), Reliable Session, Security Session (无)、是(None), Yes Yes 二进制Binary Yes
(缓冲式)(buffered)
NetNamedPipeBinding .NET.NET (传输)、无(Transport), None 无、(传输)None, (Transport) (无)、是(None), Yes Yes 二进制Binary Yes
(缓冲式)(buffered)
NetMsmqBinding .NET.NET 消息、(传输)、无Message, (Transport), None (无)、传输(None), Transport 无、(是)None, (Yes) No 二进制Binary No
NetPeerTcpBinding 对等Peer (传输)(Transport) (无)(None) (无)(None) Yes No
MsmqIntegrationBinding MSMQMSMQ (传输)(Transport) (无)(None) 无、(是)None, (Yes) n/an/a n/an/a No
BasicHttpContextBinding Basic Profile 1.1(基本配置文件 1.1)Basic Profile 1.1 (无)、传输、消息、混合(None), Transport, Message, Mixed (无)(None) (无)(None) n/an/a 文本、(MTOM)Text, (MTOM) Yes
(缓冲式)(buffered)
NetTcpContextBinding .NET.NET (传输)、消息、无、混合(Transport), Message, None, Mixed (传输)、可靠会话、安全会话(Transport), Reliable Session, Security Session (无)、是(None), Yes Yes 二进制Binary Yes
(缓冲式)(buffered)
WSHttpContextBinding WSWS 传输、(消息)、混合Transport, (Message), Mixed (无)、可靠会话、安全会话(None), Reliable Session, Security Session (无)、是(None), Yes n/an/a 文本、(MTOM)Text, (MTOM) No
UdpBinding

注意: 可以通过实现此绑定所实现的标准 SOAP-over-UDP(UDP 上的 SOAP)规范来获得互操作性。Note: Interoperability can be achieved by implementing the standard SOAP-over-UDP spec which this binding implements.
.NET.NET (无)(None) (无)(None) (无)(None) n/an/a (文本)(Text) No

重要

NetHttpBinding 是为使用 HTTP 或 WebSocket 服务设计的绑定,默认情况下使用二进制编码。NetHttpBinding is a binding designed for consuming HTTP or WebSocket services and uses binary encoding by default. NetHttpBinding 将检测它是否与请求-答复协定或双工协定结合使用,并更改其行为以进行匹配 - 它将针对请求-答复协定使用 HTTP,并针对双工协定使用 WebSocket。NetHttpBinding detects whether it's used with a request-reply contract or duplex contract and changes its behavior to match; it uses HTTP for request-reply and WebSockets for duplex. 可以使用重写此行为WebSocketTransportUsage绑定设置:双工时 - 这是默认值,其行为如前所述。This behavior can be overridden using the WebSocketTransportUsage binding setting: WhenDuplex - This is the default value and behaves as described above. 从不 - 阻止使用 WebSocket。Never - This prevents WebSockets from being used. 尝试使用具有此设置的双工协定将导致异常。Attempting to use a duplex contract with this setting results in an exception. 始终 - 甚至对于请求-答复协定,也会强制使用 WebSocket。Always - This forces WebSockets to be used even for request-reply contracts. NetHttpBinding 支持 HTTP 模式和 WebSocket 模式下的可靠会话。NetHttpBinding supports reliable sessions in both HTTP mode and WebSocket mode. 在 WebSocket 模式下,会话由传输来提供。In WebSocket mode sessions are provided by the transport.

下表对上表列出的功能进行说明。The following table explains the features listed in the previous table.

功能Feature 描述Description
互操作性类型Interoperability Type 指定绑定用来确保互操作的协议或技术。Names the protocol or technology with which the binding ensures interoperation.
安全性Security 指定如何保护通道:Specifies how the channel is secured:
-None:SOAP 消息的不安全和客户端未经身份验证。- None: The SOAP message isn't secured and the client isn't authenticated.
-传输:在传输层上满足安全要求。- Transport: Security requirements are satisfied at the transport layer.
-消息:在消息层上满足安全要求。- Message: Security requirements are satisfied at the message layer.
混合:声明包含在 message;传输层满足完整性和保密性需求。- Mixed: Claims are carried in the message; integrity and confidentiality requirements are satisfied by the transport layer.
会话Session 指定此绑定是否支持会话协定。Specifies whether this binding supports session contracts.
事务Transactions 指定是否启用事务。Specifies whether transactions are enabled.
双工Duplex 指定是否支持双工协定。Specifies whether duplex contracts are supported. 请注意,此功能要求支持绑定中的会话。Note that this feature requires support for Sessions in the binding.
编码Encoding 指定消息的网络格式。Specifies the wire format of the message. 允许的值包括:Allowable values include:
- 文本:例如 UTF-8。- Text: for example UTF-8.
- 二进制- Binary
消息传输优化机制 (MTOM):一种方法的高效编码的 SOAP 信封上下文中的二进制 XML 元素。- Message Transmission Optimization Mechanism (MTOM): A method for efficiently encoding binary XML elements within the context of a SOAP envelope.
流式处理Streaming 指定传入和传出消息是否支持流。Specifies whether streaming is supported for incoming and outgoing messages. 使用绑定上的 TransferMode 属性可设置值。Use the TransferMode property on the binding to set the value. 允许的值包括:The allowable values include:
- Buffered:对请求和响应消息进行缓冲处理。- Buffered: The request and response messages are both buffered.
- Streamed:对请求和响应消息进行流式处理。- Streamed: The request and response messages are both streamed.
- StreamedRequest:对请求消息进行流式处理,对响应消息进行缓冲处理。- StreamedRequest: The request message is streamed and the response message is buffered.
- StreamedResponse:对请求消息进行缓冲处理,对响应消息进行流式处理。- StreamedResponse: The request message is buffered and the response message is streamed.

请参阅See also