Something new in WCF 4.0

Published on Wednesday, August 3, 2011
wcf

Comparing with WCF 3.x, WCF 4.0 has new features. for example:

default endpoints:

With WCF 3.x, you have to provide configured endpoints when you host a service, otherwise, you will get an exception. In WCF 4, you will not worried if you forgot to set endpoint, because the runtime automatically adds one or more “default endpoints” for you.

Default Binding Configurations

In WCF 3.x, we define a named binding configuration through the bindingConfiguration attribute :

(the sample is from MSDN blog)

The following content copied from MSDN also.

<configuration>     
  <system.serviceModel>      
    <bindings>      
      <basicHttpBinding>      
        <binding name=&quot;BasicWithMtom&quot; messageEncoding=&quot;Mtom&quot;/>      
      </basicHttpBinding>      
    </bindings>      
    <services>      
      <service name=&quot;GreetingService&quot;>      
        <endpoint address=&quot;mtom&quot; binding=&quot;basicHttpBinding&quot;      
                  bindingConfiguration=&quot;BasicWithMtom&quot;      
                  contract=&quot;IHello&quot;/>      
      </service>      
    </services>      
  </system.serviceModel>      
</configuration>

In the above example, the “BasicWithMtom” binding configuration overrides the defaults for the BasicHttpBinding by changing the message encoding to MTOM. …With WCF 4, you can now define default binding configurations by simply omitting the binding configuration name when defining the new configuration. Then WCF will use that default configuration for any endpoints using that binding that don’t have an explicit binding configuration set on them.

For example, if we add the following app.config file to the console application shown earlier, the two default HTTP endpoints will pick up this default BasicHttpBinding configuration, which enables MTOM:

<configuration>     
  <system.serviceModel>      
    <bindings>      
      <basicHttpBinding>      
        <binding messageEncoding=&quot;Mtom&quot;/> <!-- notice there’s no name attribute -->      
      </basicHttpBinding>      
    </bindings>      
  </system.serviceModel>      
</configuration>      

About more information, please read "A Developer's Introduction to Windows Communication Foundation 4".