实现 IServiceBehavior 是否会影响 ServiceBehavior 属性?
我有 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)
{
}
我只想实现中央错误处理,我不想以任何其他方式更改服务行为。
感谢您的帮助。
I have a WCF service. I need to implement IServiceBehavior in my class that implements ServiceContract. I have some some attributes on that class that specify service behavior. I wanted to ask if after implementing IServiceBehavior behaviors specified in attributes still apply.
Basically does
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService
{
...
}
mean same thing as
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
public class MyService : IMyService, IServiceBehavior
{
...
}
By the same I mean that I still have ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple)
.
My implementation of IServiceBehavior is as follows:
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)
{
}
I just want to implement central error handling, I don't want to change service behavior in any other way.
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,ServiceBehaviorAttribute 中的行为仍然适用;您的 IServiceBehavior 只是为您提供了一种提供运行时进一步自定义的方法。
Yes, the behavior in the ServiceBehaviorAttribute still applies; your IServiceBehavior just provides a way for you to provide further customization of the runtime.