Does implementing IServiceBehavior affect ServiceBehavior attributes?

2.3k Views Asked by At

I have a WCF service. I need to implement IServiceBehavior in my class that implements ServiceContract. I have some some attributes on that class that specify service behavior. I wanted to ask if after implementing IServiceBehavior behaviors specified in attributes still apply.

Basically does

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, 
                 ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService
{
...
}

mean same thing as

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, 
                 ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService, IServiceBehavior
{
...
}

By the same I mean that I still have ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple).

My implementation of IServiceBehavior is as follows:

void AddBindingParameters(ServiceDescription serviceDescription, 
                          ServiceHostBase serviceHostBase, 
                          Collection<ServiceEndpoint> endpoints, 
                          BindingParameterCollection bindingParameters)
{            
}

void ApplyDispatchBehavior(ServiceDescription serviceDescription, 
                           ServiceHostBase serviceHostBase)
{
    IErrorHandler handler = new ErrorHandler();
    foreach (ChannelDispatcher dispatcher in serviceHostBase.ChannelDispatchers)
    {
        dispatcher.ErrorHandlers.Add(handler);
    }
}

void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{            
}

I just want to implement central error handling, I don't want to change service behavior in any other way.

Thanks for help.

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, the behavior in the ServiceBehaviorAttribute still applies; your IServiceBehavior just provides a way for you to provide further customization of the runtime.