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
}
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
听起来你可能会更好地实现IClientMessageInspector扩展。
You have missed IOperationBehavior
public class MyOperationBehavior : IOperationBehavior
{
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
dispatchOperation.Invoker = new MyOperationInvoker();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.