Raw Notes–WCF 4.0 New Features

Wednesday, February 29, 2012 / Posted by Luke Puplett /

WCF 4.0 Notes

Default Endpoints

Base addreses + contracts (HTTP, TCP)

WCF creates endpoints based on info it has, above.

Default Bindings - binding with no name becomes default.

Default Behaviours – behaviour with no name becomes the default.

Standard Endpoints – built-in endpoints in common configurations.

File-less Activcation – Config file defines what is usually in the .svc file, but your service is still /blah.svc


HTTP Cache now works.

Message Format selection is now done with HTTP headers as it should be.

WebFaultException now automatically does HTTP codes and everything.

ASP.NET routes means you can remove .svc file.

Service Discovery

Ad-hoc mode is broadcast based, enquire and announce to local subnet.

Managed mode is a central proxy/catalog.

Message Routing

Rules-based and transport neutral so HTTP can go via MSMQ.

Server in DMZ and routed to inside.

Bridge protocols (e.g. HTTP > net.tcp)

Well-known public façade for many services.

Load balancing, routes can be round-robin or fallback on timeout.


Multicast one-way message to receivers that need to know.

WCF 4.0 Config Model Updates

Default Endpoints

One per contract/base address combination. This is done via protocolMapping, which can be tweaked.

If any endpoints are configured, then this overrides the auto config. So adding a MEX endpoint in code will screw it up, so you need to call host.AddDefaultEndpoints();

Default Bindings & Behaviours

So you can now setup defaults in machine.config and override in web.config.

Common behaviours are not new to 4.0 but these allow additive behaviours and are only allowed in machine.config <commonBehaviors>

Standard Endpoints

Use the kind attribute on the endpoint, mexEndpoint, discoveryEndpoint, webHttpEndpoint for REST.

<endpoint kind=”webHttpEndpoint”> ßfails because it needs contract

<endpoint kind=”webHttpEndpoint” contract=”lala”>

<endpoint kind=”mexEndpoint” address=”/mex”> ß needs address

No other configuration needed.

WCF 4.0 REST Updates

Automatic Help page shows available verbs and actions, <webHttp> helpEnabled=”true” and visit blah.svc/help

Caching works like this:

public ...

Profiles are added like this (aspNetCompatibilityEnabled=”true” must be set):

<add name=”CacheFor10Seconds” duration=”10” varyByHeader=”Accept” varyByParam=”” />

Message Format Selection

Needs switching on:

<system.serviceModel/standardEndpoints/webHttpEndpoint/standardEndpoint name=”” automaticFormatSelectionEnabled=”true” />

WCF Routes

// Global.asax called from Application_Start
private void RegisterRoutes()
var f = new WebServiceHostFactory();
RouteTable.Routes.Add(new ServiceRoute(“Data”, factory, typeof(MyService)));

Labels: ,


Post a Comment