WCF (Windows Communication Foundation) provides a unified programming model for building scalable, robust services. It is a secure, reliable, and scalable messaging platform for developing service oriented applications in .Net. You can also use WCF to build RESTful services.
WCF has matured a lot over the years, and the latest stable release, WCF 4.5 comes up with many significant improvements. The salient new features and enhancements in WCF 4.5 at a quick glance:
- Support for Web Sockets
- Support for UDP endpoints
- Simplified configuration files
- Support for validation of WCF configuration
- Support for Contract - First Development
- Improvements in Streaming
Support for Web Sockets
Web sockets provide support for asynchronous full duplex communication using the HTTP protocol. In WCF 4.5, the netHttpBinding and netHttpsBinding have been have been updated to provide support for WebSockets. If you would like to set up support for WebSockets in your WCF service, you should set a CallbackContract on your ServiceContract. Here's how you can achieve this.
[ServiceContract(CallbackContract = typeof(ITestCallback))]
public interface ITestService
[OperationContract(IsOneWay = true)]
Task SendTextMessage(string text);
Support for UDP endpoints
There are a couple of ways to exchange data between two or more processes over a network. You can use either TCP (Transmission Control Protocol) or the UDP (User Datagram Protocol) transport protocol. While the TCP is a secure and reliable connection oriented protocol, the UDP is a relatively less secure or reliable, fast, and connectionless protocol. WCF 4.5 now provides support for UDP protocol -- a connectionless, lightweight protocol. The following code snippet illustrates how you can define a UDP endpoint in WCF 4.5.
<endpoint address="soap.udp://localhost:8080/" binding="udpBinding" contract="IDG.IService" />
Simplified configuration files
You longer need to worry about the lengthy configuration files that are generated by WCF. When you create a WCF service using WCF 4.5, the configuration that is generated will just have the non-default binding metadata in it. Here's what a typical configuration generated in WCF 4.5 looks like:
Support for validation of the WCF configuration
This is a great new feature introduced in WCF 4.5. With WCF 4.5, there's much improved support for intellisense in your popular Visual Studio IDE. With WCF 4.5 if Visual Studio can detect any issue with the configuration setting of your WCF service at the time of compilation, it will display you warnings when you compile your service project. Note that in the earlier versions of WCF you didn't have any support for validation of the configuration settings of your WCF service.
WCF 4.5 now provides support for contract first development -- you can now generate the data contracts from the WSDL. You now have a contract-first tool integrated into Visual Studio that you can leverage to take advantage of this feature. Note that the popular tool svcutl now comes up with a new switch (the new switch is /serviceContract) using which you can generate service and data contracts from a given WSDL document.
Improvements in streaming
Asynchronous programming is a great feature to improvement the performance of your application. You can take advantage of asynchrony to perform operations sans the need to block the main or the executing thread of the application. WCF 4.5 provides support for asynchronous streaming. Unlike in the earlier versions of WCF, your service will now not block while a service consumer is receiving the message. Rather, the thread will be made available to serve other service consumers. Now your WCF services that have been hosted in IIS can start processing the data even before the entire data has been received.
To enable this feature, you should specify the following in the service configuration.
<behavior name = "IDGBehavior">
<dispatcherSynchronization asynchronousSendEnabled = "true" />
This article is published as part of the IDG Contributor Network. Want to Join?