.netWCF

Binding in WCF(Part-14)

A WCF binding defines how the client needs to communicate with the service.

Let’s understand WCF service end points before understanding Binding.

A WCF service endpoint consists 3 things.
A – Address : Address for the WCF service
B – Binding : How the Client needs to communicate with the service
C – Contract : Defines what the service can do

In earlier post, we have created a simple Hello Service. Let’s take that as example.

Look at the app.config of HelloService.we have an end point.

In endpoint, you can see we have Address,Binding and Contract.In this example,addressis HelloService.this is not the whole service address.
We have defined a base address as well in app.config.

So the full address for the service would be:

In the above end point, we have HelloService.IHelloService contract. The contract defines what all are the operation is going to available for the client.In service, we have one operation HelloWorld and that is going to available for the client.

If you will look at the HelloWindowsClient, that we have created earlier you will see the whole address in app.config.

So now if you will run the service then it will work fine.
Now lets discuss what is binding and why we need it?
The WCF binding determines below communication protocols between client and service.

  • Transport Protocol(HTTp,TCP,MSMQ,NamedPipe etc..)
  • Message Encoding(text/XML, Binary etc)
  • Protocols(Reliable messaging,transaction support etc)

In WCF, there are several inbuilt bindings that you could use.You can find the list from MSDN.
http://msdn.microsoft.com/en-us/library/ms730879(v=vs.110).aspx

Based on your application requirement, if you are not sure which binding to use, you can follow this flow chart from StackOverflow.
http://stackoverflow.com/questions/10849920/different-wcf-bindingd-their-difference-and-compatibility-with-other-platforms

You can also create your custom bindings

© 2015, www.techkatak.com. All rights reserved.