title: Adding an Authorization header to a Service Reference SOAP request
body: <p>I've consumed a WSDL as and have succesfully called web-service methods.The request has an Authorization header that can only be added at the point the request is made:</p>
  
  <pre><code>    public static NumberCaptureClient Connect()
      {
          var remoteAddress = new EndpointAddress("https://website.com:8443/webservice/WebServiceNumberCapture");
  
          using (var NumberCaptureClient = new NumberCaptureClient(new BasicHttpBinding(BasicHttpSecurityMode.Transport), remoteAddress))
          {
              NumberCapture.ClientCredentials.UserName.UserName = "test";
              NumberCapture.ClientCredentials.UserName.Password = "test";
  
              try
              {
                  using (OperationContextScope scope = new OperationContextScope(NumberCaptureClient.InnerChannel))
                  {
                      var httpRequestProperty = new HttpRequestMessageProperty();
  
                      httpRequestProperty.Headers[HttpRequestHeader.Authorization] = "Basic " +
                      Convert.ToBase64String(Encoding.ASCII.GetBytes(NumberCaptureClient.ClientCredentials.UserName.UserName + ":" + NumberCaptureClient.ClientCredentials.UserName.Password));
  
                      OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
                  }
  
              }
              catch (Exception error)
              {
                  MessageBox.Show("Error");
                  return null;
              }
  
              return NumberCaptureClient;
          }    
      }
  </code></pre>
  
  <p>As you can see I'm in need of returning an instance of the proxy client (the client has hundereds of methods that all need the header) but need it so the headers are always sent, with the 'using' clause this isn't possible as the scope is lost outside of it.</p>
  
  <p>Is there a way to permanantly add the headers so they are sent with every request to the webservice?</p>