WCF pipeline architecture is very extendable, allowing the developer to hook-in, in various locations and implement a custom logic as needed.
As there are so many extendability points and some might seem to overlap. It is sometimes confusing or overwhelming to decide which extensibility method to use and where exactly to hook it.
So how do you approach this extendability dilema?
The first question you have to ask yourself, is what is the scope level of the change? This will assist you in dicovering where to hook your extensibility point. It will also help you decide among overlapping extendability points, by choosing the more approriate one for your scope.
There are 4 possible answers for this questions:
The figure above shows the different scope levels in which you can hook your custom extensibility point.
The most granular scope is at the operation level and it is accessible by using IOperationBehavior. It is the most granular, as WCF contracts are constructed of one or more operations and a contract is part of an endpoint which is part of a service.
Going up one level, we have the endpoint level which is accessible by using IEndpointBehavior.
The next level is the contract level, accessible by using IContractBehavior. One can argue if this level is at higher scope than the endpoint level or the opposite is true. The reasons I placed the contract level above the endpoint level is because multiple endpoints can have the same contract (with different address and binding), thus modifying the contract behavior might affect multiple endpoints.
The highest level is the service level, accessible by using IServiceBehavior. It is obvious why this is the highest level, as a service can implement multiple contracts (and have multiple endpoints).
After dealing with the “Where” question, we still need to answer the question “Which” extensibility point suits us most.
The following diagrams can be used to assist you. Even though they do not contain all extensibility points, they contain the most frequently used.
On the client –
On the Server –
One last thing, which is good to know and understand is the order in which these extensibility points are invoked.
On the client side:
On the server side:
For more information about the extensibility points available, see – http://wcfpro.wordpress.com/wcf-extensions/