title: Can not get User credentials using webhttpbinding for JSON calls to WCF Service
body: <p>Hope someone can help!</p>
  
  <p>I am calling a WCF service using JSON but I am not able to get the user credentials out.<br>
  We are using Kerberos so IIS is setup as the following:</p>
  
  <h2>Server-side tasks:</h2>
  
  <ol>
  <li>IIS server is member of domain</li>
  <li>Set IIS server computer account in AD Users &amp; Computers MMC as "Trusted for Delegation"</li>
  <li>IIS Server must be rebooted for this policy to take effect.</li>
  <li>Integrated Windows Authentication only must be selected for site / virtual directory</li>
  <li>IIS must not have NTLM only set as authentication method (this is usually not a problem, NEGOTIATE is default, so unless you specifically ran a script to change this, don't worry about it).</li>
  <li>IIS server name either must match exactly account name in AD, or SetSPN tool should be used in cases where IIS site is set as alternative name (e.g. server is called server01.domain.com, and website is called www.application.com).</li>
  </ol>
  
  <h2>Client-side tasks</h2>
  
  <ol>
  <li>Client must be using IE 5.x+. If client is running IE 6, ensure that "Enable Integrated Windows Authentication (requires restart)" is selected from Tools > Internet Options > Advanced.</li>
  <li>Web site MUST be recognized as Local Intranet (not Internet Zone) site to client. I have not seen any documentation explaining why, but I just have never been able to get it to work otherwise. If necessary, specifically add this to Local Intranet sites list.</li>
  <li>Client account must not be marked as "Sensitive, Do not Delegate" in AD Users and Computers MMC. </li>
  </ol>
  
  <p>Everything works nicely when using wsHTTPBinding. However to get JSON working I have to use WebHttpBinding.
  I then need to get the user credentials out so I can use impersonation to talk to the backend services.</p>
  
  <p>My binding in the WFC config is as below:
  I used <a href="http://underground.infovark.com/2008/03/21/wcf-webhttp-binding-and-authentication/" rel="nofollow noreferrer">http://underground.infovark.com/2008/03/21/wcf-webhttp-binding-and-authentication/</a>
  to help:</p>
  
  <pre><code>&lt;webHttpBinding&gt;
      &lt;binding name="AjaxBinding"&gt;
          &lt;security mode="None"&gt;
               &lt;transport clientCredentialType="Ntlm" /&gt;
           &lt;/security&gt;
       &lt;/binding&gt;
  &lt;/webHttpBinding&gt;
  
  &lt;endpoint name="DataJson" address="Datajson" binding="webHttpBinding" 
          bindingConfiguration="AjaxBinding" 
          behaviorConfiguration="jsonbehaviour" contract="MyContract"/&gt;
  
  &lt;behavior name="jsonbehaviour"&gt;
       &lt;!--&lt;webHttp/&gt;--&gt;
       &lt;enableWebScript/&gt;
  &lt;/behavior&gt;
  </code></pre>
  
  <p>It is calling the WCF service successfully but I am unable to get anything from: <code>HttpContext.Current.User.Identity</code> or <code>ServiceSecurityContext.Current.WindowsIdentity</code> other than anonymous so I am unable to do:</p>
  
  <pre><code>WindowsIdentity identity = (WindowsIdentity)HttpContext.Current.User.Identity();
  
  using (identity.Impersonate())
  {
      // ... code to call application B goes here ...
  }
  </code></pre>
  
  <p>I have tried adding this into the web.config in case of multiple identities that I read about:</p>
  
  <pre><code>              &lt;deny users="?"/&gt;
  </code></pre>
  
  <p>Any ideas anyone?</p>