Click here to Skip to main content
15,305,819 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am doing Custom UserName Password Validation for WCF Service in with c#. I have set a WCF Service Library and set the Authenticator Class in it. Added to my WCF Service, Updated as required in the web.config. However while calling the API Method from Client Side , I am able to fetch the response from Server Side But the validate override method is not hitting on debugging/working.

I am using http protocol here.

What I have tried:

Authentication Class
public override void Validate(string userName, string password)
           //validate arguments
           if (string.IsNullOrEmpty(userName))
               throw new ArgumentNullException(userName);
           if (string.IsNullOrEmpty(password))
               throw new ArgumentNullException(password);
           //check if user is not test
           if (userName!="test" || password != "test")
               throw new FaultException("Incorrect Username or Password");

Web.config update for the Authentication case set
            <userNameAuthentication userNamePasswordValidationMode="Custom"
             customUserNamePasswordValidatorType="TruckService.ServiceLibrary.TruckService,TruckService.ServiceLibrary" />
  <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName"/>

Calling from Client Side
using (ServiceReference1.TruckServiceClient obj = new ServiceReference1.TruckServiceClient())
                obj.ClientCredentials.UserName.UserName = "test";
                obj.ClientCredentials.UserName.Password = "test";
                string returndata = obj.GetData(100);
Updated 20-Sep-21 18:12pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900