实现 IServiceBehavior 是否会影响 ServiceBehavior 属性?

发布于 2024-08-02 11:22:24 字数 1523 浏览 5 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我很坚强 2024-08-09 11:22:24

是的,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文