none
wcf strongly typed FaultContract is not working within UserNamePasswordValidator RRS feed

  • Question

  • Dear Members.

    On server side:

    public class Authenticator : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if (!AccessControlManager.ValidateUser(userName, password))
            {
                LoginIncorrectFault fault = new LoginIncorrectFault();
    
                fault.Message = "Invalid user and/or password";
    
                throw new FaultException<LoginIncorrectFault>(fault);
            };
        }
    }

    ServiceContract details:

        [OperationContract]
        [FaultContract(typeof(LoginIncorrectFault))]
        void Login();

    On client side:

            try
            {
                var clientCredentials = new ClientCredentials();
    
                clientCredentials.UserName.UserName = textEdit_UserName.Text;
                clientCredentials.UserName.Password = textEdit_UserPwd.Text;
                factory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
                factory.Endpoint.Behaviors.Add(clientCredentials);
    
                GlobalsManager.ServiceClient = factory.CreateChannel();
    
                GlobalsManager.ServiceClient.Login();
    
            }
            catch (FaultException<LoginIncorrectFault> ex)
            {
                MessageBox.Show(ex.Detail.Message);
            };

    But, error raised: "An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail."

    However, if I run the throwing code inside ServiceContract like below, everything works fine:

    public class ESFService : IESFService
    {
        public void Login()
        {
            LoginIncorrectFault fault = new LoginIncorrectFault();
    
            fault.Message = "Invalid user and/or password";
    
            throw new FaultException<LoginIncorrectFault>(fault);
    
        }

    }

    Thanks.

    Trace details:

    DataItem> <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Warning"> <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Security.SecurityBindingVerifyIncomingMessageFailure.aspx</TraceIdentifier> <Description>The security protocol cannot verify the incoming message.</Description> <AppDomain>EngineHost.vshost.exe</AppDomain> <ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/SecurityProtocolTraceRecord"> <SecurityProtocol>System.ServiceModel.Security.SymmetricSecurityProtocol</SecurityProtocol> <Action>http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT</Action> <To>http://localhost:8070/ESFService</To> <EndpointReference xmlns="http://www.w3.org/2005/08/addressing"> <Address>http://www.w3.org/2005/08/addressing/anonymous</Address> </EndpointReference> <MessageId>urn:uuid:cf27ff49-96b5-4d9f-bcfb-47c1d39503de</MessageId> </ExtendedData>


    Thursday, November 5, 2015 4:44 AM

Answers

  • Hi hajiyev,

    According to this issue, can you post a demo about this case?

    The trace details shown the ''Thesecurity protocol cannot verify the incoming message''.

    So, what is your development environment? Are you host your WCF Service on IIS?

    For more information, please refer to the following articles:

    1.WCF:An unsecured or incorrectly fault error

    Best Regards,

    Grady


    Friday, November 6, 2015 6:43 AM
    Moderator