Alejandro Martin
Alejandro Martin

Reputation: 5877

Is the ServiceBehavior attribute inherited by another classes?

I have several WCF services, and those services share some common methods. So, I have created a base class (not a WCF service) with those methods and made all the WCF services to inherit from this class. Something like this:

[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
    public abstract class BaseService

And one of the WCF services:

public class ExampleService : BaseService, IExampleService
    {

I'm using the ServiceBehavior attribute to set the ConcurrencyMode and InstanceContextMode values, and my question is: Is correct to mark the base class with the ServiceBehavior attribute, and expect all the services to inherit the values of the ServiceBehavior attribute, or should I mark one by one all the WCF services?

Upvotes: 2

Views: 1787

Answers (1)

Rajesh
Rajesh

Reputation: 7876

Yes, ServiceBehavior Attribute is inherited to the child classes as the "ServiceBehaviorAttribute" class has the AttributeUsage attribute which doesn't set the "Inherited" value to False.

The default value for "Inherited" is True in "AttributeUsageAttribute" class.

A simple example would be to set the Namespace property in your Abstract class and see that reflected in your wsdl.

Upvotes: 10

Related Questions