简体   繁体   English

ServiceBehavior属性是否由其他类继承?

[英]Is the ServiceBehavior attribute inherited by another classes?

I have several WCF services, and those services share some common methods. 我有几个WCF服务,这些服务共享一些通用方法。 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. 因此,我使用这些方法创建了一个基类(不是WCF服务),并使所有WCF服务都可以从此类继承。 Something like this: 像这样:

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

And one of the WCF services: WCF服务之一:

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? 我正在使用ServiceBehavior属性设置ConcurrencyMode和InstanceContextMode值,我的问题是:用ServiceBehavior属性标记基类是正确的,并且期望所有服务都继承ServiceBehavior属性的值,还是我应该标记一张一张所有的WCF服务?

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. 是的,由于“ ServiceBehaviorAttribute”类具有AttributeUsage属性,因此不会将“ Inherited”值设置为False,因此ServiceBehavior Attribute会继承到子类。

The default value for "Inherited" is True in "AttributeUsageAttribute" class. 在“ AttributeUsageAttribute”类中,“ Inherited”的默认值为True。

A simple example would be to set the Namespace property in your Abstract class and see that reflected in your wsdl. 一个简单的示例是在您的Abstract类中设置Namespace属性,然后将其反映在wsdl中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM