In this article, I am describing what is Window Communication Foundation (WCF) and why it is introduced in .NET Framework 3.0.
Background
In Modern Application (Distributed Application) development, you can use COM+, .NET Enterprise Services, MSMQ, .NET Remoting, Web services, etc. for communication. All these technologies play a different role and to use it you need to develop different solutions for different technologies. You have to focus on each of the technologies to develop rather than the application business logic.
WCF unifies the capabilities into single, common, general service oriented programming model for Communication. WCF provides a common approach using a common API which developers can focus on their application rather than on communication protocol.
Why Do We Need WCF?
There is one main Bank system which is directly connected with the database, that provides other systems like ATM machine, Loan System data using various communication protocols like Remoting, web service, etc. For communicating with different Systems using different communication protocols, you have to know the API of that technology. In WCF, you have to just make different End points for different services. There is no need to learn a different API. You can use only one common API for communication with different System.
In WCF, you have to just make different End points for different services. There is no need to learn a different API. You can use only one common API for communication with a different System.

WCF Architecture
ABC of an EndPoint in WCF

All communications with the WCF service will happen via the endpoints. The endpoints specify a Contract that defines which methods of the
Service
class that will be accessible via the endpoint; each endpoint may expose a different set of methods. The endpoints also define a binding that specifies how a client will communicate with the service and the address where the endpoint is hosted.
A-Address(Where?): Specifies the location of the service which will be like
http://Myserver/MyService.Clients will use this location to communicate with our service.
Collapse | Copy Code
//
// The sample address for above transport schema may look like
http://localhost:81
http://localhost:81/MyService
net.tcp://localhost:82/MyService
net.pipe://localhost/MyPipeService
net.msmq://localhost/private/MyMsMqService
net.msmq://localhost/MyMsMqService
//
B-Binding-Address(How?): Specifies how the two parties will communicate in terms of transport and encoding and protocols.
WCF Supports Nine Types of Bindings
Basic Binding
Offered by the
BasicHttpBinding
class, this is designed to expose a WCF service as a legacy ASMX web service, so that old clients can work with new services. When used by the client, this binding enables new WCF clients to work with old ASMX services.
TCP Binding
Offered by the
NetTcpBinding
class, this uses TCP for cross-machine communication on the intranet. It supports a variety of features, including reliability, transactions, and security, and is optimized for WCF-to-WCF communication. As a result, it requires both the client and the service to use WCF.
Peer Network Binding
Offered by the
NetPeerTcpBinding
class, this uses peer networking as a transport. The peer network-enabled client and services all subscribe to the same grid and broadcast messages to it.
IPC Binding
Offered by the
NetNamedPipeBinding
class, this uses named pipes as a transport for same-machine communication. It is the most secure binding since it cannot accept calls from outside the machine and it supports a variety of features similar to the TCP binding.
Web Service (WS) Binding
Offered by the
WSHttpBinding
class, this uses HTTP or HTTPS for transport, and is designed to offer a variety of features such as reliability, transactions, and security over the Internet.
Federated WS Binding
Offered by the
WSFederationHttpBinding
class, this is a specialization of the WS binding, offering support for federated security.
Duplex WS Binding
Offered by the
WSDualHttpBinding
class, this is similar to the WS binding except it also supports bidirectional communication from the service to the client.
MSMQ Binding
Offered by the
NetMsmqBinding
class, this uses MSMQ for transport and is designed to offer support for disconnected queued calls.
MSMQ Integration Binding
Offered by the
MsmqIntegrationBinding
class, this converts WCF messages to and from MSMQ messages, and is designed to interoperate with legacy MSMQ clients.
Choosing Binding Type
C-Contract(What?): Specifies the interface between client and the server. It's a simple interface with some attribute.
Types of Contracts
What are Various Ways of Hosting WCF Services?
There are three major ways of hosting a WCF services:
- Self-hosting the service in its own application domain. The service comes into existence when you create the object of Service Host class and the service closes when you call the Close of the Service Host class.
- Host in application domain or process provided by IIS Server.
- Host in application domain and process provided by WAS (Windows Activation Service) Server.
Choose Type of Hosting
Advantage
- WCF is interoperable with other services when compared to .Net Remoting,where the client and service have to be .Net.
- WCF services provide better reliability and security in compared to ASMX web services.
- In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements.
- WCF has integrated logging mechanism, changing the configuration file settings will provide this functionality. In other technology developer has to write the code.
Disadvantage
Making right design for your requirement is little bit difficult. I will try to help you on solving these difficulties in the following article.
Difference between WCF and Web service
Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them.
Features | Web Service | WCF |
Hosting | It can be hosted in IIS | It can be hosted in IIS, windows activation service, Self-hosting, Windows service |
Programming | [WebService] attribute has to be added to the class | [ServiceContraact] attribute has to be added to the class |
Model | [WebMethod] attribute represents the method exposed to client | [OperationContract] attribute represents the method exposed to client |
Operation | One-way, Request- Response are the different operations supported in web service | One-Way, Request-Response, Duplex are different type of operations supported in WCF |
XML | System.Xml.serialization name space is used for serialization | System.Runtime.Serialization namespace is used for serialization |
Encoding | XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom | XML 1.0, MTOM, Binary, Custom |
Transports | Can be accessed through HTTP, TCP, Custom | Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom |
Protocols | Security | Security, Reliable messaging, Transactions |
No comments:
Post a Comment