WCF: Retrieving MethodInfo from OperationContext

后端 未结 4 1418
猫巷女王i
猫巷女王i 2020-12-13 07:20

Is there an elegant way to get the method that will be executed on a service instance from MessageInspector/AuthorizationPolicy/some other extension point? I could use

4条回答
  •  有刺的猬
    2020-12-13 07:51

    If OperationContext.CurrentIncomingMessageHeaders.Action is null, you can do this -- it's a bit terser:

    string actionName = OperationContext.Current.IncomingMessageProperties["HttpOperationName"] as string;
    Type hostType = operationContext.Host.Description.ServiceType;
    MethodInfo method = hostType.GetMethod(actionName);
    

提交回复
热议问题