我有几个WCF服务,这些服务共享一些通用的方法。因此,我使用这些方法创建了一个基类(而不是WCF服务),并使所有的WCF服务都继承自这个类。如下所示:
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
public abstract class BaseService和其中一个WCF服务:
public class ExampleService : BaseService, IExampleService
{我使用ServiceBehavior属性来设置ConcurrencyMode和WCF值,我的问题是:用ServiceBehavior属性标记基类,并期望所有服务继承ServiceBehavior属性的值,是正确的,还是应该逐个标记所有InstanceContextMode服务?
发布于 2012-01-24 17:53:55
是的,子类继承了ServiceBehavior属性,因为"ServiceBehaviorAttribute“类具有AttributeUsage属性,该属性不会将”继承的“值设置为False。
在"AttributeUsageAttribute“类中,"Inherited”的默认值是True。
一个简单的例子是在您的Abstract类中设置Namespace属性,并查看它在wsdl中的反映。
https://stackoverflow.com/questions/8983493
复制相似问题