How to add a default endpoint behaviors to all services

3.5k Views Asked by At

I'm attempting to add an endpoint behavior to all services of a host.

So for example, I have a couple of .svc ServiceHost declarations and I want to know how I would be able to configure this via Web.config.

Any ideas? Thanks.

3

There are 3 best solutions below

0
On BEST ANSWER

Create custom class derived from ServiceHost and custom class derived from ServiceHostFactory. In your custom ServiceHost implementation add needed behaviors. Here you have example.

0
On

Untested, but see if this helps -

foreach (var endPoint in mySvcHost.Description.Endpoints)
{
    endPoint.Behaviors.Add(new MyBehavior());
}
2
On

It's untested but I think if you add an EndpointBehavior with no name to the Advanced->Endpoint Behavior (in the WCF config tool), then it's done for all service endpoints (unless overriden).

The same thing works for the Service Behaviors (that's what I'm using so I know that works).