WCF 4.0 –Part 1
WCF 4.0 will be available with .Net framework 4.0 and builds upon the features provided by WCF 3.5 (including SP1). WCF 4.0 brings in several features to make the life of developers and application administrator easy. To enhance the support for REST Services, certain features from REST starter kit are also integrated with WCF 4.0. In this blog let’s take a look at features which simplifies things for application administrators
WCF achieved Unification of multiple distributed technologies like asmx services, msmq, remoting, COM+ by abstracting their respective protocols through bindings, while doing so it introduced additional complexity of managing it through configuration files which were nonexistent with ASMX services. Of course flexibility comes with a price.
Applying bindings and behaviors specific to different distributed scenarios needs thorough WCF understanding and once Services are deployed in production; administrators find it difficult to tweak the system.servicemodel section to maintain it.
WCF 4.0 removes the need of having configuration files. It does this by providing default endpoint and behavior. Default endpoint only kicks in when the service has not been configured with any endpoints.
Depending on .net 4 machine.config mapping, WCF picks up the binding. For Http if the binding defined is BasicHttpBinding it will use it. One can change the binding for a specific protocol like http, tcp, msmq, etc.in machine.config. e.g. change to WsHttpBinding instead of BasicHttpBinding for http.2) Default Behavior
Similar to default endpoint WCF also provides default behavior. Unlike 3.5 where behavior configuration needs to be specified explicitly using attribute <behaviorConfiguration>, one doesn’t need to specify the behavior explicitly in 4.0.If you don’t specify behavior in 3.5 services it will fail to compile whereas the same service will compile and work with 4.0
3) Standard endpoints
Standard endpoints are pre bundled end points that WCF can use without developer needing to define details of it. These endpoints are defined using <Kind> attribute. Some of the standard endpoints are udpAnnouncementEndpoint, udpDiscoveryEndpoint, workflowControlEndpoint, mexEndpoint.
In the following example for mexEndPoint, note there is no mention of binding and contract
<endpoint binding="basicHttpBinding" contract="IHello"/>
<endpoint kind="mexEndpoint" address="mex“
4) File-less Activation (no .svc)
Http://xyz.com/abc.svc .svc at the end of url makes it user unfriendly. It also makes it Low REST service as it donot follow the REST URI principle.Till date developers have to overcome this limitation by implementing URLReWrite module in IIS. Writing custom code to implement this is error prone and needs maintenance over a period. WCF 4.0 has introduced a feature to access WCF services using attribute called as relativeAddress.
Following .config setting depicts how a PaymentService can be accessed using relative URL.
<add relativeAddress="/Payment" service=“PaymentService.svc"/>
</system.serviceModel>5) Simplifying IIS/ASP.NET Hosting
WCF services are now that much simpler to write as it no more mandates writing Interface definition and one can directly write class and decorate it with Service Contract, decorate Service operations with Operation Contract as shown in below example. This makes it as simple as asmx services. Top it with no configuration files and hosting in IIS gets that much easier.[ServiceContract]
public class CalculatorService
public double AddNumber(double a, double b)
All the above features in WCF 4.0 are mostly related to configuration. In the next blog we will dwell into what more WCF 4.0 has in store.