title: The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm="pc"'
body: <p>Server:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;services&gt;
          &lt;service name="Service" behaviorConfiguration="md"&gt;
              &lt;!-- Service Endpoints --&gt;
              &lt;endpoint address="SslService" binding="basicHttpBinding" bindingConfiguration="security" contract="IService"/&gt;
              &lt;host&gt;
                  &lt;baseAddresses&gt;
                      &lt;add baseAddress="https://pc:8080/Service.svc"/&gt;
                  &lt;/baseAddresses&gt;
              &lt;/host&gt;
          &lt;/service&gt;
      &lt;/services&gt;
      &lt;bindings&gt;
          &lt;basicHttpBinding&gt;
              &lt;binding name="security"&gt;
                  &lt;security mode="Transport"&gt;
                      &lt;transport clientCredentialType="Basic"/&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;behaviors&gt;
          &lt;serviceBehaviors&gt;
              &lt;behavior name="md"&gt;
        &lt;serviceCredentials&gt;
          &lt;userNameAuthentication
            userNamePasswordValidationMode="Custom"
            customUserNamePasswordValidatorType="ClassLibrary1.CustomUserNameValidator, ClassLibrary1" /&gt;
        &lt;/serviceCredentials&gt;
                  &lt;serviceMetadata httpsGetEnabled="true"/&gt;
              &lt;/behavior&gt;
          &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>ClassLibrary1.CustomUserNameValidato:</p>
  
  <pre><code>public class CustomUserNameValidator : System.IdentityModel.Selectors.UserNamePasswordValidator
      {
          public override void Validate(string userName, string password)
          {
              if (userName != "111" || password != "111")
              {
  
                  throw new System.ServiceModel.FaultException("Unknown username or incorrect password");
              }
          }
      }
  </code></pre>
  
  <hr>
  
  <p>Client:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
          &lt;basicHttpBinding&gt;
              &lt;binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
                  openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                  allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                  maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                  messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                  useDefaultWebProxy="true"&gt;
                  &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                      maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
                  &lt;security mode="Transport"&gt;
                      &lt;transport clientCredentialType="Basic" proxyCredentialType="Basic" realm=""&gt;
                          &lt;extendedProtectionPolicy policyEnforcement="Never" /&gt;
                      &lt;/transport&gt;
                      &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
          &lt;endpoint address="https://pc:8080/Service.svc/SslService" binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
              name="BasicHttpBinding_IService" /&gt;
      &lt;/client&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <hr>
  
  <pre><code>ServiceReference1.ServiceClient s = new WindowsFormsApplication1.ServiceReference1.ServiceClient();
  
  s.ClientCredentials.UserName.UserName = "111";
  s.ClientCredentials.UserName.UserName = "111";
  MessageBox.Show(s.GetData(3)); // &lt;---- ERROR
  </code></pre>
  
  <p><strong>The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm="pc"'.</strong></p>