WCF Introduction
WCF is a unified communication framework that integrates all the Communication frameworks like ASMC/WSE, .NET REMOTING, DCOM/COM and MSMQ into one logical model.
WCF increases the productivity in the sense that you learn only one programming model rather than learning multiple models as in the other communication frameworks describe above. Each one of them has its own programming model so if developers want to learn or work in any of them, they need to understand each framework programming model separately.
In WCF, you write code in one way and have many ways of communication, like in one case if you want SOAP based communication through MSMQ or in another case Restful based communication through Http etc.
WCF Service Components
Each WCF service has three main components
- Address
- Binding
- Contract
Address
Address is called end-point also. They represent service location or contain a piece of information about where to send a message. Address specifies protocol (Http) and host (www.example.com) for using service.
Bindings
Binding specifies how to send a message and which protocol is used i.e. SOAP, or how a client can communicate with the service. Bindings also specify security constraints and other options. Some of the built-in bindings that WCF provides and their usage scenarios are as follow.
Binding Types | Usage Scenario |
WebHttpBinding | For Restful Communication using Http |
BasicHttpBinding | For SOAP Communication using Http |
NetTcpBinding | For .Net-To-.Net(Cross Machine) Communication using TCP |
Based on requirements, you can create custom bindings too.
Example
- <configuration>
- <system.serviceModel>
- <services>
- <service name=”servicename”>
- <endpoint address=”http:
- </services>
- </system.serviceModel>
- </configuration>
Contract
Contract is an interface where you define the methods that you want to expose. Clients interact with services through contract.
Example
- [ServiceContract]
- public interface InterfaceName {
- [OperationContract]
- string Example(string name)
- }