none
UserNamePasswordValidator throws "The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state" RRS feed

  • Question

  • Im using UserNamePasswordValidator to authenticate the user credentials over https. If user is not authenticated then im throwing security exception

        public class MyValidator : UserNamePasswordValidator
        {
            public override void Validate(string userName, string password)
            {
                if (userName != "myusername" && password != "Mypassword")
                {
                    throw new SecurityTokenException("Invalid username or password");
                }
            }
        }
    However when client invoke the service with invalid credentials he is getting the following exception 

    {"The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state."}

    I'm not sure why?

    Note: There are lot of articles that suggest to use IErrorHandler to send FaultException back to client but that's wrong in this scenario. Because UserNamePassworkValidator validates the credential on different thread so even though you implement IErrorHandler, it will not invoke ProvideFault method of IErrorHandler. I have implemented IErrorHandler for this service and it handles other unhandled exceptions without any issue.

    Thursday, December 4, 2014 6:41 PM

All replies

  • may be i didnt put my question properly, but my question was not How to implement it but after implementing UserNamePasswordValidator, when client try to invoke the service with invalid credential, it does not get the same exception message as thrown in Validate method. Instead client always receives faulted state exception as mentioned above.

    It doesn't matter what type of exception you throw from validate method (SecurityTokeException or FaultException) the client always get faulted state exception.


    • Edited by lax4u Tuesday, December 9, 2014 3:36 AM
    Tuesday, December 9, 2014 3:35 AM