title: How to use a Service Reference with a basic authentication WCF SOAP Service
body: <p>I have a WCF SOAP service that uses basic access authentication.  SSL is not being used - I understand the security issues here.</p>
  
  <p>Using the WCFTestClient application I have verified the service works by temporarily hard coding into the service a user name and password to use when the <code>Authorization</code> header is not present.</p>
  
  <p>I am now trying to write a test application that passes the credentials via the <code>Authorization</code> header.  I've added a service reference to my service in my test app but the <code>Authorization</code> header is not present in the http request.  The generated <code>MyServiceClient</code> class uses <code>System.ServiceModel.ClientBase</code></p>
  
  <p>In my test app I am setting the credentials as follows</p>
  
  <pre><code>MyServiceClient client = new MyServiceClient("BasicHttpBinding_MyService");
  client.ClientCredentials.UserName.UserName = "WebServiceUsername";
  client.ClientCredentials.UserName.Password = "WebServicepassword";
  </code></pre>
  
  <p>I have also tried as follows</p>
  
  <pre><code>MyServiceClient client = new MyServiceClient();
  ClientCredentials loginCredentials = new ClientCredentials();
  loginCredentials.UserName.UserName = "WebServiceUsername";
  loginCredentials.UserName.Password = "WebServicepassword";
  client.Endpoint.Behaviors.Remove(client.Endpoint.Behaviors.Find&lt;ClientCredentials&gt;()); 
  client.Endpoint.Behaviors.Add(loginCredentials);
  </code></pre>
  
  <p>The service web.config is as follows</p>
  
  <pre><code>&lt;services&gt;
    &lt;service name="MyService" behaviorConfiguration="MyBehavior" &gt;
      &lt;endpoint contract="MyService" binding="basicHttpBinding" /&gt;
      &lt;endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>
  
  <p>The test app.config is as follows</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="BasicHttpBinding_MyService"&gt;
            &lt;security mode="TransportCredentialOnly"&gt;
              &lt;transport clientCredentialType="Basic"/&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="http://localhost:55314/MyService.svc"
          binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService"
          contract="MyService" name="BasicHttpBinding_MyService" /&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Any thoughts on what I am missing?</p>