开发者

How to add a custom IOperationInvoker to every operation in an endpoint

I have the need for a custom IOperationInvoker in my service. I have it working just fine, but I don't p开发者_如何学Goarticularly like the idea that in order to apply it to a given operation I have to make it an attribute. I can't seem to find any documentation on how to have it config based (similar to a MessageInspector on an endpoint).

I created an CustomBehavior that implements an IEndpointBehavior. In the ApplyDispathBehavior I have the following:

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

However, the custom invoker doesn't seem to "stick". Could the changes be getting cleared later in the life cycle?

Everything does work if I make the behavior an attribute, but I would rather not do that. Does anyone know of a better way to apply a custom OperationBInvoker to all methods in a given endpoint?

Much thanks!


I think I figured it out. By looping through each operation, I can add a behavior to it. I don't know if this is the best way, but it does work.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜