我有 WCF 服务。我需要在实现 ServiceContract 的类中实现 IServiceBehavior。我在该类上有一些指定服务行为的属性。我想问一下在实现属性中指定的 IServiceBehavior 行为后是否仍然适用。
基本上可以
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService
{
...
}
意思是一样的
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService, IServiceBehavior
{
...
}
同样,我的意思是我仍然有ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)
。
我对 IServiceBehavior 的实现如下:
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)
{
}
我只想实现中央错误处理,我不想以任何其他方式改变服务行为。
感谢帮助。