title: The server has rejected the client credentials, WCF as Windows Service
body: <p>I am able to connect to my WCF service with the Win-form application, however i am not able to do so with my windows service. Whenever i fire open() to the proxy it throws the following error</p>
  
  <blockquote>
    <p>The server has rejected the client credentials</p>
    
    <p>Inner Exception: System.Security.Authentication.InvalidCredentialException: The server
    has rejected the client credentials.<br>
    ---> System.ComponentModel.Win32Exception: The logon attempt failed<br>
    --- End of inner exception stack trace ---<br>
    at System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResult
    lazyResult)<br>
    at System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential
    credential, ChannelBinding binding, String targetName, ProtectionLevel
    requiredProtectionLevel, TokenImpersonationLevel
    allowedImpersonationLevel)<br>
    at System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential
    credential, String targetName, ProtectionLevel
    requiredProtectionLevel, TokenImpersonationLevel
    allowedImpersonationLevel)<br>
    at System.ServiceModel.Channels.WindowsStreamSecurityUpgradeProvider.WindowsStreamSecurityUpgradeInitiator.OnInitiateUpgrade(Stream
    stream, SecurityMessageProperty&amp; remoteSecurity)</p>
  </blockquote>
  
  <p>Tried searching for the solution, but none fitting my requirements, hence posted.</p>
  
  <p>Please help...</p>
  
  <p><strong>Update 1:</strong> </p>
  
  <p>@A.R., Tried using </p>
  
  <pre><code>client.ClientCredentials.Windows.AllowedImpersonationLevel =
      System.Security.Principal.TokenImpersonationLevel.Impersonation;
  </code></pre>
  
  <p>but to no avail.</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>WCF service Configuration</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;diagnostics performanceCounters="All" /&gt;
      &lt;bindings&gt;
        &lt;netTcpBinding&gt;
          &lt;binding name="myBindingForLargeData" maxReceivedMessageSize="5242880" maxConnections="10"&gt;
            &lt;readerQuotas maxDepth="64" maxStringContentLength="5242880" maxArrayLength="16384"
                          maxBytesPerRead="4096" maxNameTableCharCount="16384"/&gt;
          &lt;/binding&gt;
        &lt;/netTcpBinding&gt;
      &lt;/bindings&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="WCFService.ServiceBehavior"
          name="WCFService.CollectorService"&gt;
          &lt;endpoint address="" binding="netTcpBinding" bindingConfiguration="myBindingForLargeData"
            name="netTcpEndPoint" contract="WCFService.ICollectorService" /&gt;
          &lt;endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
            name="mexTcpEndPoint" contract="IMetadataExchange" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="net.tcp://localhost:8010/WCFService.CollectorService/" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="WCFService.ServiceBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="False"/&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="True" /&gt;
            &lt;serviceThrottling
            maxConcurrentCalls="32"
            maxConcurrentSessions="32"
            maxConcurrentInstances="32"
             /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>