简体   繁体   English

WCF ChannelFactory和OperationBehavior

[英]WCF ChannelFactory and OperationBehavior

I have a service contract as follow 我有一份服务合同如下

[ServiceContract]
public interface IService
{
     [MyCustomBehavior]
     [OperationContract]
     void MyOperation();
}

The question is whether a call to 问题是是否致电

 new ChannelFactory<IService>(myBinding, myUri)

Will implicitly add MyCustomBehavior before the call, just by virtue of me passing the IService to the ChannelFactory or will I need to dig deeper and explicitly set MyCustomBehavior to the MyOperation operation? 仅仅由于我将IService传递给ChannelFactory会隐式在调用之前添加MyCustomBehavior,还是我需要更深入地挖掘并将MyCustomBehavior显式设置为MyOperation操作?

Operation Behaviors 操作行为

Operation behaviors, which implement the IOperationBehavior interface, are used to extend both the client and service runtime for each operation. 实现IOperationBehavior接口的操作行为用于扩展每个操作的客户端和服务运行时。

There are two mechanisms for adding operation behaviors to an operation. 有两种将操作行为添加到操作的机制。 The first mechanism is to create a custom attribute to be used on the method that models the operation. 第一种机制是创建要在对操作进行建模的方法上使用的自定义属性。 When an operation is added to either a ServiceHost or a ChannelFactory, WCF adds any IOperationBehavior attributes to the behaviors collection on the OperationDescription created for that operation. 将操作添加到ServiceHost或ChannelFactory时,WCF会将任何IOperationBehavior属性添加到为该操作创建的OperationDescription上的行为集合。

The second mechanism is by directly adding the behavior to the behaviors collection on a constructed OperationDescription. 第二种机制是通过将行为直接添加到构造的OperationDescription上的行为集合中。

I will suggest you to read this first. 我建议您先阅读此内容。

Configuring and Extending the Runtime with Behaviors 使用行为配置和扩展运行时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM