Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wcf IOperationInvoker实现中的Access MethodInfo_Wcf_Wcf Extensions - Fatal编程技术网

Wcf IOperationInvoker实现中的Access MethodInfo

Wcf IOperationInvoker实现中的Access MethodInfo,wcf,wcf-extensions,Wcf,Wcf Extensions,我已经实现了IOperationInvoker来定制WCF调用。 在Invoke方法中,我希望访问OperationInvoker调用的方法的自定义属性。 我已经编写了以下代码。 但是,它没有提供在该方法上指定的自定义属性 public MyOperationInvoker(IOperationInvoker operationInvoker, DispatchOperation dispatchOperation) { this.operationInvoker = o

我已经实现了IOperationInvoker来定制WCF调用。 在Invoke方法中,我希望访问OperationInvoker调用的方法的自定义属性。 我已经编写了以下代码。 但是,它没有提供在该方法上指定的自定义属性

public MyOperationInvoker(IOperationInvoker operationInvoker, DispatchOperation dispatchOperation)
{
            this.operationInvoker = operationInvoker;
}

public object Invoke(object instance, object[] inputs, out object[] outputs)
{
   MethodInfo mInfo=(MethodInfo)this.operationInvoker.GetType().GetProperty("Method").
                     GetValue(this.operationInvoker, null);
object[] objCustomAttributes = methodInfo.GetCustomAttributes(typeof(MyAttribute), true);

}

在运行时,OperationInvoker的类型为SyncMethodInvoker,其中包含MethodInfo。但由于其保护级别,我们无法将OperationInvoker强制转换为SyncMethodInvoker。但是,OperationDescription中有一个MethodInfo对象。所以我通常要做的是将IOperationBehavior.ApplyDispatchBehavior方法中的MethodInfo传递给CustomOperationInvoker的构造函数

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);
  }

  // other method
}

public class CustomOperationInvoker : IOperationInvoker
{
  private IOperationInvoker oldInvoker;
  private MethodInfo methodInfo;
  public CustomOperationInvoker(IOperationInvoker oldOperationInvoker, MethodInfo info)
  {
    this.oldInvoker = oldOperationInvoker;
    this.methodInfo = info;
  }

  // then you can access it 
}