Infosys Microsoft Alliance and Solutions blog

« Win 7 Network adapter problem | Main | Silverlight on IE 8 »

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

1) Configuration less WCF, and automatic endpoints

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, 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



      <service name="GreetingService">       

      <endpoint binding="basicHttpBinding" contract="IHello"/>  

      <endpoint kind="mexEndpoint" address="mex“




4)      File-less Activation (no .svc)

Http://  .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"/>




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.

public class CalculatorService
    public double AddNumber(double a, double b)
        return a+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.



In your article Number 5 is not new feature in WCF 4.0
you can do that in pervious versions as well.

doing like that is bad idea in SOA world .
Share Contract not Class.
please let me know if you have any question.

#5 is about simplified hosting in terms of how close it is to Asmx services without the need to write DataContract and configuration together in 4.0 and not just about DataContract.
I agree with you on sharing contract principle in SOA.

Is this still valid?

relativeAddress attribute has to have a string with and extension.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Please key in the two words you see in the box to validate your identity as an authentic user and reduce spam.

Subscribe to this blog's feed

Follow us on

Blogger Profiles

Infosys on Twitter