title: In WCF, for a webHttpBinding, how do I specify credentials in the client side web.config when the server is using basic authentication?
body: <p>I have two WCF RESTful services - the "general" service is public and has no security; the "admin" service I intend to use basic authentication over SSL.  This is my server side web.config:  </p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
          &lt;webHttpBinding&gt;
              &lt;binding name="general" maxReceivedMessageSize="2147483647"&gt;
                  &lt;readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" /&gt;
                  &lt;security mode="None"&gt;
                      &lt;transport clientCredentialType="None" /&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
              &lt;binding name="admin" maxReceivedMessageSize="2147483647"&gt;
                  &lt;readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" /&gt;
                  &lt;security mode="Transport"&gt;
                      &lt;transport clientCredentialType="Basic" /&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/webHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;behaviors&gt;
          &lt;serviceBehaviors&gt;
              &lt;behavior&gt;
                  &lt;serviceMetadata httpGetEnabled="true"/&gt;
                  &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
              &lt;/behavior&gt;
          &lt;/serviceBehaviors&gt;
          &lt;endpointBehaviors&gt;
              &lt;behavior name="web"&gt;
                  &lt;webHttp/&gt;
              &lt;/behavior&gt;
          &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;services&gt;
          &lt;service name="MyNamespace.AppServices.GeneralService"&gt;
              &lt;endpoint address="" binding="webHttpBinding" contract="MyNamespace.Contracts.IGeneralService" behaviorConfiguration="web" bindingConfiguration="general" /&gt;
          &lt;/service&gt;
          &lt;service name="MyNamespace.AppServices.AdminService"&gt;
              &lt;endpoint address="" binding="webHttpBinding" contract="MyNamespace.Contracts.IAdminService" behaviorConfiguration="web" bindingConfiguration="admin" /&gt;
          &lt;/service&gt;
      &lt;/services&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>On the client side, I currently have code that looks like this:</p>
  
  <pre><code>private static IGeneralService GetGeneralChannel()
  {
      WebHttpBinding binding = new WebHttpBinding();
      binding.Security.Mode = WebHttpSecurityMode.None;
      binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
      binding.MaxReceivedMessageSize = Int32.MaxValue;
      binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
      binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
  
      WebChannelFactory&lt;IGeneralService&gt; cf = new WebChannelFactory&lt;IGeneralService&gt;(binding, new Uri("http://localhost:1066/GeneralService"));
      IGeneralService channel = cf.CreateChannel();
      return channel;
  }
  
  private static IAdminService GetAdminChannel()
  {
      WebHttpBinding binding = new WebHttpBinding();
      binding.Security.Mode = WebHttpSecurityMode.Transport;
      binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
      binding.MaxReceivedMessageSize = Int32.MaxValue;
      binding.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
      binding.ReaderQuotas.MaxArrayLength = Int32.MaxValue;
  
      WebChannelFactory&lt;IAdminService&gt; cf = new WebChannelFactory&lt;IAdminService&gt;(binding, new Uri("http://localhost:1066/AdminService"));
      cf.Credentials.UserName.UserName = "myUserName";
      cf.Credentials.UserName.Password = "myPassword";
  
      IAdminService channel = cf.CreateChannel();
      return channel;
  }
  </code></pre>
  
  <p>The question is, since I obviously do not want to hard-code all of this configuration information, how do I need to provide it in the web.config on the client?  It is pretty clear to me that the binding element needs to look pretty much the same on the client as it does on the server.  However, where do I indicate the credentials that are assigned to the WebChannelFactory?</p>
  
  <p>Any help and/or insight will be appreciated.</p>
  
  <p>Thanks,
  Steve</p>