title: Getting DefaultNetworkCredentials to pass through to WCF Service
body: <p>I have a WCF service I have created in a WebApplication with the following configuration in web.config</p>
  
  <pre><code>&lt;service name="RedwebServerManager.WebApplication.DesktopService"
             behaviorConfiguration="ServBehave"&gt;
      &lt;endpoint
         address=""
          binding="basicHttpBinding"
          bindingConfiguration="basicBind"
          contract="RedwebServerManager.WebApplication.IDesktopService"/&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="basicBind"&gt;
        &lt;security mode="TransportWithMessageCredential"&gt;
          &lt;transport clientCredentialType="Windows"/&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  </code></pre>
  
  <p>This service needs to take in WindowsCredentials in to get information in a database based upon the authenticated user. This service current has one method implementing an interface with the following signature</p>
  
  <pre><code>    [ServiceContract]
  public interface IDesktopService
  {
      /// &lt;summary&gt;
      /// Gets the clients.
      /// &lt;/summary&gt;
      /// &lt;returns&gt;IEnumerable&amp;lt;ClientServiceModel&amp;gt;.&lt;/returns&gt;
      [OperationContract]
      IEnumerable&lt;ClientServiceModel&gt; GetClients();
  }
  </code></pre>
  
  <p>I have a Windows Forms application which is consuming the WCF service and I want to pass through the credentials of the current user using the application as this will all be sitting on our domain. The app.config is as follows</p>
  
  <pre><code>    &lt;system.serviceModel&gt;
      &lt;bindings&gt;
          &lt;basicHttpBinding&gt;
              &lt;binding name="BasicHttpBinding_IDesktopService"&gt;
                &lt;security mode="TransportWithMessageCredential"&gt;
                  &lt;transport clientCredentialType="Windows" proxyCredentialType="Windows"/&gt;
                &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
          &lt;endpoint address="https://redwebservermanager.redweb.network/DesktopService.svc"
              binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDesktopService"
              contract="ManagerService.IDesktopService" name="BasicHttpBinding_IDesktopService" /&gt;
      &lt;/client&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>If I manually set the credentials username and password everything works correctly however I have been trying</p>
  
  <pre><code>managerService.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials
  </code></pre>
  
  <p>so that I can pass the current users credentials over but I keep getting an error on the call to GetClients() that the username and password is not set.</p>
  
  <p>Can anyone help me? I also tried adding </p>
  
  <pre><code>[OperationBehavior(Impersonation = ImpersonationOption.Required)]
  </code></pre>
  
  <p>to the method but this made no difference.</p>