title: WCF client with ssl and username/password authentication
body: <p>I am trying to connect to service which is accesssible over https and need authentication.</p>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>Test method
    TestProject1.UnitTest1.TestReharB2B
    threw exception: 
    System.ServiceModel.Security.MessageSecurityException:
    The HTTP request is unauthorized with
    client authentication scheme
    'Anonymous'. The authentication header
    received from the server was 'Basic
    realm="Application"'. ---> 
    System.Net.WebException: The remote
    server returned an error: (401)
    Unauthorized..</p>
  </blockquote>
  
  <p>It seems to me like that username and password is not sent to service. What am I missing?</p>
  
  <p>The code:</p>
  
  <pre><code>EndpointAddress address = new EndpointAddress(
                      new Uri("https://84.52.158.151:8443/JavaStore/services/B2BService"),
                          EndpointIdentity.CreateDnsIdentity("JavaStore"),
                          new AddressHeaderCollection()
                  );
  
  BasicHttpBinding binding = new BasicHttpBinding();
  binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
  binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
  
  var client = new ReharB2BService.B2BServicePortTypeClient(binding, address);
  
  client.ChannelFactory.Credentials.UserName.UserName = "dotNet";
  client.ChannelFactory.Credentials.UserName.Password = "dotnetpwd";
  
  client.Open();
  client.getAllItems();
  </code></pre>