Freigeben über


IEndpointBehavior vs IServiceBehavior

Why should this be a post topic? From the naming, its clear that one is for extending the "Service" and the other is for extending "Endpoints". We recently had a interesting question posted in our internal forums on this topic and so though I should share it. The ApplyDispatchBehavior method on IServiceBehavior has access to all endpoints and their runtime components and so shouldn't that be enough for wiring up customization? The short answer is yes, but there are subtle differences.

Some usability differences are

1. ServiceBehavior applies only on service while EndpointBehavior applies on both client and service.

2. ServiceBehavior can be specified via config/attribute/code while endpointbehavior can be specified via config/code.

3. ServiceBehavior has access to all ServiceEndpoints dispatch runtime and so could modify all dispatch runtimes while Endpointbehavior gets called with the runtime for that endpoint only.

 

Look at it this way, ServiceBehavior lets you access runtime parameters for all endpoints while Endpointbehavior lets you access runtime components only for that endpoint. So if you have a need to extend functionality that spawns the entire contract (or multiple contracts) then use ServiceBehavior and if you are interested in extending one specific endpoint then use Endpointbehavior.

 

And ofcourse there is the biggest difference, if you want to customize endpoints on client then the only option is IEndpointBehavior. :-)