Search code examples
wcfwcf-security

WCF - Validation: Invalid token, How to redirect the message with exception details


I have implemented the members of IdispatchMessageInspector to validate the tokenId from the SOAP header. If the token is not valid, I would like redirect with error message. So that it would restrict to access the web methods. I don't know how to do it? Anybody done this before?

#region IDispatchMessageInspector Members

    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


Solution

  • Throwing an exception is right thing to do. Using IErrorHandler interface you can handle error on the service or let the host (IIS?) handle error (500).