title: The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm=""
body: <p>I am trying to access a Soap webservice (HTTP) which requires authentication.I am using WCF to consume the service. 
  I am getting error Message as "The HTTP request is unauthorized with client authentication scheme 'Basic'. The authentication header received from the server was 'Basic realm="XXXXX"'."</p>
  
  <p>However when I tried to send the authentication headers along with each request. I'm getting 401 errors when I attempt to do anything with the web service.</p>
  
  <p>Any help is appreciated, thank you.</p>
  
  <p>This is what my code looks like:</p>
  
  <pre><code> var myBinding = new BasicHttpBinding("exampleBinding");
      myBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
      myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
      myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
      EndpointAddress ea = new EndpointAddress("http://test.co.uk/webservices");
  
      var serviceClient = new ServicesClient(myBinding, ea);
      serviceClient.ClientCredentials.UserName.UserName = "username";
      serviceClient.ClientCredentials.UserName.Password = "password";
      HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
  
      httpRequestProperty.Headers[HttpRequestHeader.Authorization] = "Basic " +                   Convert.ToBase64String(Encoding.ASCII.GetBytes(serviceClient.ClientCredentials.UserName.UserName + ":" + serviceClient.ClientCredentials.UserName.Password));
  
      httpRequestProperty.Headers[HttpRequestHeader.ProxyAuthorization] =  "Basic " +             Convert.ToBase64String(Encoding.ASCII.GetBytes(serviceClient.ClientCredentials.UserName.UserName + ":" + serviceClient.ClientCredentials.UserName.Password));
  
      using (OperationContextScope scope = new OperationContextScope((IClientChannel)serviceClient.InnerChannel))
      {
        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] =   httpRequestProperty;
  
        var response = serviceClient.DepartureBoard(request);
      }
  
  
  Web config
  -----------
     &lt;bindings&gt;
            &lt;basicHttpBinding&gt;
              &lt;binding name="jpservicesBinding"&gt;
                &lt;security mode="Transport"&gt;
                  &lt;transport clientCredentialType="Basic" proxyCredentialType="Basic" realm=""&gt;&lt;/transport&gt;
                  &lt;message clientCredentialType="UserName"/&gt;
                &lt;/security&gt;
              &lt;/binding&gt;
            &lt;/basicHttpBinding&gt;
          &lt;/bindings&gt;
          &lt;client&gt;
            &lt;endpoint address="http://test.co.uk/webservices"
              binding="basicHttpBinding" bindingConfiguration="exampleBinding"
              contract="RealTimePlanner.jservices" name="test" /&gt;
          &lt;/client&gt;
  </code></pre>