WCF - 验证:无效令牌,如何使用异常详细信息重定向消息

时间:2013-05-22 14:57:35

标签: wcf wcf-security

我已经实现了 IdispatchMessageInspector 的成员来验证SOAP标头中的tokenId。如果令牌无效,我想重定向并显示错误消息。因此它将限制访问Web方法。我不知道怎么办?有人这样做过吗?

#region IDispatchMessageInspector会员

    public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel, InstanceContext instanceContext)
    {            

        if !(ValidateToken(tokenValue))
            //Redirect the error message 

        return null;
    }

    public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
    {
        //Log the Response with Log4Net or
        Console.WriteLine("IDispatchMessageInspector.BeforeSendReply called.");
    }

#endregion

1 个答案:

答案 0 :(得分:1)

抛出异常是正确的事情。使用IErrorHandler接口可以处理服务上的错误或让主机(IIS?)处理错误(500)。