WCF Service Binding


Before we learn the ABC of WCF, we need to know how a WCF service is made accessible to the clients.

A WCF service allows communication through an Endpoint. And the endpoint is the only point of communication of the WCF service that enables message exchange with the client as shown in Fig 1.




Fig. 1

And this Endpoint needs to set the ABC attributes of the WCF service as shown in Fig 2.


Fig. 2

Thus in the WCF world, ABC is an abbreviation of Address, Binding and Contract attributes of an Endpoint.

An example of the Endpoint

Let us quickly run through an example of an endpoint setting in the web.config file at the service side. 
<!-- Endpoint settings in WCF service -->
<endpoint address="http://localhost:8731/EmployeeWCFService.ServiceImplementation.Manager/" 
binding="basicHttpBinding" 
contract="EmployeeWCFService.ServiceContract.IEmployee" />
Where, address is the network address of the service, binding specifies transport protocol (HTTP, TCP, etc.) selected for the service and contract is the interface the service implements.

For the purpose of this article, we are going to emphasize on the Binding part of the WCF communication mechanism.

So, what is the Binding?

The Binding is an attribute of an endpoint and it lets you configure transport protocol, encoding and security requirements as shown in Fig 3




Fig 3

Types of Binding

One of the design goals of WCF is to unify the way distributed systems are developed prior to release of .Net Framework 3.0. WCF offers a single development framework for all scenarios where distributed solutions were implemented using different technologies such as ASMX web services, .Net Remoting, COM+, etc. WCF achieves this by configuring binding attributes of an endpoint. WCF lets you choose HTTP or TCP transport protocol, encoding, etc. just by tweaking the value of binding attribute for an endpoint.

To cater to different transport protocols, WCF lets you select HTTP, TCP and MSMQ binding types. For the purpose of this article, we are going to concentrate on HTTP and TCP binding with a concise explanation and simple example settings.

basicHttpBinding

This type of binding exists in new .Net world only to support backward compatibility with ASMX based clients (WS-Basic Profile 1.1). Basic http binding sends SOAP 1.1 messages and is used when there is a requirement for the WCF services to communicate with non WCF based systems. Thus, providing an endpoint with basicHttpBinding makes interoperating with other basic implementations of web services a great choice.

Note: All other bindings except basicHttpBinding support WS* specifications including security, reliable messaging and transaction support, where appropriate.

How to setup the basicHttpBinding?


Let us examine how to setup binding for an endpoint in the web.config file.

Step 1: Choose basicHttpBinding as a value in the binding attribute of an endpoint. 



<endpoint 
address="http://localhost:8731/EmployeeWCFService.ServiceImplementation.Manager/"
binding="basicHttpBinding"  
bindingConfiguration="basicBinding"
contract=" EmployeeWCFService.ServiceContract.IEmployee">
Step 2: This step is optional and is only required if the binding's default properties need to be modified, as shown in the example below. In this case, name the binding same as bindingConfiguration attribute in the endpoint section. 


<bindings>|
<
basicHttpBinding>
            <
binding    name="basicBinding" 
textEncoding="utf-8" 
openTimeout="00:03:00"
closeTimeout="00:03:00"
/>
</basicHttpBinding>           
</
bindings>



Note: All other types of binding are setup in the same way.

wsHttpBinding

This binding sends SOAP 1.2 messages and implements WS* specifications to support enterprise requirements of security, reliability, ordered delivery and transaction management.

netTcpBinding

This binding sends SOAP 1.2 messages, provides binary encoding and optimized communication between WCF services and WCF clients on Windows network. This binding is the fastest binding amongst all WCF binding options between different nodes in the TCP network. Unlike http bindings, the TCP binding does not offer interoperability but is highly optimized for .Net 3.0 and above clients. Thus, in .Net version 3.0 and above, providing an endpoint with netTcpBinding is an easy option to development of distributed systems and can replace COM+ and .Net Remoting model.

netNamedPipeBinding

This binding is used to provide secure and reliable Named Pipe based communication between WCF services and WCF client on the same machine. It is the ideal choice for communication between processes on the same machine.

netPeerTcpBinding

This type of binding exists to cater peer-to-peer computing using WCF services.

For more information on PNRP visit Microsoft page Peer Name Resolution Protocol

0 Responses to “WCF Service Binding”

Post a Comment

Labels

Topics