<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">DistributedWorld</title><subtitle type="html" /><id>http://blogs.msdn.com/b/distributedworld/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/distributedworld/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/distributedworld/atom.aspx" /><generator uri="http://telligent.com" version="5.6.50428.7875">Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><updated>2012-04-24T11:47:00Z</updated><entry><title>AppFabric : Why is my local cache expiring too soon???</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/distributedworld/archive/2013/02/14/appfabric-why-is-my-local-cache-expiring-too-soon.aspx" /><id>http://blogs.msdn.com/b/distributedworld/archive/2013/02/14/appfabric-why-is-my-local-cache-expiring-too-soon.aspx</id><published>2013-02-14T10:37:00Z</published><updated>2013-02-14T10:37:00Z</updated><content type="html">&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Windows Server AppFabric 1.0 (or Microsoft AppFabric for Windows Server as 1.1 is now called) provides feature to enable &lt;a href="http://msdn.microsoft.com/en-us/library/hh334204(v=azure.10).aspx"&gt;local caching&lt;/a&gt; for enhanced performance. There can be a situation when AppFabric client could start deleting local cache much before expected (that is before configured Timeout, or Notification). One of the reasons of this could be if virtual bytes (total of virtual address space memory actually used by process) of client process touches 85% of RAM on machine.&lt;/p&gt;
&lt;p&gt;To check if you are running into this situation, enable &amp;lsquo;Virtual Bytes Peak&amp;rsquo; performance counter on AppFabric client process and graph it against total Physical Memory on client machine. If web application is your AppFabric client, the client process would be worker process (w3wp.exe) corresponding to its application pool.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51-metablogapi/6064.image_5F00_68D06A1C.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51-metablogapi/6038.image_5F00_thumb_5F00_4E23CE03.png" alt="image" width="507" height="392" border="0" /&gt;&amp;nbsp;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10393636" width="1" height="1"&gt;</content><author><name>nishantks</name><uri>http://blogs.msdn.com/nish_5F00_singh77_4000_hotmail.com/ProfileUrlRedirect.ashx</uri></author><category term="Appfabric local cache" scheme="http://blogs.msdn.com/b/distributedworld/archive/tags/Appfabric+local+cache/" /></entry><entry><title>WCF on TCP : Keep your connections alive</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/distributedworld/archive/2012/06/15/wcf-on-tcp-keep-your-connections-alive.aspx" /><id>http://blogs.msdn.com/b/distributedworld/archive/2012/06/15/wcf-on-tcp-keep-your-connections-alive.aspx</id><published>2012-06-15T08:15:46Z</published><updated>2012-06-15T08:15:46Z</updated><content type="html">&lt;p&gt;I recently had a customer coming in with question and request on WCF connection pooling, which is very valid. I was almost convinced that answer to his question would be 'by design' but what worried me was if there is a solution for his predicament. To my pleasant surprise, mighty WCF team did think about the scenario and 'by design' there was a solution to his exact problem.&lt;/p&gt;  &lt;p&gt;He is using net.tcp port sharing on the server for two different WCF services configured with net.tcp binding. The client code is such that proxy is created every time, service called and proxy closed. This sequence could be done for two services in any required combinations, lets say by calling Service 1() and Service2(). If Service1() is called repeatedly, TCP connection created in first call is pooled and reused. This is nice and as expected to save on connection establishment costs every time. But as soon as Service2() is called, TCP connection used for Service1() is reset. This sounds inappropriate. Seems, cost of port sharing is that pooled connection for Service1 has to be replaced with new connection to Service2. Very inefficient in an enterprise scenario where client makes random calls to Service1 and Service2 in volume as connection will be reset each time.&lt;/p&gt;  &lt;p&gt;Whoever plays with TCP connection pooling is almost certain to stumble upon this: &lt;a href="http://kennyw.com/work/indigo/173"&gt;http://kennyw.com/work/indigo/173&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Solution to my customer's predicament lies in this line taken from above link &amp;quot;&lt;em&gt;Our connection pool is configurable through &lt;/em&gt;&lt;a href="http://blogs.msdn.com/drnick/archive/2006/07/06/657619.aspx"&gt;&lt;em&gt;TcpConnectionPoolSettings/NamedPipeConnectionPoolSettings&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. These settings include a GroupName that we use for isolation&lt;/em&gt;&amp;quot;&lt;/p&gt;  &lt;p&gt;You may think of it like this. TCP connection pool in WCF is identified with 'Port Number' and 'GroupName' (possibly more but only these are relevant for our purpose). If you omit 'GroupName', WCF provides a default. If you are not explicitly providing '&lt;a href="http://msdn.microsoft.com/en-us/library/ms731366.aspx"&gt;connectioPoolSettings&lt;/a&gt;', you are in effect omitting 'GroupName'. Since both the endpoints (for Service1 and Service2) use same port and have same 'GroupName' (Default), implies both endpoints will use same connection pool Id. When Service2 needs to be reached, its connection pool is already in place at client side but WCF infrastructure need to reset the connection to same port.&lt;/p&gt;  &lt;p&gt;Use 'GroupName' to isolate connection pools for two endpoints and you can have connections alive when switching from Service1 to Service2 in there own respective pools. &lt;/p&gt;  &lt;p&gt;This does mean that you will need to resort to custom binding but that’s an acceptable cost for such a huge benefit. A typical client config to achieve desired behaviour with net.tcp transport will look like this:&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.47%; height: 320px; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;xml&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;version&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;encoding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; ?&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;configuration&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;bindings&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;customBinding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt; = &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;quot;bindingA&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;tcpTransport&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;connectionPoolSettings&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;groupName&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;connectionPoolA&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;tcpTransport&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;bindingB&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;tcpTransport&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;connectionPoolSettings&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;groupName&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;connectionPoolB&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;tcpTransport&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;customBinding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;bindings&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;client&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;endpoint&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;address&lt;/span&gt;=&amp;quot;&lt;span style="color: rgb(255, 0, 0);"&gt;net&lt;/span&gt;.&lt;span style="color: rgb(255, 0, 0);"&gt;tcp:&lt;/span&gt;//&amp;amp;&lt;span style="color: rgb(255, 0, 0);"&gt;lt&lt;/span&gt;;&lt;span style="color: rgb(255, 0, 0);"&gt;hostname&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;/&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;APPLICATION-A&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;/Service.svc&amp;quot;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; binding=&amp;quot;customBinding&amp;quot; bindingConfiguration=&amp;quot;bindingA&amp;quot;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; contract=&amp;quot;WCF1.IService&amp;quot; name=&amp;quot;NetTcpBinding_IService_A&amp;quot;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;endpoint&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;endpoint&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;address&lt;/span&gt;=&amp;quot;&lt;span style="color: rgb(255, 0, 0);"&gt;net&lt;/span&gt;.&lt;span style="color: rgb(255, 0, 0);"&gt;tcp:&lt;/span&gt;//&amp;amp;&lt;span style="color: rgb(255, 0, 0);"&gt;lt&lt;/span&gt;;&lt;span style="color: rgb(255, 0, 0);"&gt;hostname&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;/&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;APPLICATION-B&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;/Service.svc&amp;quot;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; binding=&amp;quot;customBinding&amp;quot; bindingConfiguration=&amp;quot;bindingB&amp;quot;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; contract=&amp;quot;WCF2.IService&amp;quot; name=&amp;quot;NetTcpBinding_IService_B&amp;quot;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;endpoint&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;client&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&amp;#160; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;configuration&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10320382" width="1" height="1"&gt;</content><author><name>nishantks</name><uri>http://blogs.msdn.com/nish_5F00_singh77_4000_hotmail.com/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Identity delegation in WCF</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/distributedworld/archive/2012/05/24/identity-delegation-in-wcf.aspx" /><id>http://blogs.msdn.com/b/distributedworld/archive/2012/05/24/identity-delegation-in-wcf.aspx</id><published>2012-05-24T10:01:00Z</published><updated>2012-05-24T10:01:00Z</updated><content type="html">&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Further to my earlier post in an attempt to demystify Kerberos and IIS hosted WCF service (&lt;a title="http://blogs.msdn.com/b/distributedworld/archive/2012/04/24/troubleshoot-kerberos-in-wcf.aspx" href="http://blogs.msdn.com/b/distributedworld/archive/2012/04/24/troubleshoot-kerberos-in-wcf.aspx"&gt;http://blogs.msdn.com/b/distributedworld/archive/2012/04/24/troubleshoot-kerberos-in-wcf.aspx&lt;/a&gt;) , I realized that successful delegation of client credentials to back end service/DB is also a common scenario and hence this short post. From WCF perspective, there are only three things to be done to successfully delegate client credentials :&lt;/p&gt;
&lt;p&gt;1. First and foremost, client should allow itself to delegate. In WCF, this can be done by setting allowedImpersonationLevel="Delegation" on client side endpoint behavior&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: 'Courier New', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;"&gt;
&lt;div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;clientCredentials&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"&gt;       &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;windows&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;allowedImpersonationLevel&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="Delegation"&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;clientCredentials&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;2. Second, service should be impersonating client. It could either be done in Declarative or Imperative manner per operation. You can get more details here : &lt;a href="http://msdn.microsoft.com/en-us/library/ms730088.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms730088.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;3. Third, and this is important and what often confuses users. The AD (Active Directory) object used to authenticate server/service should be trusted for Delegation. Essentially, what you need to figure out is if its 'Server' or 'Service' authentication, which is used in your scenario, which in turn is consequence of combination of 'useAppPoolCredentials', 'Kernel authentication' and 'Explicit service identity' (The table in my previous blog may come handy to find this out).&lt;/p&gt;
&lt;p&gt;So for example, if your middle tier used Kernel authentication with useAppPoolCredentials="false", the middle tier server should be trusted for delegation (irrespective of Identity middle tier service is running as). On the other hand, if you did a 'Service' authentication with custom identity, that specific identity should be trusted for delegation (you will need to create a SPN for that identity in order to enable 'Delegation' tab in AD)&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51-metablogapi/4621.clip_5F00_image001_5F00_006323E7.png"&gt;&lt;img style="border: 0px currentcolor; padding-top: 0px; padding-right: 0px; padding-left: 0px; display: inline; background-image: none;" title="clip_image001" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51-metablogapi/4606.clip_5F00_image001_5F00_thumb_5F00_342B1A38.png" alt="clip_image001" width="244" height="213" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;Edit&amp;gt; I would like to add a 4th point here. Remember that backend WCF service's client is middle tier and this client will also want the service (backend) to authenticate itself. Same principles of Kerberos authentication apply here and easiest way around this is to provide backend WCF service identity a SPN (say "MyBackendSvc/MyBackendBox") and specify same in backend service and middle tier config&lt;/p&gt;
&lt;div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: 'Courier New', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;"&gt;
&lt;div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;endpoint..&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"&gt;    &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;identity&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;        &lt;span style="color: #0000ff;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000;"&gt;servicePrincipalName&lt;/span&gt; &lt;span style="color: #ff0000;"&gt;value&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;="MyBackendSvc/MyBackendBox"&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"&gt;    &lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;identity&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: #0000ff;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #800000;"&gt;endpoint&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Some useful tips:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;All in previous post (like klist purge) are still useful : &lt;a title="http://blogs.msdn.com/b/distributedworld/archive/2012/04/24/troubleshoot-kerberos-in-wcf.aspx" href="http://blogs.msdn.com/b/distributedworld/archive/2012/04/24/troubleshoot-kerberos-in-wcf.aspx"&gt;http://blogs.msdn.com/b/distributedworld/archive/2012/04/24/troubleshoot-kerberos-in-wcf.aspx&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Following two properties to discover current process identity and caller identity come very handy while troubleshooting Identity issues.&lt;/li&gt;
&lt;/ol&gt;
&lt;div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: 'Courier New', courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: #f4f4f4;"&gt;
&lt;div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span id="lnum1" style="color: #606060;"&gt; 1:&lt;/span&gt; &lt;span style="color: #008000;"&gt;// This is current process identity (will be same as caller if impersonating)&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"&gt;&lt;span id="lnum2" style="color: #606060;"&gt; 2:&lt;/span&gt; String user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span id="lnum3" style="color: #606060;"&gt; 3:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: #f4f4f4;"&gt;&lt;span id="lnum4" style="color: #606060;"&gt; 4:&lt;/span&gt; &lt;span style="color: #008000;"&gt;// This is caller's identity&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: 'Courier New', courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span id="lnum5" style="color: #606060;"&gt; 5:&lt;/span&gt; WindowsIdentity callerWinIdentity = ServiceSecurityContext.Current.WindowsIdentity;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10309811" width="1" height="1"&gt;</content><author><name>nishantks</name><uri>http://blogs.msdn.com/nish_5F00_singh77_4000_hotmail.com/ProfileUrlRedirect.ashx</uri></author><category term="WCF delegation" scheme="http://blogs.msdn.com/b/distributedworld/archive/tags/WCF+delegation/" /></entry><entry><title>Kerberos and IIS hosted WCF : 'useAppPoolCredentials', 'Kernel mode authentication' and 'etc.'</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/distributedworld/archive/2012/04/24/troubleshoot-kerberos-in-wcf.aspx" /><id>http://blogs.msdn.com/b/distributedworld/archive/2012/04/24/troubleshoot-kerberos-in-wcf.aspx</id><published>2012-04-24T10:47:00Z</published><updated>2012-04-24T10:47:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Having invested quite a deal of time in troubleshooting a WCF authentication issue this week, I thought of sharing the experience, as this can perhaps save some man hours in the future. Though&amp;#160; I worked my way through multiple issues in course of this exercie, but at a higher level, this post can come handy if you are investigating an authentication failure of the type below of a WCF service hosted in IIS, with windows authentication enabled:&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;em&gt;System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate, NTLM'&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Or &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;If you are trying to get your service being authenticated as a custom domain identity. &lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;I also hope for this post to provide some directions to go around troubleshooting WCF authentication related issue in general as this is what I ended up doing in spirit.&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: large; text-decoration: underline;"&gt;&lt;strong&gt;&lt;span size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;Goal:&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Aim of my exercise is to successfully use Integrated Windows Authentication (Kerberos and not NTLM) for the custom identity account under which the service is running. Why Kerberos and not NTLM?? In my case, I want to delegate client credentials from the middle tier WCF service to the backend Database and this is only possible with Kerberos (NTLM does not support delegation of credentials)&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;It’s worth mentioning that IIS 7 onwards, kernel mode authentication is enabled by default in IIS. Though Microsoft recommends this to remain enabled for reasons of performance and avoiding authentication related issues, there may be situations where someone really wants to authenticate against the custom identity and not the machine account and do it outside of Kernel mode (I was doing it to mimic IIS 6 days where kernel mode authentication was not an option). IIS 7 onwards, you can configure ‘Kernel-mode authentication’ under 'Advanced Settings' after enabling 'Windows Authentication' authentication type (Authentication feature of IIS, available at the server, site and application level)&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51/1524.pic1.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51/1524.pic1.jpg" width="353" height="237" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;span style="font-size: large; text-decoration: underline;"&gt;&lt;strong&gt;&lt;span size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;Environment &amp;amp; Setup&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;I have a very simple WCF service configured with a single contract, basicHttpBinding and chose security mode 'TransportCredentialOnly' so as to avoid mixing it up with SSL and learning too much too soon. This is the relevant part of my service's web config :&lt;/span&gt;&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&amp;#160;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;bindings&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;basicHttpBinding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;binding1&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;security&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;mode&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;TransportCredentialOnly&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;transport&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;clientCredentialType&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;Windows&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;transport&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;security&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;binding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;basicHttpBinding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;bindings&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;    &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;services&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;service&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;MyService&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;Behavior&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;endpoint&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;endpoint1&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;binding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;basicHttpBinding&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;binding1&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;contract&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;MyContract&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;identity&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;            &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;servicePrincipalName&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;MyService/MyMachine&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;          &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;identity&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;        &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;endpoint&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;      &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;service&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;    &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;services&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;The service is hosted in IIS 7.5 (Windows 2008 R2) and running as identity 'EMEADS\SvcOwner'&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;If SPN in above config amazes you, with WCF client and service, you are free to venture out of SPN naming conventions (so forget about Service class, port etc.)&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;I find this MSDN magazine article quite useful to understand SPNs in general as well as wrt WCF : &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163570.aspx"&gt;&lt;span style="color: rgb(0, 0, 255); font-size: small;" size="3" color="#0000ff"&gt;http://msdn.microsoft.com/en-us/magazine/cc163570.aspx&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;This is how I set the SPN for my service:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;span style="font-size: small;" size="3"&gt;setspn -a MyService/MyMachine EMEADS\SvcOwner &lt;/span&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: large;"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: large;"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;Action time:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;I disabled all other authentication schemes, keeping Windows Authentication only in IIS, right from the server level down through web site and up to my WCF application. I also disabled Kernel mode authentication at all levels under 'Advance Settings' for 'Windows Authentication'.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: calibri; font-size: small;" size="3" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51/0336.pic1.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51/0336.pic1.jpg" width="394" height="152" /&gt;&lt;/a&gt;&amp;#160;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: calibri; font-size: small;" size="3" face="Calibri"&gt;&lt;/span&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: calibri; font-size: small;" size="3" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51/6165.pic1.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-52-51/6165.pic1.jpg" width="371" height="221" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: calibri; font-size: small;" size="3" face="Calibri"&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;With SPN in place, I was all set to get pass the authentication when inevitable happened : &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;span style="font-family: calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;#160;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;Unhandled Exception: System.ServiceModel.Security.MessageSecurityException: The &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;HTTP request is unauthorized with client authentication scheme 'Negotiate'. The &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;authentication header received from the server was 'Negotiate oWwwaqADCgEBomMEYW&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;BfBgkqhkiG9xIBAgIDAH5QME6gAwIBBaEDAgEepBEYDzIwMTIwNDIwMDkzODU4WqUFAgMOUo6mAwIBKa&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;kOGwxFTUVBRFMuTE9DQUyqEzARoAMCAQGhCjAIGwZua3NuMiQ='. ---&amp;gt; System.Net.WebExceptio&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;n: The remote server returned an error: (401) Unauthorized. ---&amp;gt; System.Componen&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;tModel.Win32Exception: The target principal name is incorrect&lt;/span&gt;&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;#160;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: large;"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;Troubleshooting:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Win32Exception inner exception message often helps to indicate what is wrong here. &amp;quot;&lt;em&gt;The target principal name is incorrect&lt;/em&gt;&amp;quot; suggest an issue with service Identity (SPN in this case). (For a quick experiment, I disabled the Active Directory account under which my client is running and though WCF MessageSecurityException remained same but inner Win32Exception message changed to &amp;quot;&lt;em&gt;The logon attempt failed&lt;/em&gt;&amp;quot;. Self-explanatory)&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;With the 'AllowNtlm’ property of WindowsClientCredentials set to ‘false’ (note: This property is now marked as obsolete-local machine policy should be used instead: &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.security.windowsclientcredential.allowntlm.aspx"&gt;&lt;span style="color: rgb(0, 0, 255); font-size: small;" size="3" color="#0000ff"&gt;http://msdn.microsoft.com/en-us/library/system.servicemodel.security.windowsclientcredential.allowntlm.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt; ) and 'Negotiate' provider enabled on WCF app, I knew I am troubleshooting Kerberos already. The first troubleshooting step was to enable Kerberos logging on my client box: &lt;/span&gt;&lt;a href="http://support.microsoft.com/kb/262177"&gt;&lt;span style="color: rgb(0, 0, 255); font-size: small;" size="3" color="#0000ff"&gt;http://support.microsoft.com/kb/262177&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Reproducing the issue again, the following event was logged in the System event log:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;-Log Name:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System 
      &lt;br /&gt;Source:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Microsoft-Windows-Security-Kerberos 

      &lt;br /&gt;Date:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 20/04/2012 12:03:31 

      &lt;br /&gt;Event ID:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 3 

      &lt;br /&gt;Task Category: None 

      &lt;br /&gt;Level:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Error 

      &lt;br /&gt;Keywords:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Classic 

      &lt;br /&gt;User:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; N/A 

      &lt;br /&gt;Computer:&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; NKSN1.EMEADS.local 

      &lt;br /&gt;Description: 

      &lt;br /&gt;A Kerberos Error Message was received: 

      &lt;br /&gt;on logon session 

      &lt;br /&gt; Client Time: 

      &lt;br /&gt; Server Time: 11:3:31.0000 4/20/2012 Z 

      &lt;br /&gt;Error Code: 0x29 KRB_AP_ERR_MODIFIED 

      &lt;br /&gt;Extended Error: 

      &lt;br /&gt; Client Realm: 

      &lt;br /&gt; Client Name: 

      &lt;br /&gt; Server Realm: EMEADS.LOCAL 

      &lt;br /&gt;Server Name: nksn2$ 

      &lt;br /&gt;Target Name: 

      &lt;br /&gt; Error Text: 

      &lt;br /&gt; File: 3 

      &lt;br /&gt;Line: 576 

      &lt;br /&gt;Error Data is in record data.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;At this time, I noticed, even when my Kerberos logging was not enabled, there were these events in event log from earlier attempts of troubleshooting:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;span style="font-family: calibri; font-size: x-small;" size="3" face="Calibri"&gt;Kerberos event 4 : 
      &lt;br /&gt;The Kerberos client received a KRB_AP_ERR_MODIFIED error from the server nksn2$. The target name used was HTTP/nksn2.emeads.local. This indicates that the target server failed to decrypt the ticket provided by the client. This can occur when the target server principal name (SPN) is registered on an account other than the account the target service is using. Please ensure that the target SPN is registered on, and only registered on, the account used by the server. This error can also happen when the target service is using a different password for the target service account than what the Kerberos Key Distribution Center (KDC) has for the target service account. Please ensure that the service on the 

      &lt;br /&gt;server and the KDC are both updated to use the current password. If the server name is not fully qualified, and the target domain (EMEADS.LOCAL) is different from the client domain (EMEADS.LOCAL), check if there are identically named server accounts in these two domains, or use the fully-qualified name to identify the server.&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;That was quite a wealth of info to give me directions. &lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;setspn –X’ is the easiest way to trace duplicate SPNs ('duplicate SPN' is when the same SPN gets assigned to more than one accounts. 'Duplicate SPNs' is just one possible SPN related issue. Go through link in 'References' section below for complete SPN checklist for Kerberos). For some reason, I used an old school way to find which account(s) is (are) using this SPN: &lt;/span&gt;&lt;a href="http://technet.microsoft.com/en-us/library/cc772897(v=WS.10).aspx"&gt;&lt;span style="color: rgb(0, 0, 255); font-size: small;" size="3" color="#0000ff"&gt;http://technet.microsoft.com/en-us/library/cc772897(v=WS.10).aspx&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;And I got this output from the LDP tool:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;***Searching...&lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;ldap_search_s(ld, &amp;quot;DC=EMEADS,DC=local&amp;quot;, 2, &amp;quot;serviceprincipalname=MyService/MyMachine&amp;quot;, attrList,&amp;#160; 0, &amp;amp;msg)&lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;Getting 2 entries:&lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;Dn: CN=SvcOwner,CN=Users,DC=EMEADS,DC=local&lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;canonicalName: EMEADS.local/Users/svcowner; &lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small; background-color: rgb(255, 255, 0);"&gt;&lt;em&gt;name: SvcOwner; &lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;objectClass (4): top; person; organizationalPerson; user;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;Dn: CN=iismanaged,CN=Managed Service Accounts,DC=EMEADS,DC=local&lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;canonicalName: EMEADS.local/Managed Service Accounts/iismanaged; &lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small; background-color: rgb(255, 255, 0);"&gt;&lt;em&gt;name: iismanaged; &lt;/em&gt;&lt;/span&gt;

  &lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;objectClass (4): top; person; organizationalPerson; user;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;This confirms that duplicate SPNs are getting in my path. To start from a clean slate, I to deleted both the SPNs and created a new one, only for the custom identity the WCF service is running as (you need to be a domain administrator to run this):&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Delete both SPNs:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;em&gt;setspn -d MyService/MyMachine emeads\iismanaged&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;em&gt;setspn -d MyService/MyMachine emeads\svcowner&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Create the SPN as I want it to be (for domain idenity under which the service is running)&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;em&gt;setspn -a MyService/MyMachine emeads\svcowner&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;I thought I am close. Another run and again :&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;Unhandled Exception: System.ServiceModel.Security.MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate oWwwaqADCgEBomMEYW BfBgkqhkiG9xIBAgIDAH5QME6gAwIBBaEDAgEepBEYDzIwMTIwNDIwMDkzODU4WqUFAgMOUo6mAwIBKakOGwxFTUVBRFMuTE9DQUyqEzARoAMCAQGhCjAIGwZua3NuMiQ='. ---&amp;gt; System.Net.WebException: The remote server returned an error: (401) Unauthorized. ---&amp;gt; System.ComponentModel.Win32Exception: The target principal name is incorrect&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Well, remember your client system caches SPNs for target identity, hence always run 'klist purge' after any SPN changes. Unfortunately, in my case, even 'klist purge' is of no consequence and I still run into the same exception. Perhaps because I was playing around with 'useAppPoolCredentials' setting in applicationHost.config: &lt;/span&gt;&lt;a href="http://technet.microsoft.com/en-us/library/dd759186.aspx"&gt;&lt;span style="color: rgb(0, 0, 255); font-family: times new roman; font-size: small;" size="3" face="Times New Roman" color="#0000ff"&gt;http://technet.microsoft.com/en-us/library/dd759186.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: times new roman;" face="Times New Roman"&gt; &lt;/span&gt;. I reverted everything to default on IIS (useAppPoolCredentials = false) and did an iisreset. The WCF client successfully negotiated credentials with service now and all is well. &lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;Now is the time to demystify links between 'kernel mode authentication’, 'useAppPoolCredentials' and 'service SPN identity'.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;After investing another great deal with various experiments and readings, these are the scenarios and respective implications:&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;span style="text-decoration: underline;"&gt;Scenario 1&lt;/span&gt;. useAppPoolCredentials=false&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;font size="2"&gt;&lt;span style="text-decoration: underline;"&gt;1a&lt;/span&gt;. Kernel mode disabled. Client explicitly specifies service SPN Identity (Service identity can be of various types like Certificate, UPN etc) :&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;client&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;endpoint....&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;identity&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;servicePrincipalName&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;value&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;MyService/MyMachine&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;identity&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;  &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;endpoint&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;client&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;font size="2"&gt;This succeeds with custom Identity credentials. But as already warned, this is non-performant as Kernel is not handling authentication&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;font size="2"&gt;&lt;/font&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;font size="2"&gt;&lt;span style="text-decoration: underline;"&gt;1b&lt;/span&gt;. Kernel mode enabled. Client explicitly specifies SPN Identity as above. As expected, authentication fails since the server is expecting host/http SPN.&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;font size="2"&gt;&lt;/font&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;font size="2"&gt;&lt;span style="text-decoration: underline;"&gt;1c&lt;/span&gt;. Kernel mode enabled. Client does not specify service SPN Identity. Authentication succeeds but with default host/http SPN. This is what we always recommend. Performant and (almost) no authetication issues.&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;span style="text-decoration: underline;"&gt;Scenario 2&lt;/span&gt;. useAppPoolCredentials=true&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;font size="2"&gt;&lt;span style="text-decoration: underline;"&gt;2a&lt;/span&gt;. Kernel mode disabled. (With kernel mode disabled, useAppPoolCredentials is of no consequence as authentication is now onus of application host) Client explicitly specifies service SPN Identity. This succeeds with custom Identity credentials but non performant like 1a.&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;font size="2"&gt;&lt;/font&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;font size="2"&gt;&lt;span style="text-decoration: underline;"&gt;2b&lt;/span&gt;. Kernel mode enabled. Client explicitly specifies service SPN Identity. Authentication succeeds. Kernel authenticating against appPool identity. More performant and recommended for custom identity scenarios.&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;&lt;span style="font-family: segoe ui;" face="Segoe UI"&gt;&lt;span style="text-decoration: underline;"&gt;2c&lt;/span&gt;. Kernel mode enabled. Client does not specifies service SPN Identity. Authentication FAILS as client provided ticket for host/http SPN whereas Kernel mode authentication at server is configured to authenticate against appPool credentials.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;/span&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: arial black,avant garde;"&gt;Putting all of above in nice tabular form&lt;/span&gt;:&lt;/span&gt;&lt;/p&gt;

&lt;table style="width: 585px; height: 273px;" border="1" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="154"&gt;
        &lt;p align="center"&gt;&lt;b&gt;UseAppPoolCredentials&lt;/b&gt;&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p align="center"&gt;&lt;b&gt;Kernel-mode Authentication&lt;/b&gt;&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p align="center"&gt;&lt;b&gt;Client explicitly specify service SPN Identity&lt;/b&gt;&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p align="center"&gt;&lt;b&gt;Server/Service Authentication Result&lt;/b&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;False (default)&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Disabled&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Yes&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Succeeds (Service authenticated)&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;False (default)&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Enabled&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Yes&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Fails (as Server authentication is attempted)&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;False (default)&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Enabled&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;No&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Succeeds (Server authenticated)&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;True&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Disabled&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Yes&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Succeeds (Service authenticated)&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;True&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Enabled&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Yes&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Succeeds (Service authenticated)&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;True&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Enabled&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;No&lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="154"&gt;
        &lt;p&gt;Fails (as Server authentication is attempted)&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;&lt;/span&gt;&lt;/span&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-family: segoe ui;" face="Segoe UI"&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;The learning is that kernel mode authentication in IIS doesn't necessarily mean machine account. With 'useAppPoolCredentials=true', we are telling IIS to do kernel &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;mode authentication with AppPool identity account (and not machine account). To be 100% sure, I verified network traffic using Netmon 3.4 and indeed kerberos ticket was issued &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;for 'MyService/MyMachine' SPN and used successfully for service authentication with useAppPoolCredentials=true.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: medium; text-decoration: underline;"&gt;&lt;strong&gt;&lt;span size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;Some other tips:&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;- An easy way to rule out any SPN related issues is by running the service as ‘Network Services’ account where default host SPNs are used. That means, remove any ‘Identity’ related configs from client and service and test again.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;- &lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;When Kernel-mode authentication is used and useAppPoolCredentials=’false’ (default), server ticket will be issued and decrypted with machine account . In this case, server Identity will be inferred from service URI and not required to be explicitly mentioned in client or service config. Refer : &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/webtopics/archive/2009/01/19/service-principal-name-spn-checklist-for-kerberos-authentication-with-iis-7-0.aspx"&gt;&lt;span style="color: rgb(0, 0, 255); font-size: small;" size="3" color="#0000ff"&gt;http://blogs.msdn.com/b/webtopics/archive/2009/01/19/service-principal-name-spn-checklist-for-kerberos-authentication-with-iis-7-0.aspx&lt;/span&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;-Remember to 'klist purge' after any SPN related change&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;-if duplicate SPNs are such a hassle, why are they even permitted. I hope to get an answer to this soon and update the post.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;-For simple scenarios, your Authentication types should be coherent right from server to application level in IIS unless there are other considerations&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;-Remember to do iisreset after any change in applicationhost.config&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;How to force Kerberos with WCF:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;Binding should specify clientCredentialType=&amp;quot;Windows&amp;quot;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;If your service is hosted in IIS 7.5, there is a new authentication provider 'Negotiate:Kerberos', which doesn't fall back to NTLM&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span style="font-size: x-small;" size="2"&gt;How to force NTLM with WCF:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;Binding should specify clientCredentialType=&amp;quot;Ntlm&amp;quot;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: x-small;" size="2"&gt;WCF service host (IIS in most cases) should have NTLM as one of authentication provider in the list.&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="font-size: medium; text-decoration: underline;"&gt;&lt;strong&gt;&lt;span size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;References:&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;&lt;strong&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/b/asiatech/archive/2011/10/26/iis-7-kerberos-authentication-failure-krb-ap-err-modified.aspx"&gt;http://blogs.msdn.com/b/asiatech/archive/2011/10/26/iis-7-kerberos-authentication-failure-krb-ap-err-modified.aspx&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;&lt;strong&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: calibri;" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/b/friis/archive/2009/12/31/things-to-check-when-kerberos-authentication-fails-using-iis-ie.aspx?wa=wsignin1.0"&gt;http://blogs.msdn.com/b/friis/archive/2009/12/31/things-to-check-when-kerberos-authentication-fails-using-iis-ie.aspx?wa=wsignin1.0&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10297102" width="1" height="1"&gt;</content><author><name>nishantks</name><uri>http://blogs.msdn.com/nish_5F00_singh77_4000_hotmail.com/ProfileUrlRedirect.ashx</uri></author><category term="WCF kerberos SPN useAppPoolCredentials" scheme="http://blogs.msdn.com/b/distributedworld/archive/tags/WCF+kerberos+SPN+useAppPoolCredentials/" /></entry></feed>