What happened to IChannelBehavior?

With the WCF Feb CTP release the IChannelBehavior interface has been removed. In previous CTP's this interface would be used to write a behavior that will let users add customization points on the client side. Actually, we have rewired the behavior mechanism which hopefully will be much clearer to use. Instead of having IEndpointBehavior and IChannelBehavior that applied to Service and Client respectively, we merged them into IEndpointBehavior. Now IEndpointBehavior will be used to extend endpoints on both sides.

Another interface that has been removed from the previous CTP is the IValidator interface. This interface was used by users to validate the input parameters before the runtime was constructed. This interface has also been merged with the IBehavior interfaces. So how does the new behavior interfaces look?

Each I*Behavior has the following methods

void AddBindingParameters(...)

void ApplyClientBehavior(...)

void ApplyDispatchBehavior(...)

void Validate(...)

As you can see, each behavior now has a Validate method that should be used for validation. The AddBindingParameters method can be used to pass custom parameters if the underlying channel expects it. The core work of the behaviors will now be performed in the ApplyDispatchBehavior or ApplyClientBehavior which will be called based on whether the behavior is being applied on the client or the service. So, with this new model, existing behaviors that implemented IChannelBehaviors should implement IEndpointBehavior and do their customization in ApplyClientBehavior and just no-op the ApplyDispatchBehavior implementation. Note that the IServiceBehavior  does not expose an ApplyClientBehavior method as this behavior can be used only on the service.

Here is the order in which these are called for any behavior.

Validate ==> Called when all information needed to build the runtime has been collected and is passed on to user for verification.

AddBindingParameter ==> Called in the first step of building the runtime and before the underlying channel listener is constructed. So users can add custom parameters expected by the underlying channel impelmentation.

Apply[Client/Dispatch]Behavior ==> Finally the runtime has been built and this lets them add customizations to the runtime. Ex. add InstanceContextInitializers.

In the next post I will focuss on how to control the complete process of runtime generation by implementing custom ServiceHost.



Comments (3)

  1. Маджаяр расказывает об изменениях в модели расширений, Ральф Сквилэйс — о конфиг

  2. I’ll prepost this breaking change in the Feb CTP and write more about it later. In a previous post I…

  3. qdzx2008 says:

    .NET 点滴 ASP.NET 2.0

Skip to main content