title: WCF custom username and password validation is not executed
body: <p>I have a WCF service hosted on IIS 7.5 with the settings of basicHttpBinding binding and TransportWithMessageCredential security. I would like to send a FaultException to the client in case of failed authentication but unfortunately the Validate method of custom validator class is not executed.
  I have read <a href="https://go4answers.webhost4life.com/Example/wcf-customusernamepasswordvalidatortype-50333.aspx" rel="nofollow">here</a>, that custom validator works only for self-hosting scenario:
  Is it true, or I made a mistake somewhere?</p>
  
  <pre><code>public class ServiceUserNamePasswordValidator : UserNamePasswordValidator
  {
      public override void Validate(string userName, string password)
      {
          if (null == userName || null == password)
          {
              throw new ArgumentNullException();
          }
  
          if (!(userName == MobilApp.Helper.SiteGlobal.UserName &amp;&amp; password == MobilApp.Helper.SiteGlobal.Password))
          {
              throw new FaultException("Unknown Username or Incorrect Password");
          }
  
      }
  }
  </code></pre>
  
  <p>web.config:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="True" /&gt;
  &lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="ServiceBinding" useDefaultWebProxy="false"&gt;          
        &lt;security mode="TransportWithMessageCredential"&gt;
          &lt;transport clientCredentialType="Certificate" /&gt;
          &lt;message clientCredentialType="UserName" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;services&gt;
    &lt;service name="Service.TestService" behaviorConfiguration="CustomValidator"&gt;
      &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration="ServiceBinding"
        bindingNamespace="https://service/TestService/"
        contract="Service.ITestService"&gt;
        &lt;identity&gt;
          &lt;dns value="localhost" /&gt;
        &lt;/identity&gt;
      &lt;/endpoint&gt;
      &lt;endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /&gt;
      &lt;host&gt;
        &lt;baseAddresses&gt;
          &lt;add baseAddress="https://service/TestService/" /&gt;
        &lt;/baseAddresses&gt;
      &lt;/host&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="CustomValidator"&gt;
        &lt;useRequestHeadersForMetadataAddress/&gt;
        &lt;serviceMetadata httpGetEnabled="false" httpsGetEnabled="True" httpsGetUrl="wsdl" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="false" httpHelpPageEnabled="false" httpsHelpPageEnabled="true" /&gt;
        &lt;serviceCredentials&gt;
          &lt;clientCertificate&gt;
            &lt;authentication
              certificateValidationMode="ChainTrust"
              revocationMode="NoCheck" /&gt;
          &lt;/clientCertificate&gt;
          &lt;serviceCertificate
            findValue="test.com"
            x509FindType="FindBySubjectName"
            storeLocation="LocalMachine"
            storeName="My" /&gt;
          &lt;userNameAuthentication
            userNamePasswordValidationMode="Custom"
            customUserNamePasswordValidatorType="ServiceUserNamePasswordValidator, Service" /&gt;
        &lt;/serviceCredentials&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thank you.</p>