At run time, OperationInvoker is of type SyncMethodInvoker, which contains MethodInfo. But due to its level of protection, we cannot use OperationInvoker for SyncMethodInvoker. However, there is a MethodInfo object in OperationDescription. So, what I usually do is pass MethodInfo in the IOperationBehavior.ApplyDispatchBehavior method to the CustomOperationInvoker constructor.
public class OperationBehaviourInterceptor : IOperationBehavior { public void ApplyDispatchBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.DispatchOperation dispatchOperation) { MethodInfo currMethodInfo = operationDescription.SyncMethod; var oldInvoker = dispatchOperation.Invoker; dispatchOperation.Invoker = new OperationInvokerBase(oldInvoker,currMethodInfo); }
source share