Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <endpointBehaviors> and <serviceBehaviors>

Tags:

asp.net

wcf

I'm not sure I understand the difference between web.config elements <endpointBehaviors> and <serviceBehaviors> (and the adjoining behaviours, of course).

like image 443
Robotronx Avatar asked Dec 30 '15 09:12

Robotronx


2 Answers

From here:

  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.

Also MSDN can always be referred to get the details:

<endpointBehaviors> This configuration section represents all the behaviors defined for a specific endpoint.

<serviceBehaviors> This configuration section represents all the behaviors defined for a specific service.

A good MSDN reference: Configuring and Extending the Runtime with Behaviors

like image 128
Rahul Tripathi Avatar answered Nov 18 '22 23:11

Rahul Tripathi


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 of course there is the biggest difference, if you want to customize endpoints on client then the only option is IEndpointBehavior.

The Contract specifies what the service actually does. In other words, what Operations are valid.

The Endpoint specifies an actual running instance of the service. It is the actual "service" in the sense that it executes, either as a Windows Service or under IIS.

The Service Behavior defines how the endpoint interacts with clients. Attributes like security, concurrency, caching, logging, etc. - those are all part of the behavior.

There is also an Operation Behavior which is similar to the Service Behavior but only gets applied when a specific operation is run.

like image 35
jitendra joshi Avatar answered Nov 18 '22 23:11

jitendra joshi