【问题标题】:How to add a custom IOperationInvoker to every operation in an endpoint如何将自定义 IOperationInvoker 添加到端点中的每个操作
【发布时间】:2010-06-20 01:36:26
【问题描述】:

我需要在我的服务中使用自定义 IOperationInvoker。我让它工作得很好,但我并不特别喜欢这样的想法,即为了将其应用于给定的操作,我必须将其设为属性。我似乎找不到任何关于如何配置它的文档(类似于端点上的 MessageInspector)。

我创建了一个实现 IEndpointBehavior 的 CustomBehavior。在 ApplyDispathBehavior 我有以下内容:

public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
{
    foreach (var operation in endpointDispatcher.DispatchRuntime.Operations)
    {
        operation.Invoker = new MockServiceOperationInvoker() {Invoker=operation.Invoker };
    }
}

但是,自定义调用程序似乎并没有“坚持”。是否可以在生命周期的后期清除更改?

如果我将行为作为属性,一切都会起作用,但我宁愿不这样做。有谁知道将自定义 OperationBInvoker 应用于给定端点中的所有方法的更好方法?

非常感谢!

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    我想我明白了。通过循环每个操作,我可以为其添加一个行为。我不知道这是否是最好的方法,但它确实有效。

    public class MockOperationBehavior : BehaviorExtensionElement,  IOperationBehavior, IEndpointBehavior
    {
      public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
      {
         foreach (var op in endpoint.Contract.Operations)
         {
             op.Behaviors.Add(this);
         }
      }
    }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 2019-08-23
    • 1970-01-01
    • 2021-05-28
    • 2018-01-11
    • 1970-01-01
    相关资源
    最近更新 更多