简体   繁体   English

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

[英]How to restrict the Operation method call in wcf if it fails in IParameterInspector BeforeCall method

I using IParameterInspector BeforeCall method to validate the user for the current session and if the validation fails it will throw the exception and has to return. 我使用IParameterInspector BeforeCall方法验证当前会话的用户,如果验证失败,它将抛出异常并必须返回。 I am able to validate it and throwing the exception and I can see it in AfterCall correlationState parameter, but still it is executing the wcf method which I was calling from client. 我能够验证它并引发异常,并且可以在AfterCall relatedState参数中看到它,但是它仍在执行我从客户端调用的wcf方法。

Is there is any way to restrict that method call to not hit the wcf method in the IParameterInspector BeforeCall method itself. 有什么方法可以限制该方法调用,以使其不命中IParameterInspector BeforeCall方法本身中的wcf方法。

my code : 我的代码:

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

You should throw faultexception instead of returning it: 您应该抛出faultexception而不是返回它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM