WCF Extension Points – Dispatcher

Posted: December 28, 2008 in WCF

In this post I will be discussing about the various extensibility points of WCF in the server side.I had already discussed in one of my earlier posts (WCF ServiceHost & Channels) about the basic flow of control in the service side but still let me repeat this here once more for a better context setting.The key elements of the service side dispatcher framework are:

  1. ChannelDispatchers – ChannelDispatchers (ChannelDispatcher) accept incoming messages.Each ChannelDispatcher is associated with exactly one ChannelListener.ChannelListener receives the message as mentioned and the message is processed by channels.After the message is processed by the associated channels then ChannelDispatcher passes it on to a suitable EndpointDispatcher.
  2. EndPointDispatchers – EndPointDispatchers are responsible for taking a message out of the channel stack and passing them to the right service operation.
    • One of the key element of the EndpointDispatcher is the DispatchRuntime.DispatchRuntime provides facility to alter default service behaviour using custom classes to provide enhanced functionality related to Service Instancing,Error Handling,Security etc.
    • DispatchRuntime contains the DispatchOperation which is responsible for routing the message to the right operation and providing customizations facilities applicable at the operation level.

I will list down the extension points available in DispatchRuntime and DispatchOperation along with the interfaces required to be implemented in order to develop these extension components.


  1. DispatchRuntime exposes the following two properties which provide facility to customize how ChannelDispatcher accepts or closes a channel.
    • ChannelInitializers – This is a collection of System.ServiceModel.DispatchRuntime.IChannelInitializer interface objects.This interface is for raising notifications when a channel is created.
    • InputSessionShutdownHandlers – This is a collection of System.ServiceModel..DispatchRuntime.IInputSessionShutdown interface objects.This interface is used to define actions for shutdown of an input session.
  2. The following properties are exposed for customizing message processing:
    • MessageInspectors – This is a collection of System.ServiceModel.DispatchRuntime.IDispatchMessageInspector objects.IDispatchMessageInspector defines contract to manipulate the messages
      • after a message is received but before dispatched to the operation
      • after a operation is executed but before reply is sent
    • OperationSelectors – This is a collection of System.ServiceModel.DispatchRuntime.IDispatchOperationSelector objects.IDispatchOperationSelector defines contract to select an operation name based on the message content.
    • Operations – This is a collection of System.ServiceModel.DispatchRuntime.DispatchOperation.We will discuss about the DispatchOperation in the next section.
    • ErrorHandlers – This is a collection of System.ServiceModel.DispatchRuntime.IErrorHandler objects.IErrorHandler defines methods to control the behaviour when an application exception is thrown.
  3. The creation and lifetime of the service instances can be controlled by
    • InstanceContextInitializers – This is a collection of System.ServiceModel.DispatchRuntime.IInstanceContextInitializer objects.IInstanceContextInitialzer defines the contract to manipulate the InstanceContext objects.
    • InstanceProvider – This is an object of type System.ServiceModel.DispatchRuntime.IInstanceProvider and this interface defines methods to customize creation and release of service instances.


  1. Formatter – This property of type System.ServiceModel.DispatchRuntime.IDispatchMessageFormatter provides explicit control over message formatting.
  2. CallContextInitializers – This is a collection of System.ServiceModel.Dispatcher.ICallContextInitializer objects.This interface defines methods to add additional state information that is required during execution of the call.
  3. ParameterInspectors – This is a collection of System.ServiceModel.DispatchRuntime.IParameterInspector objects and this interface defines methods to inspect/modify the parameters before and after method call.

So to extend the WCF functionality we need develop a component implementing the required interfaces and then assign it with the appropriate property of DispatchRuntime/DispatchOperation.Now the obvious question is how do we attach the these components to the runtime in declarative or config driven manner?.This is where the WCF behaviours come into picture which I will discuss in my next post.


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