Custom authentication in WCF RRS feed

  • Question

  • Hello,

    I want to implement a custom Username and Password validation in my WCF service. The configuration of my web.cofig looks like this:

        <binding name="ServiceBinding">
          <security mode="Message">
            <message clientCredentialType="UserName"/>
        <behavior name="customBehaviour">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyWcfService.ClientValidator,MyWcfService"/>
      <service name="MyWcfService.Service1" behaviorConfiguration="customBehaviour">
        <endpoint address=""  binding="wsHttpBinding" contract ="MyWcfService.IService1">
        <endpoint contract="IMetadataExchange"  binding="mexHttpBinding"  address="mex" />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

    This is my custom validator:

    public class ClientValidator : UserNamePasswordValidator
        public override void Validate(string userName, string password)
            if (null == userName || null == password)
                throw new ArgumentNullException();
            if (!(userName == "test" && password == "tset"))
                throw new SecurityTokenException("Unknown Username or Incorrect Password");

    However when calling the service via my test client, the validation does not happen. What do i miss here?

    Thanks in advance,


    Monday, June 18, 2018 8:25 PM

All replies

  • Hi KBid,

    For your issue, I suggest you add the "ServiceBinding" to your endpoint.

    <endpoint address=""  binding="wsHttpBinding" bindingConfiguration="ServiceBinding" contract ="MyWcfService.IService1">

    Best Regards,

    Tao Zhou

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, June 19, 2018 2:40 AM