Click here to Skip to main content
15,886,422 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 asp.net 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
<serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom"
             customUserNamePasswordValidatorType="TruckService.ServiceLibrary.TruckService,TruckService.ServiceLibrary" />
          </serviceCredentials>
  <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName"/>
          </security>

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);
            }
Posted
Updated 20-Sep-21 18:12pm
v2

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