title: Passing windows identity to WCF from ASP.NET
body: <p>I have a WCF service hosted in IIS with integrated windows authentication enabled and anonymous authentication disabled. When I try and call this service from ASP.NET, I'm getting the following MessageSecurityException:</p>
  
  <p>"The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate,NTLM'.]"</p>
  
  <p>Any ideas?</p>
  
  <p>This is my service configuration:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="CalculatorServiceBasicHttpBinding"&gt;
        &lt;security mode="TransportCredentialOnly"&gt;
          &lt;transport clientCredentialType="Windows" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;services&gt;
    &lt;service name="Service.CalculatorService" 
             behaviorConfiguration="CalculatorServiceBehavior"&gt;
      &lt;endpoint name="BasicHttpEndpoint"
                address="" 
                binding="basicHttpBinding" 
                bindingConfiguration="CalculatorServiceBasicHttpBinding"
                contract="Framework.ICalculatorService"&gt;
      &lt;/endpoint&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="CalculatorServiceBehavior"&gt;
        &lt;serviceMetadata httpGetEnabled="true"/&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>This is how I'm calling the service:</p>
  
  <pre><code>var basicHttpBinding = new BasicHttpBinding();
  basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
  basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
  var factory = new ChannelFactory&lt;Framework.ICalculatorService&gt;(basicHttpBinding, new EndpointAddress("http://localhost/CalculatorService/CalculatorService.svc")); 
  factory.Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
  var proxy = factory.CreateChannel();
  var emailAddress = proxy.GetMyEmailAddress();
  ((ICommunicationObject)proxy).Close();
  factory.Close();
  </code></pre>