tags:

views:

274

answers:

3

I want to add my own IOperationInvoker to a wcf client but can't get it to work. I have this

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
}
+1  A: 

You must have something mixed up here - the IOperationInvoker is a server-side only extension point. It allows you to inspect an incoming message and invoke a particular operation on the service based on that message (its content, headers - whatever).

On the client side, this doesn't make sense at all - there's no way a client can use a IOperationInvoker implementation.

If you want to know how to add an IOperationInvoker implementation on the server-side, check out this blog post for a complete run-down.

For an excellent general-purpose introduction to WCF extensibility, check out Aaron Skonnards MSDN article here.

Marc

marc_s
Ok, I'm trying to add exception handling to all methods in the service client, is there a way to do this?
A: 

Sounds like you might be better served implementing an IClientMessageInspector extension instead.

tomasr
A: 

It would be great if someone could provide a little bit of sample code on this one as I can't find an example that does what I want to do. If all goes well I don't do anything, if I get an exception I want to wrap that up in my own exception type and rethrow it.