{"id":699,"date":"2006-11-17T18:51:00","date_gmt":"2006-11-18T03:51:00","guid":{"rendered":"http:\/\/www.cloudidentity.com\/blog\/2006\/11\/17\/using-windows-cardspace-for-securing-a-wpf-smartclient-in-wcf-token-caching-sauce\/"},"modified":"2006-11-17T18:51:00","modified_gmt":"2006-11-18T03:51:00","slug":"using-windows-cardspace-for-securing-a-wpf-smartclient-in-wcf-token-caching-sauce","status":"publish","type":"post","link":"https:\/\/www.cloudidentity.com\/blog\/2006\/11\/17\/using-windows-cardspace-for-securing-a-wpf-smartclient-in-wcf-token-caching-sauce\/","title":{"rendered":"Using Windows CardSpace for securing a WPF smartclient, in WCF &amp; token caching sauce"},"content":{"rendered":"<p><P>Hello everybody.<\/P><br \/>\n<P>It&#8217;s some time that I have <A class=\"\" href=\"http:\/\/cardspace.netfx3.com\/files\/folders\/samples_rc_1\/entry7343.aspx\">this sample<\/A> in the buffer: I am publishing now in a rush, since this sundaly I leave for 2 weeks in EU for some nice CardSpace briefings here and there. I won&#8217;t be on mail very much, so I hope you will hold most questions for when I will be back in Redmond \ud83d\ude42<\/P><br \/>\n<P>I would really love to speak at lenght about this, but I really don&#8217;t have much time (I have also to mention all the ones that helped, and the list is long!:)). For the time being I am including an exerpt of <A class=\"\" href=\"http:\/\/cardspace.netfx3.com\/files\/folders\/samples_rc_1\/entry7343.aspx\">the sample documentation<\/A>: later I&#8217;ll go deeper on it.<\/P><br \/>\n<P>Enjoy \ud83d\ude42<\/P><br \/>\n<P>Vittorio<\/P><br \/>\n<P>&nbsp;<FONT face=\"Verdana\" size=\"5\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/FONT><\/P><br \/>\n<H2><EM><FONT face=\"Cambria\">Windows CardSpace, WCF and Token Caching<\/FONT><\/EM><\/H2><br \/>\n<P><br \/>\n<P class=\"SectionHeading\"><STRONG><FONT face=\"Verdana\"><\/FONT><\/STRONG><\/P><A class=\"\" title=\"_Toc116894262\" name=\"_Toc116894262\"><\/A><A class=\"\" title=\"_Toc112215655\" name=\"_Toc112215655\"><\/A><SPAN><FONT face=\"Verdana\" size=\"3\">Windows CardSpace provides a consistent experience across web and rich client scenarios. Windows Communication Foundation (WCF) supports CardSpace out of the box, supplying a powerful means of handling authentication in web service based applications: users enjoy an easy experience that shields them from the complexities of WS-Policy, while WCF receives a token for securing the messages. <\/FONT><\/SPAN><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The WCF programming model stores credentials on a per-channel basis: hence, in normal conditions the user would be prompted to choose a card as many times as a channel is created and used. WCF extensibility model, however, offers an easy way of modifying this behavior.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The sample presented here demonstrates how a simple WPF application can leverage CardSpace for securing the access to two different WCF web services, prompting the user only once.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"SectionHeading\"><SPAN><SPAN><STRONG><FONT face=\"Verdana\">Contents of this sample<\/FONT><\/STRONG><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">This sample contains the following components:<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">A sample certificate<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Installation scripts<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>The Simple WPF Smartclient solution<\/FONT><\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>A sample selfissued card<\/FONT><\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>This document<\/FONT><\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"SectionHeading\"><SPAN><SPAN><STRONG><FONT face=\"Verdana\">Certificate Setup<\/FONT><\/STRONG><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">This example does not require any website setup. The example requires, however, the installation of an X509 certificate. The configuration is done using the installation batch file provided in the sample folder:<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><BR><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>Install.bat<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">If you have troubles on Windows Vista, please install those certificates manually under the Local Machine store or refer to the documentation <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/aa967570.aspx\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>here<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">For more information and troubleshooting tips, consult the document <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">installation-instructions.doc<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> located in the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">documents<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> folder. Please note that this document provides help for a wide range of CardSpace examples, hence it sometimes refer to things (like websites setup) that do not apply to the sample here described.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P><B><SPAN><BR><\/SPAN><\/B>&nbsp;<\/P><br \/>\n<P class=\"SectionHeading\"><SPAN><SPAN><STRONG><FONT face=\"Verdana\">The Application<\/FONT><\/STRONG><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">The application is a WPF client which aggregates weather and traffic info on a simple map. It can be accessed by opening the solution <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>MeteoAndTraffic.sln<\/SPAN><FONT face=\"Verdana\"> in Visual Studio. Before examining the code, let\u2019s verify the intended behavior of the application: once you loaded the solution, start it by pressing F5. The screenshot below shows the application as it appears once it starts.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><FONT face=\"Verdana\" size=\"3\"><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT>&nbsp;<\/P><br \/>\n<P><IMG src=\"http:\/\/www.maseghepensu.it\/image002.gif\">&nbsp;<\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The user can click on the \u201cGet Traffic Info\u201d button for retrieving traffic <\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">information from a web service: the data will be displayed in the form of different colors on the road segments. The button \u201cGet Weather Info\u201d will contact a different web service, which will reply with weather information on the area. Both web services are offered by the same organization, nonetheless they are exposed on different endpoints.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">Both web services are secured by CardSpace, and configured for accepting the self issued card provided with the sample. The self issued card can be imported by double clicking on the file <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>SampleCardsPrimaCard.crds<\/SPAN><FONT face=\"Verdana\">: the password is \u201c88888888\u201d without the quotes.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Once the card has been imported, click on any of the two buttons mentioned above: the order is not important.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The system will open the identity selector, prompting for a self issued card. <\/FONT><\/SPAN><\/SPAN><\/P><IMG src=\"http:\/\/www.maseghepensu.it\/image004.gif\"><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Select the sample card \u201cPrima Card\u201d and hit Send: the identity selector will close and the application will perform the web service call.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Assuming that the button clicked was \u201cGet Weather Info\u201d, the application will show a scene similar to the following:<\/FONT><\/SPAN><\/SPAN><\/P><IMG src=\"http:\/\/www.maseghepensu.it\/image006.gif\"><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">At this point, all subsequent calls will not prompt the user again regardless of the service invoked. Pushing the \u201cGet Traffic Info\u201d button will update the visualization with traffic data right away, without showing the identity selector.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\"><\/FONT><\/SPAN><\/SPAN>&nbsp;<\/P><IMG src=\"http:\/\/www.maseghepensu.it\/image008.gif\"><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">If you want to be prompted again, it is enough to empty the token cache by pressing the \u201cFlush Token\u201d button: the next invocation will not find a suitable token in the cache, hence the user will be asked to select a card and restart the cycle.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Let\u2019s take a closer look at the code that made this behavior possible.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"SectionHeading\"><SPAN><SPAN><STRONG><FONT face=\"Verdana\">The client code<\/FONT><\/STRONG><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The client application is a simple Windows Presentation Foundation application: the visual components were created with Microsoft Expression Interactive Designer, then the project has been imported into Visual Studio 2005. The details of the WPF design are out of the scope of this document and won\u2019t be discussed here (refer to <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/blogs.msdn.com\/vbertocci\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>Vittorio\u2019s blog<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\"> for any question about it).<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">You can find the client project in the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">MeteoAndTraffic<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> solution, under the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">MeteoAndTraffic<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> project name. It contains the following files:<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">Application.xaml<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">Application.xaml.cs<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">AssemblyInfo.cs<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">App.config<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">MeteoServiceContract.cs<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">TrafficServiceContract.cs<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">Map.xaml<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">Map.xaml.cs<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">We can safely ignore <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">Application.xaml<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> , <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">Application.xaml.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> and <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">AssemblyInfo.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The file <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">App.config <\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">contains the typical WCF configuration which is necessary for invoking two endpoints with <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><FONT size=\"3\"><SPAN>wsHttpBinding <\/SPAN><FONT face=\"Verdana\">and CardSpace. If you are not familiar with the use of WCF and CardSpace, please refer to the <\/FONT><\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/windowssdk.msdn.microsoft.com\/en-us\/library\/ms731095.aspx\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>SDK documentation<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\"> or consider going through a <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/labs.netfx3.com\/\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>virtual lab<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">MeteoServiceContract.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> and <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">TrafficServiceContract.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> files contain the contract definitions of the weather and traffic web services, respectively. Again, please consult the documentation suggested above if those concepts are not clear.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">Map.xaml<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> contains WPF code defining the appearance of the main UI; <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">Map.xaml.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> contains the initialization code and the actual web service invocation code. Here there is an excerpt of <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">Map.xaml.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">:<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><I><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/I><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><FONT face=\"Lucida Console\">&#8230;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN>public<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN> MapScene()<\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN>{<\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>this<\/SPAN>.InitializeComponent();<\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN>}<\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN>&nbsp;<\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><FONT face=\"Lucida Console\"><SPAN><SPAN><SPAN>void<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN> BtnTrafficClicked(<SPAN>object<\/SPAN> sender, <SPAN>RoutedEventArgs<\/SPAN> e)<\/SPAN><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>try<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>ChannelFactory<\/SPAN>&lt;TrafficService.<SPAN>ITraffic<\/SPAN>&gt; cnFactory = <SPAN>new<\/SPAN> <\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>ChannelFactory<\/SPAN>&lt;TrafficService.<SPAN>ITraffic<\/SPAN>&gt;(<SPAN>&#8220;TrafficClient&#8221;<\/SPAN>);<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>TrafficService.<SPAN>ITraffic<\/SPAN> chn = cnFactory.CreateChannel();<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>List<\/SPAN>&lt;<SPAN>TrafficInfo<\/SPAN>&gt; ti = chn.GetTrafficInfo();<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>cnFactory.Close();<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>UpdateTrafficUI(ti);<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>catch<\/SPAN> (<SPAN>Exception<\/SPAN> ee)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>MessageBox<\/SPAN>.Show(<SPAN>&#8220;Something went wrong: nn&#8221;<\/SPAN> + ee.ToString());<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><FONT face=\"Lucida Console\">&#8230;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">That code fragment looks exactly like a usual WCF sample. Let\u2019s assume for a moment that the associated config file contains the usual WCF+CardSpace configuration, as described <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/msdn2.microsoft.com\/en-gb\/library\/ms751504.aspx\"><FONT color=\"#0033cc\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>here<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">In <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>BtnTrafficClicked<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><FONT face=\"Verdana\"><SPAN>,<\/SPAN> the event handler associated to the \u201cGet Traffic Info\u201d button, we:<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">1.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">Create a <\/FONT><\/SPAN><\/SPAN><FONT size=\"3\"><SPAN><SPAN><SPAN>ChannelFactory<\/SPAN><FONT face=\"Verdana\"> connected to the contract type (<\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>TrafficService.<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>ITraffic<\/SPAN><FONT face=\"Verdana\">) and endpoint associated to the service we want to invoke<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">2.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">Use the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><FONT size=\"3\"><SPAN>ChannelFactory<\/SPAN><FONT face=\"Verdana\"> for instantiating a proxy to the service<\/FONT><\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">3.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">Use the proxy for invoking the service and obtaining the data we need (in this case, a <\/FONT><\/SPAN><\/SPAN><FONT size=\"3\"><SPAN><SPAN><SPAN>List<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>&lt;<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>TrafficInfo<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>&gt;<\/SPAN><FONT face=\"Verdana\">)<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">4.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">Close the channel (via <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><FONT size=\"3\"><SPAN>ChannelFactory.Close()<\/SPAN><FONT face=\"Verdana\">) and use the data obtained for updating the UI<\/FONT><\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">From the description in the former section, we know that at a certain point during the execution of this code (namely in point 3 in the list above) the user has been prompted by the CardSpace UI. When the user selects one card, the system will obtain the corresponding security token (from the internal STS if a self issued card is selected, from an external identity provider in case of a managed card): this token will be stored in the channel and used to secure the call.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">If I would reuse the same channel instance for subsequent calls, WCF would use the token already stored in the channel cache and would not ask the user to re-select the card. Since we close the channel, however, the token cache is lost and subsequent clicks on the \u201cGet Traffic Info\u201d button would cause the CardSpace UI to show again. Unfortunately, just avoiding destroying the channel does not solve the problem. If the user would press the \u201cGet Weather Info\u201d we would execute <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>BtnMeteoClicked<\/SPAN><FONT face=\"Verdana\">: the code would be perfectly analogous to what we have described for <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>BtnTrafficClicked<\/SPAN><FONT face=\"Verdana\">. The problem is that the channel instance would be necessarily different from the one we created in <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>BtnTrafficClicked<\/SPAN><FONT face=\"Verdana\">, so WCF would have to populate the token cache of this new channel and in so doing it would again prompt the user for selecting a card.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Fortunately, the extensibility model of WCF allows modifying the above described behavior; furthermore, it is possible to implement our custom caching behavior without imposing any modification to the C# code. <\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">If you are interested in the details, please refer to the <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/windowssdk.msdn.microsoft.com\/en-us\/library\/ms733836.aspx\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>credential types explanation in the SDK documentation<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">; in this context, it is enough to say that the token caching logic is managed by the <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/windowssdk.msdn.microsoft.com\/en-us\/library\/ms553830.aspx\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>ClientCredentials<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\"> behavior. We can modify the way in which a channel handles credentials by replacing <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/windowssdk.msdn.microsoft.com\/en-us\/library\/ms553830.aspx\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>ClientCredentials<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\"> from its behaviors list with our own implementation. For doing that we need to <\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">1.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">Create our implementation of <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/windowssdk.msdn.microsoft.com\/en-us\/library\/ms553830.aspx\"><FONT size=\"3\"><FONT color=\"#800080\"><FONT face=\"Verdana\"><SPAN><SPAN>ClientCredentials<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">2.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">Change the configuration of the client so that it will take advantage of our class, as opposed to the <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/windowssdk.msdn.microsoft.com\/en-us\/library\/ms553830.aspx\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>ClientCredentials<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\"> implementation supplied by the framework <\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">In the remainder of this section we will explore 2., while in the next section we will get a closer look to the implementation details of our custom behavior.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Below you can see the first lines of the config file associated to our client:<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&lt;?<SPAN>xml<\/SPAN> <SPAN>version<\/SPAN>=&#8221;1.0&#8243; <SPAN>encoding<\/SPAN>=&#8221;utf-8&#8243; ?&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&lt;<SPAN>configuration<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp; <\/SPAN>&lt;<SPAN>system.serviceModel<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>extensions<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>behaviorExtensions<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>add<\/SPAN> <SPAN>name<\/SPAN>=&#8221;SimpleCardSpaceTokenClientCredentials&#8221; <SPAN>type<\/SPAN>=&#8221;SimpleCardSpaceTokenClientCredentialsSample.SimpleCardSpaceTokenClientCredentialsConfigHandler, SimpleCardSpaceTokenClientCredentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null&#8221; \/&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>behaviorExtensions<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>extensions<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">In those lines we declare a config handler for our custom <\/FONT><\/SPAN><\/SPAN><\/SPAN><A href=\"http:\/\/windowssdk.msdn.microsoft.com\/en-us\/library\/ms553830.aspx\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>ClientCredentials<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN> <\/SPAN><\/SPAN><SPAN><SPAN><SPAN>class. This basically tells to the system that:<\/SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT size=\"3\">\u00b7<\/FONT><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">There is a new behavior available, represented by the tag <\/FONT><\/SPAN><\/SPAN><\/SPAN><FONT><FONT face=\"Lucida Console\"><SPAN><SPAN><SPAN class=\"codeChar0\"><SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN><\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT size=\"3\">\u00b7<\/FONT><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The code for reading the configuration values is in the class <\/FONT><\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"codeChar0\"><SPAN><FONT face=\"Lucida Console\">SimpleCardSpaceTokenClientCredentialsSample.SimpleCardSpaceTokenClientCredentialsConfigHandler<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">, provided by the assembly <\/FONT><\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"codeChar0\"><SPAN><FONT face=\"Lucida Console\">SimpleCardSpaceTokenClientCredentials<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/SPAN><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN><SPAN>.<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN><SPAN>The next lines represent the endpoints recognized by the client application. <\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>client<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>endpoint<\/SPAN> <\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>name<\/SPAN>=&#8221;MeteoClient&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>address<\/SPAN>=&#8221;http:\/\/localhost:4127\/MeteoService\/MeteoEndpoint&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>contract<\/SPAN>=&#8221;MeteoService.IMeteo&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>binding<\/SPAN>=&#8221;wsHttpBinding&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>bindingConfiguration<\/SPAN>=&#8221;myBinding&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>behaviorConfiguration<\/SPAN>=&#8221;MyClientBehavior&#8221;&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>identity<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>certificateReference<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>findValue<\/SPAN>=&#8217;www.fabrikam.com&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>storeLocation<\/SPAN>=&#8217;LocalMachine&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>storeName<\/SPAN>=&#8217;My&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>x509FindType<\/SPAN>=&#8217;FindBySubjectName&#8217; \/&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>identity<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>endpoint<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>endpoint<\/SPAN> <\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>name<\/SPAN>=&#8221;TrafficClient&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>address<\/SPAN>=&#8221;http:\/\/localhost:4128\/TrafficService\/TrafficEndpoint&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>contract<\/SPAN>=&#8221;TrafficService.ITraffic&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>binding<\/SPAN>=&#8221;wsHttpBinding&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp; <\/SPAN><SPAN>bindingConfiguration<\/SPAN>=&#8221;myBinding&#8221;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>behaviorConfiguration<\/SPAN>=&#8221;MyClientBehavior&#8221;&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>identity<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>certificateReference<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN><SPAN>findValue<\/SPAN>=&#8217;www.fabrikam.com&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>storeLocation<\/SPAN>=&#8217;LocalMachine&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>storeName<\/SPAN>=&#8217;My&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>x509FindType<\/SPAN>=&#8217;FindBySubjectName&#8217; \/&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>identity<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>endpoint<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>client<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>bindings<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>wsHttpBinding<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>binding<\/SPAN> <SPAN>name<\/SPAN>=&#8221;myBinding&#8221;&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>security<\/SPAN> <SPAN>mode<\/SPAN>=&#8221;Message&#8221;&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>message<\/SPAN> <SPAN>clientCredentialType<\/SPAN>=&#8221;IssuedToken&#8221;\/&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>security<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>binding<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>wsHttpBinding<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>bindings<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Here it is all business as usual: there is no significant difference from what is described <\/FONT><\/SPAN><\/SPAN><\/SPAN><A href=\"http:\/\/msdn2.microsoft.com\/en-gb\/library\/ms751504.aspx\"><FONT color=\"#0033cc\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>here<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>. We define an endpoint for getting weather information and one for getting traffic data; they both share the same binding, <\/SPAN><\/SPAN><SPAN><SPAN><SPAN>wsHttpBinding<\/SPAN>, and the same behavior configuration.<\/SPAN><\/SPAN><\/FONT><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><FONT size=\"3\"><FONT face=\"Verdana\">The final lines of the configuration file are the one where we actually apply our custom behavior.<\/FONT><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>behaviors<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>endpointBehaviors<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>behavior<\/SPAN> <SPAN>name<\/SPAN>=&#8217;MyClientBehavior&#8217;&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;!&#8211;<SPAN>&lt;ClientCredentials&gt;<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;serviceCertificate&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;authentication<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>trustedStoreLocation=&#8217;LocalMachine&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>revocationMode=&#8217;NoCheck&#8217;\/&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;defaultCertificate<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>findValue=&#8217;www.fabrikam.com&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN>storeLocation=&#8217;LocalMachine&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>storeName=&#8217;My&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>x509FindType=&#8217;FindBySubjectName&#8217; \/&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/serviceCertificate&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><FONT face=\"Lucida Console\"><SPAN><SPAN><SPAN><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/ClientCredentials&gt;<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>&#8211;&gt;<\/SPAN><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>serviceCertificate<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>authentication<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>trustedStoreLocation<\/SPAN>=&#8217;LocalMachine&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>revocationMode<\/SPAN>=&#8217;NoCheck&#8217;\/&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;<SPAN>defaultCertificate<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>findValue<\/SPAN>=&#8217;www.fabrikam.com&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>storeLocation<\/SPAN>=&#8217;LocalMachine&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>storeName<\/SPAN>=&#8217;My&#8217;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>x509FindType<\/SPAN>=&#8217;FindBySubjectName&#8217; \/&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>serviceCertificate<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>behavior<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>endpointBehaviors<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>&lt;\/<SPAN>behaviors<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp; <\/SPAN>&lt;\/<SPAN>system.serviceModel<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&lt;\/<SPAN>configuration<\/SPAN>&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">In the commented element you will probably recognize the usual behavior, as described <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/msdn2.microsoft.com\/en-gb\/library\/ms751504.aspx\"><FONT color=\"#0033cc\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>here<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">. We substituted it with our custom behavior, <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"codeChar0\"><SPAN><FONT face=\"Lucida Console\">SimpleCardSpaceTokenClientCredentials<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">; note that the content of the element is exactly the same of the commented version. The semantic of every subelement does not change: the effect of every setting is preserved in the new implementation, too. The only significant difference when we use our custom behavior is that tokens will survive across channel instances, and will be shared by all the endpoints that make use of our behavior in the current process.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">In the next section we will get a closer look at the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN><FONT face=\"Verdana\"><SPAN>&nbsp; <\/SPAN>code, to see how we obtained this result.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">[[[[[[[<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">This is exactly what we do in the highlighted lines:<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT size=\"3\">\u00b7<\/FONT><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">We add to the scene class a member of type <\/FONT><\/SPAN><\/SPAN><FONT size=\"3\"><SPAN><SPAN><SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN><FONT face=\"Verdana\">, our custom ClientCredentials behavior (more on the internals of <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN><FONT face=\"Verdana\"> in the next section) and we initialize it in the constructor<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT size=\"3\">\u00b7<\/FONT><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">When we create the channel, we substitute the default <\/FONT><\/SPAN><\/SPAN><A href=\"http:\/\/windowssdk.msdn.microsoft.com\/en-us\/library\/ms553830.aspx\"><FONT color=\"#800080\"><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN><SPAN>ClientCredentials<\/SPAN><\/SPAN><SPAN><SPAN><\/SPAN><\/SPAN><\/FONT><\/FONT><\/FONT><\/A><SPAN><SPAN><FONT size=\"3\"><FONT face=\"Verdana\"><SPAN>&nbsp; <\/SPAN>with our instance<\/FONT><\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"SectionHeading\"><SPAN><SPAN><STRONG><FONT face=\"Verdana\">&nbsp;<\/FONT><\/STRONG><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"SectionHeading\"><SPAN><SPAN><STRONG><FONT face=\"Verdana\">The SimpleCardSpaceTokenClientCredentials class<\/FONT><\/STRONG><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\"><FONT size=\"3\">The<SPAN>&nbsp; <\/SPAN><\/FONT><\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><FONT size=\"3\"><SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN><FONT face=\"Verdana\"> class is contained in the project <\/FONT><\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">SimpleCardSpaceTokenClientCredentials<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">, namely in the file <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">SimpleCardSpaceTokenClientCredentials.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">. It derives from <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><FONT size=\"3\"><SPAN>ClientCredentials<\/SPAN><FONT face=\"Verdana\">. It will be instanced automatically whenever the system will find it in the behaviors list in an endpoint configuration, as we have shown in the former section.<\/FONT><\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">The <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>tokenCache<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><FONT face=\"Verdana\"><SPAN> static <\/SPAN>member will survive for the entire lifetime of the UI, and will be accessible by every <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>SimpleCardSpaceTokenClientCredentials <\/SPAN><FONT face=\"Verdana\">instance: this will allow us to share its content across all the channel instances that we will use for invoking services, for as long as the user will work with the application.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Simply saving the first token obtained from CardSpace and sharing it indiscriminately, however, is not a correct solution. Different services may be bonded to different policies: in that case, the token previously cached is simply not suitable for calling the new service and the CardSpace UI MUST appear. Furthermore, tokens can expire: it is then necessary to prompt the user again in order to obtain a fresh version of the credentials. <\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">Let\u2019s focus on the code that deals with the caching function. <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>ClientCredentials<\/SPAN><FONT face=\"Verdana\"> has a method, <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>GetInfoCardSecurityToken<\/SPAN><FONT face=\"Verdana\">, that is called every time there is the need of obtaining a token from the CardSpace UI. This is the hook where we can implement our caching strategy: our custom class will override <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>GetInfoCardSecurityToken<\/SPAN><FONT face=\"Verdana\">, saving the new tokens obtained from the UI in a store and serving them back without invoking the UI if a suitable token was already cached. Below is a snippet of the relevant code.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">\/\/\/<SPAN> <\/SPAN>&lt;summary&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">\/\/\/<SPAN> Custom ClientCredentials behavior, contianing caching logic<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">\/\/\/<SPAN> <\/SPAN>&lt;\/summary&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><FONT face=\"Lucida Console\"><SPAN><SPAN><SPAN>public<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN> <SPAN>class<\/SPAN> <SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN> : <SPAN>ClientCredentials<\/SPAN><\/SPAN><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>\/\/\/<SPAN> <\/SPAN>&lt;summary&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>\/\/\/<SPAN> The static token cache, indexed by policy<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>\/\/\/<SPAN> <\/SPAN>&lt;\/summary&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>static<\/SPAN> <SPAN>Dictionary<\/SPAN>&lt;<SPAN>PolicyChainKey<\/SPAN>,<SPAN>SecurityToken<\/SPAN>&gt; tokenCache;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>protected<\/SPAN> <SPAN>override<\/SPAN> <SPAN>SecurityToken<\/SPAN> GetInfoCardSecurityToken(<SPAN>bool<\/SPAN> requiresInfoCard, <SPAN>CardSpacePolicyElement<\/SPAN>[] chain, <SPAN>SecurityTokenSerializer<\/SPAN> tokenSerializer)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>PolicyChainKey<\/SPAN> pck = <SPAN>new<\/SPAN> <SPAN>PolicyChainKey<\/SPAN>(chain);<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>TimeZone<\/SPAN> localZone = <SPAN>TimeZone<\/SPAN>.CurrentTimeZone;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>if<\/SPAN> ((tokenCache.ContainsKey(pck)) &amp;&amp; (localZone.ToLocalTime(tokenCache[pck].ValidFrom) &lt; <SPAN>DateTime<\/SPAN>.Now) &amp;&amp; (localZone.ToLocalTime(tokenCache[pck].ValidTo) &gt; <SPAN>DateTime<\/SPAN>.Now))<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>return<\/SPAN> tokenCache[pck];<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>lock<\/SPAN> (tokenCache)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>tokenCache.Add(pck, <SPAN>base<\/SPAN>.GetInfoCardSecurityToken(requiresInfoCard, chain, tokenSerializer));<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>return<\/SPAN> tokenCache[pck];<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/SPAN> <\/FONT><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">The highlighted member represents the true token cache. It is a dictionary of <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>SecurityToken<\/SPAN><FONT face=\"Verdana\">: every item is associated with a key which represents the policy conditions under which the token was obtained. We will explain this point in much greater detail later in the section.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">The override of <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>GetInfoCardSecurityToken<\/SPAN><FONT face=\"Verdana\"> is really straightforward:<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">1.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">The code derives a dictionary key from the policy requirements associated with the current token request (more on this later)<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">2.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">If the token cache<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">a.<\/FONT><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">Contains a token compatible with the current policy requirements<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">b.<\/FONT><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">Such a token is still valid<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">then the method returns such a token, without invoking the UI. Otherwise: a new token is obtained from the UI (via <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>base.GetInfoCardSecurityToken<\/SPAN><FONT face=\"Verdana\">), it gets cached and returned.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">This is really easy. Of course, we need to take steps for ensuring that the mechanism will not be abused. For this reason, we cache tokens according to the policy that was enforced when every single token was originally obtained.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Namely, we concentrate on three elements:<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">1.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">The certificate associated with the web service we are calling (our <I>target<\/I>)<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">2.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">The URI of the issuer<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">3.<\/FONT><SPAN>&nbsp;&nbsp; <\/SPAN><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">The URI of the target<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Before deciding to reuse a token we have in the cache, we have to verify if the current policy requirement is \u201cequivalent\u201d to the ones associated with the cached token.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The certificate HAS to be the same. If a token was obtained for a web service with a certain identity, in the form of an X509 certificate, the results of many cryptographic operations will be bonded to that certificate. Even the value of the PPID claim will depend on that. <\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The URI of the STS, from where we obtained the cached token, needs to be the same as well. We don\u2019t want to repurpose any token against the explicit requirements of the policy which is mandating a well determined STS.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">Where we have some degree of discretion is in the URI of the target. We can\u2019t mandate that the two are exactly the same, of course: that would partially defy the very reasons for which we are building a cache. Two different services will have two different URIs for their endpoints, yet they may use the same token. This is the case of our example, where two web services are offered by the same entity: both services share the same x509 certificate, and the same base address. In this example we arbitrarily decided that two URIs are equivalent if the server name corresponds.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">Such requirements have been expressed in the implementation of the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>PolicyChainKey<\/SPAN><FONT face=\"Verdana\"> class. The <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>PolicyChainKey<\/SPAN><FONT face=\"Verdana\"> class contains three members which contain information about the target URI, the issuer URI and the certificate hash string associated with a token. <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>PolicyChainKey<\/SPAN><FONT face=\"Verdana\"> overrides the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>Equals<\/SPAN><FONT face=\"Verdana\"> method in a way that expresses the equivalence concepts listed above.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">Thanks to the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>Equals<\/SPAN><FONT face=\"Verdana\"> override, checking a hashtable for a certain <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>PolicyChainKey<\/SPAN><FONT face=\"Verdana\"> key value corresponds to verifying if the cache contains a token that satisfies the policy requirements in the sense defined above.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">The code below is the source of the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>PolicyChainKey<\/SPAN><FONT face=\"Verdana\"> class.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp; <\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">public class <SPAN>PolicyChainKey<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>string targetHost;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>string issuer;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp; <\/SPAN><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/SPAN>string certificate;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>public PolicyChainKey(<SPAN>CardSpacePolicyElement<\/SPAN>[] chain)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>if (chain.Length != 0)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>EndpointAddress<\/SPAN> ea = <SPAN>EndpointAddress<\/SPAN>.ReadFrom(<SPAN>XmlDictionaryReader<\/SPAN>.CreateDictionaryReader(new <SPAN>XmlTextReader<\/SPAN>(new System.IO.<SPAN>StringReader<\/SPAN>(chain[0].Target.OuterXml))));<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>X509CertificateEndpointIdentity<\/SPAN> xcei = ea.Identity as <SPAN>X509CertificateEndpointIdentity<\/SPAN>;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>certificate = xcei.Certificates[0].GetCertHashString();<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>targetHost = ea.Uri.Host;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>if (chain[0].Issuer != null)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>ea = <SPAN>EndpointAddress<\/SPAN>.ReadFrom(<SPAN>XmlDictionaryReader<\/SPAN>.CreateDictionaryReader(new <SPAN>XmlTextReader<\/SPAN>(new System.IO.<SPAN>StringReader<\/SPAN>(chain[0].Issuer.OuterXml))));<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>issuer = ea.Uri.ToString();<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>public override bool Equals(<SPAN>Object<\/SPAN> obj)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>if (obj == null || GetType() != obj.GetType())<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>return false;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>PolicyChainKey<\/SPAN> p = (<SPAN>PolicyChainKey<\/SPAN>)obj;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>return (targetHost == p.targetHost) &amp;&amp; (certificate == p.certificate) &amp;&amp; (issuer == p.issuer);<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>public override int GetHashCode()<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>return (issuer == null) ? targetHost.GetHashCode() ^ certificate.GetHashCode() :<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>targetHost.GetHashCode() ^ certificate.GetHashCode() ^ issuer.GetHashCode();<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/SPAN><BR><BR><\/FONT><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The last class defined in <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">SimpleCardSpaceTokenClientCredentials.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> is straightforward. <\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><SPAN>SimpleCardSpaceTokenClientCredentialsConfigHandler<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><FONT face=\"Verdana\"><SPAN> <\/SPAN>defines how to read the configuration tag, and it basically uses directly the implementation of the base class.<\/FONT><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp; <\/SPAN>\/\/\/<SPAN> <\/SPAN>&lt;summary&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>\/\/\/<SPAN> Configuration element for the SimpleCardSpaceTokenClientCredentials behavior<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>\/\/\/<SPAN> <\/SPAN>&lt;\/summary&gt;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>public<\/SPAN> <SPAN>class<\/SPAN> <SPAN>SimpleCardSpaceTokenClientCredentialsConfigHandler<\/SPAN> : <SPAN>ClientCredentialsElement<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>public<\/SPAN> <SPAN>override<\/SPAN> <SPAN>Type<\/SPAN> BehaviorType<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>get<\/SPAN> { <SPAN>return<\/SPAN> <SPAN>typeof<\/SPAN>(<SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN>); }<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>protected<\/SPAN> <SPAN>override<\/SPAN> <SPAN>object<\/SPAN> CreateBehavior()<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN> scstcc = <SPAN>new<\/SPAN> <SPAN>SimpleCardSpaceTokenClientCredentials<\/SPAN>();<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>base<\/SPAN>.ApplyConfiguration(scstcc);<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>return<\/SPAN> scstcc;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"SectionHeading\"><SPAN><SPAN><STRONG><FONT face=\"Verdana\">The services<\/FONT><\/STRONG><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The services do not need to be aware of what the client is doing: they play no part in implementing the caching behavior featured by the sample. <\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The two service projects, <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">MeteoService<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> and <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">TrafficService<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\">, do not really contain anything different from the usual samples.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><FONT size=\"3\"><SPAN><SPAN><FONT face=\"Verdana\">The only code we added simulates a very rough form of authorization control: the body of the method checks if the token used for securing the call contains the PPID of the sample self issued card we provided. You can easily modify that hardcoded value with a PPID of your own by changing the value of the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>AppSettings<\/SPAN><FONT face=\"Verdana\"> key \u201c<\/FONT><\/SPAN><\/SPAN><\/FONT><SPAN><SPAN><SPAN>PPIDToCheck<\/SPAN><FONT face=\"Verdana\" size=\"3\">\u201d, or even better substitute the entire check with a more proper authorization mechanism. Note that if you don\u2019t provide any value for \u201c<\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN>PPIDToCheck<\/SPAN><FONT face=\"Verdana\" size=\"3\">\u201d in the service configuration the authorization step will be skipped.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">The snipped below is taken from the file <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">Program.cs<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> of the <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">TrafficService<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> project; the project <\/FONT><\/SPAN><\/SPAN><SPAN><SPAN><SPAN class=\"CodeChar\"><SPAN><FONT face=\"Lucida Console\">MeteoService<\/FONT><\/SPAN><\/SPAN><FONT face=\"Verdana\" size=\"3\"> is perfectly equivalent.<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"DocumentText\"><SPAN><SPAN><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"MsoNormal\"><SPAN><SPAN><SPAN>&nbsp;<\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<DIV><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>class<\/SPAN> <SPAN>Traffic<\/SPAN> : <SPAN>ITraffic<\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp; <\/SPAN><SPAN>&nbsp;&nbsp;<\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>private<\/SPAN> <SPAN>bool<\/SPAN> AuthorizeByPPID()<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>string<\/SPAN> ppid = System.Configuration.<SPAN>ConfigurationManager<\/SPAN>.AppSettings[<SPAN>&#8220;PPIDToCheck&#8221;<\/SPAN>];<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>if<\/SPAN> (ppid == <SPAN>null<\/SPAN>)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>return<\/SPAN> <SPAN>true<\/SPAN>;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>AuthorizationContext<\/SPAN> ac = <SPAN>ServiceSecurityContext<\/SPAN>.Current.AuthorizationContext;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>foreach<\/SPAN> (<SPAN>ClaimSet<\/SPAN> ct <SPAN>in<\/SPAN> ac.ClaimSets)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>foreach<\/SPAN> (<SPAN>Claim<\/SPAN> c <SPAN>in<\/SPAN> ct)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>if<\/SPAN> (c.ClaimType == <SPAN>&#8220;http:\/\/schemas.xmlsoap.org\/ws\/2005\/05\/identity\/claims\/privatepersonalidentifier&#8221;<\/SPAN>)<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>return<\/SPAN> (c.Resource.ToString() == ppid);<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>return<\/SPAN> <SPAN>false<\/SPAN>;<SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>}<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><FONT face=\"Lucida Console\"><SPAN><SPAN><SPAN><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>#region<\/SPAN><\/SPAN><\/SPAN><SPAN><SPAN><SPAN> ITraffic Members<\/SPAN><\/SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>public<\/SPAN> <SPAN>List<\/SPAN>&lt;<SPAN>TrafficInfo<\/SPAN>&gt; GetTrafficInfo()<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><FONT face=\"Lucida Console\"><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN><SPAN>if<\/SPAN> (AuthorizeByPPID())<\/FONT><\/SPAN><\/SPAN><\/SPAN><\/P><br \/>\n<P class=\"Code\"><SPAN><SPAN><SPAN><SPAN>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/SPAN>{<\/SPAN><\/SPAN><\/SPAN><FONT face=\"Lucida Console\"><SPAN><SPAN><SPAN>&#8230;<\/SPAN><\/SPAN><\/SPAN><SPAN><\/SPAN><\/FONT><\/P><br \/>\n<P class=\"Code\"><SPAN><FONT face=\"Lucida Console\">&nbsp;<\/FONT><\/SPAN><\/P><\/DIV><br \/>\n<P class=\"SectionHeading\"><STRONG><FONT face=\"Verdana\">Conclusion<\/FONT><\/STRONG><\/P><br \/>\n<P class=\"DocumentText\"><FONT face=\"Verdana\" size=\"3\">&nbsp;<\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><FONT face=\"Verdana\" size=\"3\">Windows CardSpace provides a consistent mean of authenticating users, both on web applications and web services. <\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><FONT face=\"Verdana\" size=\"3\">In this sample we have shown how you can obtain a smoother experience when developing smartclient applications, by reducing the number of unnecessary prompts with an adequate caching strategy.<\/FONT><\/P><br \/>\n<P class=\"DocumentText\"><FONT face=\"Verdana\" size=\"3\">If you have any question, please refer to the <\/FONT><A href=\"http:\/\/forums.microsoft.com\/MSDN\/ShowForum.aspx?ForumID=784&amp;SiteID=1&amp;PageID=0\"><FONT face=\"Verdana\" color=\"#800080\" size=\"3\">Windows CardSpace forums<\/FONT><\/A><FONT face=\"Verdana\" size=\"3\"> or to <\/FONT><A href=\"http:\/\/blogs.msdn.com\/vbertocci\/\"><FONT face=\"Verdana\" color=\"#800080\" size=\"3\">Vittorio\u2019s blog<\/FONT><\/A><FONT face=\"Verdana\" size=\"3\">.<\/FONT><\/P><br \/>\n<P>&nbsp;<\/P><\/p>\n<div style=\"clear:both\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello everybody. It&#8217;s some time that I have this sample in the buffer: I am publishing now in a rush, since this sundaly I leave for 2 weeks in EU for some nice CardSpace briefings here and there. I won&#8217;t be on mail very much, so I hope you will hold most questions&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1499,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[61,39,9,86,64,55,31,104,62],"tags":[],"class_list":["post-699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-architecture-ws","category-cardspace","category-identity","category-infocard","category-wcf","category-windows-cardspace","category-windows-communication-foundation","category-windows-presentation-foundation","category-wpf"],"_links":{"self":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/comments?post=699"}],"version-history":[{"count":0,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/posts\/699\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media\/1499"}],"wp:attachment":[{"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/media?parent=699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/categories?post=699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cloudidentity.com\/blog\/wp-json\/wp\/v2\/tags?post=699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}