[Dev Tip] Choosing the right extensibility point


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:

    1. The Service level (IServiceBehavior)  – affects the whole service.
    2. The Endpoint level (IEndpointBehavior) affects a specific endpoint.
    3. The Contract level (IContractBehavior) – affects a specific contract.
    4. The Operation level (IOperationBehavior) – affects a specific operation from a contract.

image

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 –

image

On the Server –

image

One last thing, which is good to know and understand  is the order in which these extensibility points are invoked.

On the client side:

image

On the server side:

image

For more information about the extensibility points available, see –  http://wcfpro.wordpress.com/wcf-extensions/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s