Document directory
- Bind Basic Concepts
- Bind types
- Configure the endpoint and associated binding in two ways
- Binding Function
- Bind Element
Bind Basic Concepts
Binding is a runtime type derived from a common basic type. The binding describes the transmission protocol, message encoding format, and other communication protocols used for communication.
Bind types
| Type name |
Configuration File Usage name |
Description |
| Basichttpbinding |
Basichttpbinding |
Used for compatibility with earlier WebServices |
| Wshttpbinding |
Wshttpbinding |
Web Service binding: supports the latest web service standard ws * |
| Wsdualhttpbinding |
Wsdualhttpbinding |
WS * and bidirectional communication are supported. |
| Wsfederationhttpbinding |
Wsfederationhttpbinding |
WS * is supported, and the security related to single sign-on is designed. |
| Netnamedpipebinding |
Netnamedpipebinding |
Connection-oriented binding, which communicates with a named pipeline on a machine |
| Nettcpbinding |
Nettcpbinding |
Connection-oriented binding, cross-process and Machine Communication through TCP |
| Netpeertcpbinding |
Netpeertcpbinding |
Support end-to-end communication |
| Netmsmqbinding |
Netmsmqbinding |
Support MSMQ-based communication |
| Msmqintegrationbinding |
Msmqintegrationbinding |
Supports migration of MSMQ Components |
Configure the endpoint and associated binding in two ways
The bound configuration can be in the form of a configuration file or code, as shown in the following code:
Configuration File Format (server)
<endpoint address="HelloWorld" binding="basicHttpBinding" contract="Service.IHelloWorldService"></endpoint>
Configuration File Format (client)
<endpoint address="http://localhost:10000/HelloWorld" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_oec2003" contract="HelloWorld.oec2003" name="BasicHttpBinding_oec2003" />
Code Format
WSHttpBinding wsHttpBinding = new WSHttpBinding();wsHttpBinding.Security.Mode = SecurityMode.Transport;wsHttpBinding.ReliableSession.Enabled = true;wsHttpBinding.TransactionFlow = true;
Binding Function
Each binding must provide at least one transmission protocol, one message encoding format and one related message version. In addition, there are some other functions, such as security, two-way communication, and transactions.
Transmission Protocol: There are HTTP, https, TCP, named pipeline, and MSMQ, all of which correspond to specific binding types.
Message encoding: describes how messages are formatted. Binary, text, or MTOM can be used.
Message version: regardless of the message encoding format, the message is always expressed as soap1.1 or soap1.2.
Transmission Security: the ability to transmit certificates, signatures, and encryption online. SSL is generally used.
Message security: the transmission certificate, signature, and encryption capabilities independent of the transport layer.
Two-way communication: TCP and named pipelines can be directly supported, but HTTP does not.
These binding functions are activated by configuring binding elements. The following describes binding elements.
Bind Element
Each type of binding has a set of binding elements, such as the transport protocol and encoding format mentioned above. The types of binding elements in net are inherited from the bindingelement class. Each binding in WCF must have a transmission protocol and a message encoding format. The universal binding element of the transport protocol is transportbindingelement. Some of the following sub-classes inherit transportbindingelement, which respectively represent different types of transport protocols.
Httptransportbindingelement
Httpstransportbindingelement
Msmqtransportbindingelement
The common binding element of the encoding format is messageencodingbindingelement. Some subclasses are as follows:
Binarymessageencodingbindingelement
Textmessageencodingbindingelement
Mtommessageencodingbindingelement
There are also some other binding elements that are not mandatory but particularly useful in some specific scenarios:
Security: securitybindingelement
Hybrid bidirectional communication: compositeduplexbindingelement onewaybindingelement
Reliable Communication: reliablesessionbindingelement
Transaction: transactionflowbindingelement
The above binding element must reference the namespace system. servicemodel. Channels
Binding in WCF is usually carried out in the configuration file. Although it can be implemented by code, it is more flexible in the configuration file. It can be expanded in the bindingconfiguration of the endpoint. See the following code:
<system.serviceModel> <services> <service name="Service.HelloWorldService" behaviorConfiguration="HelloWorldBebavior"> <endpoint address="HelloWorld" binding="basicHttpBinding" bindingConfiguration="baseBinding_oec2003" contract="Service.IHelloWorldService"></endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
This article only briefly introduces the concept of binding and the types of binding, and uses some code to describe the application of binding. The detailed introduction and usage of each binding are described in the following blog.