如果在IParameterInspector BeforeCall方法中Operation方法调用失败,如何限制wcf中

本文关键字:方法 wcf 何限制 失败 Operation IParameterInspector BeforeCall 如果 调用 | 更新日期: 2023-09-27 17:58:30

I使用IParameterInspector BeforeCall方法为当前会话验证用户,如果验证失败,它将抛出异常并必须返回。我能够验证它并抛出异常,我可以在AfterCall correlationState参数中看到它,但它仍然在执行我从客户端调用的wcf方法。

是否有任何方法可以限制该方法调用不命中IParameterInspector BeforeCall方法本身中的wcf方法。

我的代码:

public object BeforeCall(string operationName, object[] inputs)
        {
            if (UserAuthenticToken.IsValidUser())
                return null;
            else
            {                    
                return new FaultException("User is not authenticated.");
            }
        }

如果在IParameterInspector BeforeCall方法中Operation方法调用失败,如何限制wcf中

您应该抛出faultexception而不是返回它:

public object BeforeCall(string operationName, object[] inputs)
        {
            if (UserAuthenticToken.IsValidUser())
                return null;
            else
            {                    
                throw new FaultException("User is not authenticated.");
            }
        }