Ale*_*tin 3 c# wcf inheritance attributes
我有几个WCF服务,这些服务共享一些常用方法.所以,我用这些方法创建了一个基类(不是WCF服务),并使所有WCF服务都从这个类继承.像这样的东西:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
public abstract class BaseService
Run Code Online (Sandbox Code Playgroud)
并且其中一个WCF服务:
public class ExampleService : BaseService, IExampleService
{
Run Code Online (Sandbox Code Playgroud)
我正在使用ServiceBehavior属性来设置ConcurrencyMode和InstanceContextMode值,我的问题是:使用ServiceBehavior属性标记基类是正确的,并期望所有服务继承ServiceBehavior属性的值,或者我应该标记所有WCF服务一个接一个?
Raj*_*esh 10
是的,ServiceBehavior属性继承到子类,因为"ServiceBehaviorAttribute"类具有AttributeUsage属性,该属性未将"Inherited"值设置为False.
"Inherited"的默认值在"AttributeUsageAttribute"类中为True.
一个简单的例子是在Abstract类中设置Namespace属性,并查看wsdl中反映的内容.
| 归档时间: |
|
| 查看次数: |
1628 次 |
| 最近记录: |