简体   繁体   English

如何将IOperationInvoker添加到wcf客户端

[英]How do I add IOperationInvoker to wcf client

I want to add my own IOperationInvoker to a wcf client but can't get it to work. 我想将自己的IOperationInvoker添加到wcf客户端但无法使其工作。 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
}

You must have something mixed up here. 你必须在这里混淆一​​些东西。

The IOperationInvoker is a server-side only extension point. IOperationInvoker是仅服务器端的扩展点。 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. 在客户端,这根本没有意义 - 客户端无法使用IOperationInvoker实现。

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. 如果您想知道如何在服务器端添加IOperationInvoker实现,请查看此博客文章以获取完整的故障。

For an excellent general-purpose introduction to WCF extensibility, check out Aaron Skonnards MSDN article here . 有关WCF可扩展性的出色通用介绍,请查看Aaron Skonnards MSDN文章

Marc

听起来你可能会更好地实现IClientMessageInspector扩展。

You have missed IOperationBehavior 你错过了IOperationBehavior

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

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

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