New Features in Windows Communication Foundation (WCF) 4.0

Introduction

There have been quite a few enhancements and new features introduced in WCF 4.0. These new features and enhancements are a major boost to productivity, flexibility and they facilitate seamless development of service oriented applications. This article discusses the new features and enhancements in WCF 4.0 and how one can make use of them in applications.

What is Windows Communication Foundation (WCF)?

Windows Communication Foundation (WCF) is a platform that can be used to design and implement platform independent, scalable services. It is a framework from Microsoft that provides a platform for unification of a number of enterprise technologies under one roof. The MSDN states, “Windows Communication Foundation (WCF) is Microsoft’s unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments.”

Reference: http://msdn.microsoft.com/en-us/library/ms735119.aspx

WCF was introduced as part of .NET Framework 3.0 in 2006 and was initially named “Indigo”. The forthcoming sections in this article presents the new features and enhancements in WCF 4.0.

Pre-requisites

To work with the concepts and the code examples presented in this article, you should have the following installed on your system: Microsoft Visual Studio 2010 RC or higher

New Features and Enhancements in WCF 4.0

The new and enhanced features in Windows Communication Foundation 4.0 include the following:


  • Support for simplified configuration

  • Support for standard endpoints

  • Support for discovery

  • Support for simplified IIS hosting

  • Enhanced support for REST

  • Support for routing service

  • Support for workflow services

We will discuss each of these new features and enhancements in the sections that follow.

Support for Simplified Configuration

Configuration in WCF 4.0 is much simpler compared to the earlier versions of WCF. WCF 4.0 provides default endpoints, binding, and behavior. Refer to the WCF 4.0 service shown below:


[ServiceContract]
public class CustomerService
{
   [OperationContract]
   public string GetCustomerName(int customerID)
   {
       //Code to search customer name based on customerID and return it.
   }
}
Here’s an example of the simple configuration you would use to host the service.
using System;
using System.ServiceModel;
using System.ServiceModel.Description;
   class Program
   {
       static void Main(string[] args)
       {
           ServiceHost serviceHost = new ServiceHost
                (typeof(CustomerService));
                serviceHost.AddServiceEndpoint (typeof(CustomerService), new BasicHttpBinding(), “http://localhost:1212/ CustomerService.svc”);
           serviceHost.Open();
           Console.WriteLine(“The Customer Service has been started”);
           Console.ReadLine();
           serviceHost.Close();
       }
   }
To consume the service, you can use the following configuration:
<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<system.serviceModel>
   <behaviors>
     <serviceBehaviors>
       <behavior>
         <serviceMetadata httpGetEnabled =”true”/>
       </behavior>
     </serviceBehaviors>
   </behaviors>
</system.serviceModel>
</configuration>
To specify a more secure wsHttpBinding binding, you can specify the following configuration in your configuration file:
<?xml version=”1.0″ encoding=”utf-8″ ?>
<configuration>
<system.serviceModel>
   <behaviors>
     <serviceBehaviors>
       <behavior>
         <serviceMetadata httpGetEnabled =”true”/>
       </behavior>
     </serviceBehaviors>
   </behaviors>
   <protocolMapping>
     <add binding=”wsHttpBinding” scheme =”http”/>
   </protocolMapping>
</system.serviceModel>
</configuration>

Support for Standard Endpoints

WCF 4.0 provides support for standard endpoints–a set of preconfigured endpoints to minimize on the otherwise tedious configuration that is needed to host or consume a WCF service. The standard endpoints available in WCF 4.0 include the following:


  • dynamicEndPoint

  • discoveryEndpoint

  • udpDiscoveryEndpoint

  • announcementEndpoint

  • udpAnnouncementEndpoint

  • mexEndPoint

  • webHttpEndpoint

  • webScriptEndpoint

  • workflowControlEndpoint

More by Author

Must Read