Configuration of WCF mbinding in WCF

Source: Internet
Author: User

This section focuses on: 1. How to read the binding element in the binding. 2. Basic configuration of the custombinding element. 3. Sample Code

1. bingding is composed of binding elements. You can make appropriate combinations based on your actual needs. The following code helps you view the binding elements contained in the binding.

View code

1  NetTcpBinding binding = new NetTcpBinding();
2 foreach (BindingElement element in binding.CreateBindingElements())
3 {
4 Console.WriteLine(element.GetType().FullName);
5 }

The result of querying nettcpbinidng is as follows:

2. Configure custombinding. As follows:

Server:

View code

 1 <?xml version="1.0" encoding="utf-8" ?>
2 <configuration>
3 <system.serviceModel>
4 <services>
5 <service name="WcfCustomBinding.Host.Services.PersonService">
6 <endpoint address="net.tcp://localhost:6666/personService"
7 binding="netTcpBinding"
8 contract="WcfCustomBinding.Host.Services.IPerson"></endpoint>
9 <endpoint address="net.tcp://localhost:7777/personService"
10 binding="customBinding"
11 bindingConfiguration="personBinding"
12 contract="WcfCustomBinding.Host.Services.IPerson">
13 </endpoint>
14 </service>
15 </services>
16 <bindings>
17 <customBinding>
18 <binding name="personBinding">
19 <binaryMessageEncoding></binaryMessageEncoding>
20 <tcpTransport></tcpTransport>
21 </binding>
22 </customBinding>
23 </bindings>
24 </system.serviceModel>
25 </configuration>

Client:

View code

 1 <?xml version="1.0" encoding="utf-8" ?>
2 <configuration>
3 <system.serviceModel>
4 <client>
5 <endpoint name="Nettcp"
6 address="net.tcp://localhost:6666/personService"
7 binding="netTcpBinding"
8 contract="WcfCustomBinding.Client.Proxys.IPerson">
9 </endpoint>
10
11 <endpoint name="Custom"
12 address="net.tcp://localhost:7777/personService"
13 binding="customBinding"
14 bindingConfiguration="personBinding"
15 contract="WcfCustomBinding.Client.Proxys.IPerson">
16 </endpoint>
17 </client>
18 <bindings>
19 <customBinding>
20 <binding name="personBinding">
21 <binaryMessageEncoding></binaryMessageEncoding>
22 <tcpTransport></tcpTransport>
23 </binding>
24 </customBinding>
25 </bindings>
26
27 </system.serviceModel>
28 </configuration>

Iii. Example:

In this example, the default settings of nettcpbinding and custom mbmbinding are used, and their performance is compared on the client. In order to better compare the two types of performance, it is best to run multiple times on the client for comparison. The running result is as follows: You can change the configuration file of nettcpbinding to achieve the same performance as that of custombinding.

Download the code here

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.