Introduction:
Windows communication foundation (WCF) is one of the recent buzz in the development world. The beauty of this technology has already attracting developers towards it. To get a long range view about what WCF is or what it can do I can say, it is the best way to build a distributed system. It leverages much hassle from the development team and lets them focus on the actual application. Before WCF there were many technologies that were used to build distributed applications or any application that has to communicate other channels to provide or consume service. RMI, SOAP, CORBA, COM+, XML etc are some of these old technologies that still may be dominating the distributed world. But it seems to me, soon it will change. I will explain it next why WCF is going to be in demand instead of the old rulers.
What is the problem in old approaches:
Today’s world is different than before. Now we do not need isolated applications. The demand of software and business dependency on software has greatly increased, which created vast scope for applications and great demand of requirement. Services provided through applications now can’t be always provided in a single application. Different applications needs to communicate with each other to fulfill a demand. Applications are distributed and they need to communicate. This communication in fact is not so simplistic as it sound. The above technologies each had its pros and cons in communicating. Most of all each one is totally different than the other and developers need to learn a new technology to use it. There was no set standard or a common set of knowledge that could be used in different scenarios and need.
The solution - the root of WCF:
WS-* (pronounced “W-S-star”) is the solution for this diversity problem. It defines a set of standards that define, among other things, universal message structures and messaging choreographies that includes
- WS-Addressing,
- WS-Security,
- WS-Trust,
- WS-SecureConversation,
- WS-Federation,
- WS-ReliableMessaging,
- WS-AtomicTransaction,
- WS-Coordination,
- WS-MetadataExchange,
- WS-Policy, and
- WS-PolicyAttachment
WCF can also be used in the Representational State Transfer (REST) architecture and other distributed architectures that use Plain Old XML (POX) messages.
Although previously developers could write service oriented applications using web service and other technologies, but now developers can do it with more security, reliability, flexibility, and performance than before.
WCF applications send and receive messages through the operating system I/O such as sockets, named pipes etc but the developers are abstracted from the bottom level details by WCF letting the developer think more on the application itself.
Features of WCF:
Independent Versioning
In a distributed environment, there are many segments that communicate and perform business task. For example, in a Enterprise Resource Planner (ERP) system, there can be inventory, human resource module, client feedback module, order, supply, payroll etc. All these may be somehow related to one another. And if we consider the whole system as a single application and each part as a module of it, any change happens to a module may need change in the other related modules too. On the other hand in the service oriented approach, each part is considered as an application, and each one communicates with the other part using messaging, so change made in one part or addition of a new part may not need any change in the other parts as long as it follows the WS-* specification. Which is allowing updating the version of a segment independently of the other segments.
Asynchronous One-Way Messaging
In the traditional request reply model, we call for a service (lets say a function call at this point) and wait for it to return to us which actually halts the application at that point. As we know the asynchronous forward-only messaging is far more efficient for the I/O bound tasks but is more complicated. At this point some may think about the AJAX and say we already do it in AJAX. But he is forgetting that WCF is not only limited in web request, it handles all task that is performed in both web and desktop environment. No matter how expert the developer is, he will agree that doing I/O operations asynchronously is far more difficult. But WCF provides us the most ease in doing so. WCF is built from the ground up to support asynchronous forward-only messaging.
Platform Consolidation
Microsoft supported several major technologies for distributed computing such as RPC, WSE, ASMX, Remoting, COM+, and MSMQ. All of them has its benefits and limitations. WCF combines features from different technologies and unifies them under one programming model to make the developer free from thinking about so many technologies.
| Feature | WSE | ASMX | Remoting | COM+ | MSMQ | WCF |
| WS-* support | X | | | X | | X |
| Basic Web service interoperability | | X | | X | | X |
| .NET -to-.NET communication | | | X | | | X |
| Distributed transactions | | | | X | X | X |
| Queued messaging | | | | | X | X |
Security
WCF supports many different security models making the application secure. And WCF has an extensible architecture, it is also relatively easy to extend WCF security to meet the needs of a particular application. WCF provides security by default. The security options range from the traditional transport-centric security to the more modern, message-based security, as dictated in WS-Security and related specifications.
Reliability
Reliability is a great factor in case of distributed system. The communication must be reliable in some cases. There are four type of reliability factor in the messaging world, they are:
- At Most Once A message must arrive at the destination no more than once.
- At Least Once A message must arrive at the destination at least once.
- Exactly Once A message will arrive at a location only once.
- In Order The order of the transmitted messages must be kept intact.
To ensure the reliability WCF provide extra care and facility.
Transactional Support
As we know in real world we may need to perform several task in once scope, if one fail the others should be roll backed. WCF allows transactional scopes for communicating among the application(s).
Interoperability
WCF can communicate with applications that run in other Operating system. WCF can communicate with other applications that understand WS-*, Basic Profile (BP), and XML messages over TCP, HTTP, Named Pipes, and MSMQ.
Performance
As I mentioned above, WCF provides us the functionality provided by WSE, ASMX, Remoting, COM+, and MSMQ. Each of them has its benefits but for certain performance value. Such has MSMQ provides more reliability but trades with less performance, again Remoting is fast for .net to .net communication but is unable to communicate with a non .net application.
WCF provides different level of interoperability and performance to meet our needs.
Extensibility
One power of WCF is its extensive design. WCF is designed to work with custom transports, channels, bindings, encodings, and architectural paradigms.
Configurability
WCF provide rich configuration options through XML configuration file which if used wisely can provide lot of benefits. Administrators can change the behavior of the application by configuring the XML file rather than getting involve the developer team. Though it should be used wisely as misuse can lead to unstable application that is hard to debug.