Learning how to use a binding

Source: Internet
Author: User
Tags msmq

Network Communication is inseparable from the support of network protocols. In WCF, many transmission protocols are provided to developers for binding. For example, basichttpbinding, nettcpbinding, and wshttpbinding. For beginners, it is easy to get confused by a variety of Protocols. If you don't know which Protocol to use, let's simply talk about it here. I hope it will be helpful for beginners to learn about WCF.

In fact, I also learned and summarized it. I wrote two WCF services a few days ago. However, when I called the service through vs2008, the binding in the configuration file showed two different situations:

A Service provides a method to return a dataset. When a service reference is added, in Web. config:

Code
<Endpoint address = "http: // GAO/wcfservice1/service1.svc" binding = "wshttpbinding"
Bindingconfiguration = "wshttpbinding_iservice1" Contract = "servicereference1.iservice1"
Name = "wshttpbinding_iservice1">

Another service provides a method that returns a collection list in Web. config:

Code
<Endpoint address = "http: // GAO/slgetdatabyadoweb/slgetdatawcf. SVC"
Binding = "basichttpbinding" bindingconfiguration = "basichttpbinding_islgetdatawcf"
Contract = "servicereference2.islgetdatawcf" name = "basichttpbinding_islgetdatawcf"/>

Two WCF services with different return values have different bindings when adding service references, and do not know what Automatic Generation is used by the development environment (expert advice ). More seriously, the wshttpbinding binding service may encounter problems during cross-machine calling. It seems that the binding type is worth studying.

Binding in WCF

Binding describes the communication mode of service transmission. You can use binding to specify the transmission protocol, security requirements, encoding methods, transaction processing requirements, and reliability.

Binding includes multiple binding elements. They describe all binding requirements. You can create custom binding or use predefined binding, as shown below:

Basic binding)

Provided by the basichttpbinding class. The basic binding function exposes the WCF Service to the old asmx web service, so that the old client can collaborate with the new service. If the client uses basic binding, the new WCF client can collaborate with the old asmx service.

TCP binding

Provided by the nettcpbinding class. TCP binding uses the TCP protocol to implement cross-machine communication in the intranet. TCP binding supports multiple features, including reliability, transaction, security, and optimization of Inter-WCF communication. The premise is that both the client and the Service must use WCF.

Peer network binding

Provided by the netpeertcpbinding class. It uses the same network for transmission. Peer networks allow clients and services to subscribe to the same grid to broadcast messages. Because the equivalent network requires knowledge about grid topology and mesh computing strategy.

IPC binding

Provided by the netnamedpipebinding class. It uses a named pipe for communication between the same machine. This binding method is the safest because it cannot receive calls from outside the machine. The features supported by IPC binding are similar to those supported by TCP binding.

Web Service (WS) Binding

Provided by the wshttpbinding class. WS binding uses HTTP or HTTPS for transmission, providing features such as reliability, transaction and security for Internet-based communication.

WS federated ws binding)

Provided by the wsfederationhttpbinding class. WS federal binding is a special type of WS binding that provides support for federated security.

WS bidirectional binding (Duplex ws binding)

Provided by the wsdualhttpbinding class. WS bidirectional binding is similar to WS binding, but it also supports bidirectional communication from the service to the client.

MSMQ binding

Provided by the netmsmqbinding class. It uses MSMQ for transmission to support disconnected queue calls.

MSMQ integration binding)

Provided by the msmqintegrationbinding class. It implements conversion between a WCF message and a MSMQ message to support interoperability with the old MSMQ client.

Different bindings support different features. ToWSBinding at the beginning is platform-independent and supports Web service specifications. ToNetThe activated binding uses a binary format, which makes communication between. Net Applications very good. Other features include support for sessions, reliable sessions, transaction processing, and two-way communication.

Bound transfer protocol and encoding format

Binding and security

Here is a good article recommended to everyone, may be helpful to everyone: http://msdn.microsoft.com/zh-cn/magazine/cc163382.aspx

Binding and Reliability

The name of the binding protocol supports reliability, default reliability, and ordered transmission by default.

Basichttpbinding no N/

Nettcpbinding yes off yes on

Netpeertcpbinding no N/

Netnamedpipebinding no N/A (on) Yes N/A (on)

Wshttpbinding yes off yes on

Wsfederationhttpbinding yes off yes on

Wsdualhttpbinding yes on

Netmsmqbinding no N/

Msmqintegrationbinding no N/

The Ws binding protocol generally provides support for reliability transfer, which can be enabled in the project by programming or configuration. Reliability transmission depends on the bound target scenario.

Rational use of binding

WCF provides many predefined Bindings for us. Which one should we apply in different development scenarios? Of course, we can leave the development environment as customized. But what should we pay attention to if we define the code manually? Here are some points for your reference:

1. basichttpbinding: a binding for communication with Web services that comply with the WS-basic profile (for example, services based on ASP. NET web services (asmx. This binding uses HTTP as the transmission protocol and text/XML as the default message encoding.
 
2. wshttpbinding: a secure and interoperable binding, suitable for non-duplex service conventions.
 
3. ws2007httpbinding: a secure and interoperable binding that supports the correct versions of Security and reliablesession and the binding element of transactionflow.
 
4. wsdualhttpbinding: a secure and interoperable binding, applicable to duplex service protocols or communication through soap media.
 
5. wsfederationhttpbinding: a secure and interoperable binding. It supports the WS protocol and enables organizations in the Federation to efficiently Authenticate and authorize users.
 
6. ws2007federationhttpbinding: a secure and interoperable binding. It is derived from ws2007httpbinding and supports joint security.
 
7. nettcpbinding: a secure and optimized binding, applicable to cross-Computer Communication Between WCF applications.
 
8. netnamedpipebinding: a secure, reliable, and optimized binding that is suitable for communication between WCF applications on computers.
 
9. netmsmqbinding: A queuing binding, applicable to cross-Computer Communication Between WCF applications.
 
10. netpeertcpbinding: a binding that supports multi-Computer Security Communication.
 
11. webhttpbinding: a binding that can be used to configure endpoints for WCF Web Services exposed through HTTP requests (instead of soap messages.
 
12. msmqintegrationbinding: a binding that applies to cross-computer communication between a WCF application and an existing Message Queue (also known as MSMQ) application.

The more common is basichttpbinding, which is mainly compatible with old web services. Wsdualhttpbinding is used for WCF callback. It is usually used for IIS hosting.
Nettcpbinding is used for internal communication within the enterprise lan. It is highly efficient and supports multiple security mechanisms and policies. msmqintegrationbinding is mainly used for the development of WCF message queues.

Here, I would like to thank XU: http: // frank_xl.cnblogs.com for his guidance and help. I hope you can correct the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.