How to add IOperationInvoker to a wcf client

I want to add my own IOperationInvoker to a wcf client, but I cannot get it to work. I have it

class ClientProgram
{
    static void Main()
    {
        CreateClient().SomeMethod();
    }

    private static MyServiceClient CreateClient()
    {
        var client = new MyServiceClient(new NetTcpBinding(), new EndpointAddress"net.tcp://localhost:12345/MyService"));
        // I guess this is where the magic should happen
        return client;
    }
}

public class MyOperationInvoker : IOperationInvoker
{
    private readonly IOperationInvoker _innerOperationInvoker;

    public MyOperationInvoker(IOperationInvoker innerOperationInvoker)
    {
        _innerOperationInvoker = innerOperationInvoker;
    }

    public object Invoke(object instance, object[] inputs, out object[] outputs)
    {
        Console.WriteLine("Intercepting...");
        return _innerOperationInvoker.Invoke(instance, inputs, out outputs);
    }

    // Other methods not important
}
+3
source share
3 answers

There must be something funny here.

IOperationInvoker- This is only an extension point on the server side. It allows you to check an incoming message and call a specific operation in the service based on this message (its contents, headers - independently).

On the client side, this makes no sense - the client cannot use the implementation IOperationInvoker.

If you want to know how to add a IOperationInvokerserver-side implementation , check out this blog post for a complete exhaustion.

WCF MSDN Aaron Skonnards .

+2
+1

You have lost IOperationBehavior

public class MyOperationBehavior : IOperationBehavior
{
    public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
    {
        dispatchOperation.Invoker = new MyOperationInvoker();
    }
}
-3
source

Source: https://habr.com/ru/post/1714380/


All Articles