<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Rick Rainey</title><subtitle type="html">Developer Premier Field Engineer (PFE) at Microsoft.</subtitle><id>http://blogs.msdn.com/b/rickrain/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/rickrain/atom.aspx" /><generator uri="http://telligent.com" version="5.6.50428.7875">Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><updated>2004-10-14T18:07:00Z</updated><entry><title>Setup Identity and Access Tools for Visual Studio 2012</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2012/09/26/setup-identity-and-access-tools-for-visual-studio-2012.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2012/09/26/setup-identity-and-access-tools-for-visual-studio-2012.aspx</id><published>2012-09-26T21:05:51Z</published><updated>2012-09-26T21:05:51Z</updated><content type="html">&lt;p&gt;&lt;font size="2"&gt;There are a couple of options for installing the tools that are mentioned &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/hh545418.aspx" target="_blank"&gt;&lt;font size="2"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.&amp;#160; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Here are the steps to installing Identity and Access Tools from the Extension Manager in Visual Studio:&lt;/font&gt;&lt;/p&gt;  &lt;ol&gt;&lt;/ol&gt;  &lt;p&gt;&lt;font size="2"&gt;Start Visual Studio 2012.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;From the menu select &lt;strong&gt;TOOLS | Extensions and Updates. . .&lt;/strong&gt; &lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Click the &lt;strong&gt;Online&lt;/strong&gt; extensions node in the tree view on the left.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Search for &lt;strong&gt;“identity”&lt;/strong&gt; in the search field in the upper right&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Click the &lt;strong&gt;Download&lt;/strong&gt; button to download and install the package.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/2133.image_5F00_0F585947.png"&gt;&lt;font size="2"&gt;&lt;img title="image" style="display: inline; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/6254.image_5F00_thumb_5F00_35BA3C92.png" width="644" height="143" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;After the install, you will be prompted to restart Visual Studio.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/0882.image_5F00_29B84C5E.png"&gt;&lt;font size="2"&gt;&lt;img title="image" style="display: inline; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/8802.image_5F00_thumb_5F00_22990FE6.png" width="644" height="45" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;After restarting Visual Studio, you should now see the &lt;strong&gt;Identity and Access. . .&lt;/strong&gt; option if you right-click on your project.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/7824.image_5F00_54247D7B.png"&gt;&lt;font size="2"&gt;&lt;img title="image" style="display: inline; background-image: none;" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/5277.image_5F00_thumb_5F00_4D054103.png" width="297" height="172" /&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;ol&gt;&lt;/ol&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/7824.image_5F00_54247D7B.png"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/0882.image_5F00_29B84C5E.png"&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/7824.image_5F00_54247D7B.png"&gt;&lt;font size="2"&gt;&amp;#160;&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10353564" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WIF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WIF/" /><category term="Identity and Access" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/Identity+and+Access/" /><category term="Visual Studio 2012" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/Visual+Studio+2012/" /></entry><entry><title>Which WCF Binding Is Best?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2012/05/20/which-wcf-binding-is-best.aspx" /><link rel="enclosure" type="application/zip" length="7875" href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-30-77-35/BindingTestSolution.zip" /><id>http://blogs.msdn.com/b/rickrain/archive/2012/05/20/which-wcf-binding-is-best.aspx</id><published>2012-05-20T16:47:00Z</published><updated>2012-05-20T16:47:00Z</updated><content type="html">&lt;p&gt;&lt;span style="color: #ff0000;"&gt;[Updated - 10/3/2012: An astute &lt;a href="http://codermonkey65.blogspot.co.uk/"&gt;reader&lt;/a&gt; pointed out that the sample below will produce&amp;nbsp;some inconsistent results based on the order of the bindings being compared.&amp;nbsp; This is because of things like JIT compilation, internal&amp;nbsp;caching, etc.&amp;nbsp; As a quick fix, I added&amp;nbsp;two lines of code to the CompareBindings method to "warm up" the&amp;nbsp;binding elements that will be&amp;nbsp;compared.&amp;nbsp;&amp;nbsp;]&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Which binding is best?&amp;nbsp; That&amp;rsquo;s a question I hear and see a lot.&amp;nbsp; When it&amp;rsquo;s asked of me, the answer is always &amp;ndash; &amp;ldquo;it depends&amp;rdquo;.&amp;nbsp; It&amp;rsquo;s impossible to know from that simple question which binding is going to &amp;ldquo;best&amp;rdquo; meet your application requirements.&amp;nbsp; Quickly after I start probing for more information, the question narrows down to which binding is fastest?&amp;nbsp; Again, the answer to that question is going to be (you guessed it) &amp;ndash; &amp;ldquo;it depends&amp;rdquo;.&amp;nbsp; &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/0456.wlEmoticon_2D00_smile_5F00_34699CD9.png" /&gt;&lt;/p&gt;
&lt;p&gt;There are 4 transport schemes that WCF supports: &lt;strong&gt;http&lt;/strong&gt;, &lt;strong&gt;net.tcp&lt;/strong&gt;, &lt;strong&gt;net.pipe&lt;/strong&gt;, and &lt;strong&gt;net.msmq&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If your application requires queuing, then you only have the option of using the bindings that support queuing.&amp;nbsp; In other words, there&amp;rsquo;s nothing to compare.&amp;nbsp; If your application will be called from other applications/services on the same machine, then you should be using the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.netnamedpipebinding.aspx" target="_blank"&gt;NetNamedPipeBinding&lt;/a&gt; for cross-process calls on the same machine. So, again, there&amp;rsquo;s really nothing to compare.&lt;/p&gt;
&lt;p&gt;So, when comparing bindings, the transport scheme pretty much shakes out to a comparison between &lt;strong&gt;http&lt;/strong&gt; and &lt;strong&gt;net.tcp&lt;/strong&gt;.&amp;nbsp; These are the two left that will be used when crossing machine boundaries (actually going out on the NIC).&amp;nbsp; There are several bindings and endless binding configurations that potentially can use one of these two schemes.&amp;nbsp;&amp;nbsp; For example, does your application require security?&amp;nbsp; If so, then you have several decisions to make, such as do you want to use &lt;a href="http://msdn.microsoft.com/en-us/library/ms729700" target="_blank"&gt;transport&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/ms733137.aspx" target="_blank"&gt;message&lt;/a&gt; security?&amp;nbsp; What kind of credentials are you going to prompt your client for?&amp;nbsp; Is Federation/SSO a requirement?&amp;nbsp; Just to&amp;nbsp; name a few.&amp;nbsp; What about your message payload size?&amp;nbsp; Is it large/small?&amp;nbsp; Do you have transactional requirements for message exchanges?&amp;nbsp; Are there interoperability constraints you need to account for?&amp;nbsp; Will your service require sessions?&amp;nbsp; And so on&amp;hellip;.&amp;nbsp; So, you can begin to see why the answer to such a question is always &amp;ldquo;it depends&amp;rdquo;.&amp;nbsp; Instead, a thoughtful discussion about the application requirements is necessary to offer up sound advice on the subject.&amp;nbsp; When you do compare bindings, you need to make sure you&amp;rsquo;re comparing bindings equally &amp;ndash; that is, all the bindings meet the requirements for your application.&amp;nbsp; As an example, it&amp;rsquo;s not a fair comparison to compare &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.nettcpbinding.aspx" target="_blank"&gt;NetTcpBinding&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding" target="_blank"&gt;BasicHttpBinding&lt;/a&gt; with their default values.&amp;nbsp; These bindings offer different features by default.&lt;/p&gt;
&lt;p&gt;Still, people just want to know, if &amp;ldquo;conditions xyz&amp;rdquo; exist, which binding is going to be fastest?&amp;nbsp; For that, I have a little sample application I put together to help &lt;em&gt;you&lt;/em&gt; answer that question yourself.&amp;nbsp; Knowing that bindings are simply a collection of binding elements to support various features, you can start to construct bindings and binding configurations to compare against each other with little effort.&amp;nbsp; Below is a brief description of the primary methods in this sample application and how you may want to customize it for your needs.&lt;/p&gt;
&lt;h2&gt;TestBinding&lt;/h2&gt;
&lt;p&gt;This method hosts the service (TestService), instantiates a client proxy, and calls the ProcessData method using the binding and data provided.&amp;nbsp; It returns a &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.100).aspx" target="_blank"&gt;StopWatch&lt;/a&gt; to the caller so the elapsed time can be observed.&amp;nbsp; In this method, I have the StopWatch starting just before creating the client proxy and opening the channel.&amp;nbsp; I stop it after closing the client proxy.&amp;nbsp; You may want to make your test more granular and put the start and stop immediately before and after the call to ProcessData (if you don&amp;rsquo;t want the elapsed time to include creating the channel).&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/4137.image_5F00_41637CEA.png"&gt;&lt;img width="841" height="488" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/4628.image_5F00_thumb_5F00_785D5B23.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;CompareBindings&lt;/h2&gt;
&lt;p&gt;This method invokes the TestBinding method for an array of bindings you provide.&amp;nbsp; It will generate some random data for the test using the size you specify.&amp;nbsp; For each test, it will output the binding&amp;rsquo;s elements and the results from the StopWatch returned from TestBinding.&amp;nbsp;&amp;nbsp; Other than changing the format of the output or writing more binding configuration data to the console, you probably won&amp;rsquo;t change this.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/1882.image_5F00_165B6918.png"&gt;&lt;img width="743" height="330" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/4135.image_5F00_thumb_5F00_3B78B384.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Main&lt;/h2&gt;
&lt;p&gt;This is where I create some bindings, add them to an array of bindings, and call the CompareBindings method.&amp;nbsp; This is where you will do most of your experimenting.&amp;nbsp; Create the bindings with the elements you want/need.&amp;nbsp; Add them to the binding array&amp;nbsp; and call CompareBindings.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/5684.image_5F00_128D9E7B.png"&gt;&lt;img width="674" height="667" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/1067.image_5F00_thumb_5F00_178FDC2A.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Sample Output&lt;/h2&gt;
&lt;p&gt;This is an example of the output with the application running on my single machine.&amp;nbsp; In my test, there is no network latency since everything is local.&amp;nbsp; You may want to separate your tests out into a separate client and service application so you can include network latency in your test.&amp;nbsp; Also, this output is not comparing equal bindings so don&amp;rsquo;t read too much into my output.&amp;nbsp; I just put together a few bindings so you could see how to construct the bindings to meet your needs.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/5684.image_5F00_7557D0A3.png"&gt;&lt;img width="586" height="456" title="image" style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/2133.image_5F00_thumb_5F00_6C87C857.png" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Hopefully this helps identify which bindings are going to be best for your application and also shine some light on why it&amp;rsquo;s not a quick-and-simple answer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can download the full application code from here.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10307735" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term=".NET" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/-NET/" /></entry><entry><title>Using a Server Certificate to Protect Web.Config</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2012/02/27/using-a-server-certificate-to-protect-web-config.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2012/02/27/using-a-server-certificate-to-protect-web-config.aspx</id><published>2012-02-28T01:42:47Z</published><updated>2012-02-28T01:42:47Z</updated><content type="html">&lt;p&gt;Using ASP.NET’s &lt;a href="http://msdn.microsoft.com/en-us/library/53tyfkaw.aspx" target="_blank"&gt;protected configuration&lt;/a&gt; feature is recommended when your Web.Config file contains sensitive information.&amp;#160; The .NET Framework gives you two protected configuration providers, &lt;a href="http://msdn.microsoft.com/en-us/library/system.configuration.dpapiprotectedconfigurationprovider.aspx" target="_blank"&gt;DpapiProtectedConfigurationProvider&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.configuration.rsaprotectedconfigurationprovider.aspx" target="_blank"&gt;RsaProtectedConfigurationProvider&lt;/a&gt;.&amp;#160; Depending on your application requirements, you can use either of these to get the job done.&lt;/p&gt;  &lt;p&gt;You can also create your own protected configuration provider and there is a sample &lt;a href="http://msdn.microsoft.com/en-us/library/33ws57y0.aspx" target="_blank"&gt;here&lt;/a&gt; that shows an implementation using the TripleDESCryptoServiceProvider for encrypting and decryption.&amp;#160; Implementing your own protected configuration provider is simply a matter of writing a class that derives from &lt;a href="http://msdn.microsoft.com/en-us/library/system.configuration.protectedconfigurationprovider.aspx" target="_blank"&gt;ProtectedConfigurationProvider&lt;/a&gt;.&amp;#160;&amp;#160; In this blog post, I’m going to show a another custom provider option using a server certificate for the encryption and decryption.&lt;/p&gt;  &lt;h4&gt;&amp;#160;&lt;/h4&gt;  &lt;h4&gt;Implement the Provider&lt;/h4&gt;  &lt;p&gt;Using &lt;strong&gt;Visual Studio 2010&lt;/strong&gt;, create a new &lt;strong&gt;Class Library&lt;/strong&gt; project and inherit your class from &lt;strong&gt;ProtectedConfigurationProvider.&lt;/strong&gt;&amp;#160; The &lt;strong&gt;ProtectedConfigurationProvider&lt;/strong&gt; class is located in the &lt;strong&gt;System.Configuration assembly&lt;/strong&gt;.&amp;#160; So, you will need to add a .NET Reference to System.Configuration and also add a using statement to the top of your class for the &lt;strong&gt;System.Configuration namespace&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;This provider will perform encryption and decryption using the keys from an X509 Certificate.&amp;#160; The &lt;a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate2.aspx" target="_blank"&gt;X509Certificate2&lt;/a&gt; class is located in the &lt;strong&gt;System.Security assembly&lt;/strong&gt;.&amp;#160; So, you will need to add a .NET Reference to System.Security and also add a using statement for the &lt;strong&gt;System.Security.Cryptography.X509Certificates namespace&lt;/strong&gt;.&amp;#160; Next, add a private &lt;strong&gt;X509Certificate2&lt;/strong&gt; member to the class that will be used as a reference to the server certificate.&lt;/p&gt;  &lt;p&gt;This provider will be installed in the GAC so it is easily accessible by ASP.NET and the aspnet_regiis.exe tool on the server.&amp;#160; Therefore, add a strong name key file to the project.&amp;#160; Later on, you will need the public key token from the signed assembly.&amp;#160; To make it easy to get this, add the following post-build event to the project properties:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;quot;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe&amp;quot; -T &amp;quot;$(TargetPath)&amp;quot;&lt;/font&gt;&lt;/p&gt;    &lt;p&gt;Note: The path to sn.exe may differ on your machine.&lt;/p&gt;  &lt;/blockquote&gt;  &lt;p&gt;There are 3 methods you must override to implement the provider: &lt;strong&gt;Initialize&lt;/strong&gt;, &lt;strong&gt;Encrypt&lt;/strong&gt;, and &lt;strong&gt;Decrypt&lt;/strong&gt;.&amp;#160; The shell of your class should look like this.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/2844.ClassShell_5F00_260577BF.png"&gt;&lt;img style="display: inline; background-image: none;" title="ClassShell" border="0" alt="ClassShell" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/4162.ClassShell_5F00_thumb_5F00_05120518.png" width="811" height="360" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The implementation for &lt;strong&gt;Initialize&lt;/strong&gt; is shown below.&amp;#160; This code is pretty straight forward.&amp;#160; The key thing to note is that this provider expects &lt;strong&gt;CertSubjectDistinguishedName&lt;/strong&gt; to be defined in the &lt;strong&gt;&amp;lt;configProtectedData&amp;gt;&lt;/strong&gt; section of the config.&amp;#160; More on how that get’s defined later.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/8204.Initialize_5F00_2454ABEB.png"&gt;&lt;img style="display: inline; background-image: none;" title="Initialize" border="0" alt="Initialize" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/2746.Initialize_5F00_thumb_5F00_7184A576.png" width="731" height="424" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The implementation for &lt;strong&gt;Encrypt&lt;/strong&gt; and &lt;strong&gt;Decrypt&lt;/strong&gt; is shown here.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/5141.EncryptDecrypt_5F00_29C31C8F.png"&gt;&lt;img style="display: inline; background-image: none;" title="EncryptDecrypt" border="0" alt="EncryptDecrypt" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/5460.EncryptDecrypt_5F00_thumb_5F00_542F4DAC.png" width="559" height="329" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;That’s all there is to it.&amp;#160; When you build the project, your provider will be signed and the post-build step from above will display your public key token in the &lt;strong&gt;Output&lt;/strong&gt; window.&amp;#160; You will need this later.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/4075.Output_5F00_086376F3.png"&gt;&lt;img style="display: inline; background-image: none;" title="Output" border="0" alt="Output" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/2018.Output_5F00_thumb_5F00_19D3D7CB.png" width="603" height="175" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Deploy the Provider&lt;/h4&gt;  &lt;p&gt;This provider needs to be installed in the GAC on the target IIS server.&amp;#160; You probably won’t have gacutil.exe available on the target server to install this into the GAC.&amp;#160; So, adding a &lt;strong&gt;Visual Studio Installer Setup Project&lt;/strong&gt; to your solution will simplify this process for you. &lt;/p&gt;  &lt;p&gt;In your &lt;strong&gt;Setup Project&lt;/strong&gt;, add the &lt;strong&gt;Global Assembly Cache Folder&lt;/strong&gt; to the File System Target and specify the output from the protected configuration provider project.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/6138.SetupProject2_5F00_59318B5B.png"&gt;&lt;img style="display: inline; background-image: none;" title="SetupProject2" border="0" alt="SetupProject2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/1447.SetupProject2_5F00_thumb_5F00_2D80C15F.png" width="709" height="130" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Build the setup project and copy the &lt;strong&gt;Setup.exe&lt;/strong&gt; and &lt;strong&gt;X509ProtectedConfigProviderSetup.msi&lt;/strong&gt; file to your target IIS server.&amp;#160; For the purposes of this post, I’m deploying to &lt;strong&gt;IIS 7.5 / Windows Server 2008 R2&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;On the target server, run the &lt;strong&gt;Setup.exe&lt;/strong&gt; to install the provider.&amp;#160; Choose &lt;strong&gt;Everyone&lt;/strong&gt; when prompted by the installer to make the provider available for &lt;strong&gt;Everyone&lt;/strong&gt; or &lt;strong&gt;Just me&lt;/strong&gt;.&amp;#160; The provider assembly will be installed in &lt;strong&gt;C:\Windows\Microsoft.NET\assembly\GAC_MSIL&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Create the Server Certificate&lt;/h4&gt;  &lt;p&gt;I’m using a self-signed certificate from IIS 7.5.&amp;#160; This certificate will function as both the SSL certificate for my site as well as provide support for my custom provider to encrypt and decrypt sections of the web.config.&amp;#160; Instructions on how to create a self-signed certificate using IIS Manager can be found &lt;a href="http://learn.iis.net/page.aspx/144/how-to-set-up-ssl-on-iis/" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Since my custom provider will be using the keys from the certificate, the IIS worker process (w3wp.exe) will need read access to the certificate.&amp;#160; In IIS 7.5, the default identity for the &lt;strong&gt;DefaultAppPool&lt;/strong&gt; is &lt;strong&gt;ApplicationPoolIdentity&lt;/strong&gt;, which we’ll give read access to.&amp;#160; Information on this identity can be found &lt;a href="http://learn.iis.net/page.aspx/624/application-pool-identities/" target="_blank"&gt;here&lt;/a&gt;. To grant read access to the certificate, follow these steps.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open Microsoft Management Console (mmc.exe).&lt;/li&gt;    &lt;li&gt;Select &lt;strong&gt;File &amp;gt; Add/Remove Snap-in&lt;/strong&gt; and add the &lt;strong&gt;Certificates&lt;/strong&gt; snap-in for the &lt;strong&gt;Computer Account.&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;Expand the&lt;strong&gt; Personal &amp;gt; Certificates&lt;/strong&gt; folder, where the self-signed certificate is located.&lt;/li&gt;    &lt;li&gt;Right-click on your certificate and select &lt;strong&gt;All Tasks &amp;gt; Manage Private Keys&lt;/strong&gt;.&lt;/li&gt;    &lt;li&gt;Click the &lt;strong&gt;Add&lt;/strong&gt; button and add &lt;strong&gt;IIS AppPool\DefaultAppPool&lt;/strong&gt; to the object name field.&lt;/li&gt;    &lt;li&gt;Click the &lt;strong&gt;Check Names&lt;/strong&gt; button and it should resolve to &lt;strong&gt;DefaultAppPool&lt;/strong&gt;.&lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Permissions&lt;/strong&gt; section, give &lt;strong&gt;DefaultAppPool&lt;/strong&gt; &lt;strong&gt;Read&lt;/strong&gt; permissions only.&lt;/li&gt;  &lt;/ol&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Encrypting the Web.Config&lt;/h4&gt;  &lt;p&gt;A common scenario for encrypting sections of a web.config are when there are connection strings in the file.&amp;#160; Suppose I have a web application with a connection string in the web.config such as this that I want to encrypt using my custom protected configuration provider.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/6646.connectionString_5F00_6CDE74EF.png"&gt;&lt;img style="display: inline; background-image: none;" title="connectionString" border="0" alt="connectionString" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/4174.connectionString_5F00_thumb_5F00_102B6995.png" width="736" height="73" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Add the &amp;lt;configProtectedData&amp;gt; element to the web.config so that it references the &lt;u&gt;&lt;strong&gt;fully qualified name of the custom provider assembly&lt;/strong&gt;&lt;/u&gt;, as shown below.&amp;#160; Notice that here is where we add the &lt;strong&gt;CertSubjectDistinguishedName&lt;/strong&gt; setting that our custom provider looks for.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/3005.configProtectedData_5F00_2F6E1068.png"&gt;&lt;img style="display: inline; background-image: none;" title="configProtectedData" border="0" alt="configProtectedData" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/1854.configProtectedData_5F00_thumb_5F00_4E448446.png" width="889" height="141" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;With this information in the web.config, deploy the application to the target IIS server.&lt;/p&gt;  &lt;p&gt;On the target IIS server:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open a &lt;strong&gt;command prompt&lt;/strong&gt;.&lt;/li&gt;    &lt;li&gt;Change directory to &lt;strong&gt;C:\Windows\Microsoft.NET\Framework64\v4.0.30319&lt;/strong&gt;.&lt;/li&gt;    &lt;li&gt;Type the following command to encrypt the &amp;lt;connectionStrings&amp;gt; section of the web.config.&amp;#160; &lt;/li&gt;  &lt;/ol&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;font size="2" face="Courier New"&gt;aspnet_regiis –pe “connectionStrings” –app “/MyWebApp” –prov “X509Provider”&lt;/font&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;Note: The –app parameter will be the name of your web application.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/2018.success_5F00_3B23579A.png"&gt;&lt;img style="display: inline; background-image: none;" title="success" border="0" alt="success" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/3010.success_5F00_thumb_5F00_3AB724A5.png" width="670" height="61" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;blockquote&gt;   &lt;p&gt;If you go look at the web.config, you will see that the &amp;lt;connectionStrings&amp;gt; section has been encrypted using the custom provider.&lt;/p&gt;    &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;/blockquote&gt;  &lt;p&gt;The last thing to do is test it to make sure that ASP.NET can decrypt the contents as needed to return page requests (see below).&amp;#160; The certificate error is because I’m using a self-signed certificate in my sample.&amp;#160; But, as you can see, ASP.NET is able to successfully use the custom provider to decrypt the connection string to retrieve data from the database.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/1348.Test_5F00_5346C1F5.png"&gt;&lt;img style="display: inline; background-image: none;" title="Test" border="0" alt="Test" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/4075.Test_5F00_thumb_5F00_4AE2EC9E.png" width="644" height="287" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10273706" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term=".NET" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/-NET/" /><category term="aspnet_regiis.exe" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/aspnet_5F00_regiis-exe/" /><category term="ProtectedConfigurationProvider" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/ProtectedConfigurationProvider/" /><category term="ASP.NET" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/ASP-NET/" /></entry><entry><title>Monitoring Client-Outbound WCF Calls</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2012/01/27/monitoring-client-outbound-wcf-calls.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2012/01/27/monitoring-client-outbound-wcf-calls.aspx</id><published>2012-01-27T23:27:00Z</published><updated>2012-01-27T23:27:00Z</updated><content type="html">&lt;p&gt;Recently a colleague asked me if I knew of a way to monitor outbound WCF calls for an application.&amp;nbsp; He just wanted to be able to see the number of outbound calls an application was making.&amp;nbsp; Performance Monitor normally provides the answer to these kinds of questions.&amp;nbsp; Unfortunately, the &lt;a href="http://msdn.microsoft.com/en-us/library/ms735098.aspx" target="_blank"&gt;performance counters for WCF&lt;/a&gt; are primarily server side (incoming) counters.&amp;nbsp;&amp;nbsp; No problem &amp;ndash; just add a custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.aspx" target="_blank"&gt;performance counter&lt;/a&gt;.&amp;nbsp; Well, that is great if you have the luxury of being able to modify the application to populate the new counter.&amp;nbsp; Unfortunately, this luxury didn&amp;rsquo;t exist either.&amp;nbsp; So, what can we do?&lt;/p&gt;
&lt;p&gt;While working on another issue, I stumbled onto this little event, &lt;a href="http://msdn.microsoft.com/en-us/library/ee845503.aspx" target="_blank"&gt;218 &amp;ndash; ClientOperationCompleted&lt;/a&gt;, that is one of the WCF events emitted in &lt;a href="http://msdn.microsoft.com/en-us/library/ee530019.aspx" target="_blank"&gt;Analytic Tracing with ETW&lt;/a&gt;.&amp;nbsp; With this I am able to see outbound calls, and even filter the calls down to a particular service contract, process, or even destination address.&amp;nbsp; Here is the solution I came up with.&lt;/p&gt;
&lt;p&gt;Open the &lt;strong&gt;Windows Event Viewer&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Expand out &lt;strong&gt;Applications and Services Logs &amp;gt; Microsoft &amp;gt; Windows&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Right-click on &lt;strong&gt;Application Server-Applications&lt;/strong&gt; and select &lt;strong&gt;View &amp;gt; Show Analytic and Debug Logs&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Right-click on &lt;strong&gt;Analytics&lt;/strong&gt; under the &lt;strong&gt;Application Server-Applications&lt;/strong&gt; folder and select &lt;strong&gt;Enable Log&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/8206.image_5F00_761DC296.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/3021.image_5F00_thumb_5F00_4E77466C.png" width="383" height="334" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Right-click on &lt;strong&gt;Analytics&lt;/strong&gt; again and this time select&lt;strong&gt; Filter Current Log&amp;hellip;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In the &lt;strong&gt;Filter Current Log&lt;/strong&gt; dialog, enter &lt;strong&gt;218&lt;/strong&gt; for the &lt;strong&gt;Event ID&lt;/strong&gt; and click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/0285.image_5F00_54BE1CFA.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/5657.image_5F00_thumb_5F00_53E5B710.png" width="532" height="511" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;While this filters the events to those with ID 218, it still may not deliver what you want.&amp;nbsp; For example, after turning this on and executing a couple of WCF calls from my client, I noticed there were over 100 events (from other applications running on my machine).&amp;nbsp; I really only wanted to see the events from my client application I&amp;rsquo;m interested in.&amp;nbsp; If you drill into one of the events you can see the &lt;strong&gt;EventData&lt;/strong&gt; available to query on.&amp;nbsp; For example, &lt;strong&gt;Action&lt;/strong&gt;, &lt;strong&gt;ContractName&lt;/strong&gt;, &lt;strong&gt;Destination&lt;/strong&gt;, &lt;strong&gt;AppDomain&lt;/strong&gt; are ones I found useful.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/1460.image_5F00_2C3F3AE6.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/3010.image_5F00_thumb_5F00_57179EF8.png" width="260" height="163" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Having this information, it&amp;rsquo;s possible to write a query to provide exactly what I want.&lt;/p&gt;
&lt;p&gt;Right-click on &lt;strong&gt;Analytics&lt;/strong&gt; again and select&lt;strong&gt; Filter Current Log&amp;hellip;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In the &lt;strong&gt;Filter Current Log&lt;/strong&gt; dialog, click on the &lt;strong&gt;XML&lt;/strong&gt; tab.&lt;/p&gt;
&lt;p&gt;Click on the &lt;strong&gt;Edit query manually&lt;/strong&gt; checkbox so you can edit the query directly.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/8306.image_5F00_32861174.png"&gt;&lt;img style="display: inline; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-41-27-metablogapi/5460.image_5F00_thumb_5F00_1D285C0C.png" width="528" height="440" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Replace the query with your custom query.&amp;nbsp; Here are a couple of examples to get started.&lt;/p&gt;
&lt;p&gt;If you want to filter on outbound calls for a particular &lt;strong&gt;contract&lt;/strong&gt; name&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;lt;QueryList&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;nbsp; &amp;lt;Query Id="0" Path="Microsoft-Windows-Application Server-Applications/Analytic"&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Select Path="Microsoft-Windows-Application Server-Applications/Analytic"&amp;gt;*[System[(EventID=218)]] and *[EventData[(Data[@Name="ContractName"]="&lt;span style="background-color: #ffff00;"&gt;YourServiceContractName&lt;/span&gt;")]]&amp;lt;/Select&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;nbsp; &amp;lt;/Query&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;lt;/QueryList&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you want to filter on outbound calls for a particular &lt;strong&gt;process&lt;/strong&gt;&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;lt;QueryList&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;nbsp; &amp;lt;Query Id="0" Path="Microsoft-Windows-Application Server-Applications/Analytic"&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Select Path="Microsoft-Windows-Application Server-Applications/Analytic"&amp;gt;*[System[(EventID=218)]] and *[EventData[(Data[@Name="AppDomain"]="&lt;span style="background-color: #ffff00;"&gt;yourprocess.exe&lt;/span&gt;")]]&amp;lt;/Select&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;nbsp; &amp;lt;/Query&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Courier New; font-size: x-small;" size="2" face="Courier New"&gt;&amp;lt;/QueryList&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You get the idea.&amp;nbsp; You can adjust the query to meet your specific needs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10261367" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /></entry><entry><title>Why scriptLocation may not work when pointing to a proxy script file in your application config file.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2011/03/25/why-scriptlocation-may-not-work-when-pointing-to-a-proxy-script-file-in-your-application-config-file.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2011/03/25/why-scriptlocation-may-not-work-when-pointing-to-a-proxy-script-file-in-your-application-config-file.aspx</id><published>2011-03-25T18:38:06Z</published><updated>2011-03-25T18:38:06Z</updated><content type="html">&lt;p&gt;Consider this scenario: You have a .NET application that issues &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx" target="_blank"&gt;HttpWebRequests&lt;/a&gt; to a remote server.&amp;#160; You deploy this application to an environment that requires proxy servers be configured using a proxy script file (WPAD / PAC).&amp;#160; The solution is pretty simple.&amp;#160; In your app.config, you can add this configuration:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160; &amp;lt;system.net&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;defaultProxy useDefaultCredentials=&amp;quot;true&amp;quot;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;proxy usesystemdefault=&amp;quot;False&amp;quot; &lt;/font&gt;&lt;font size="2" face="Courier New"&gt;scriptLocation=&amp;quot;&lt;/font&gt;&lt;font size="2" face="Courier New"&gt;http://&amp;lt;IIS Server or IP Address&amp;gt;/wpad.dat&lt;/font&gt;&lt;font size="2" face="Courier New"&gt;&amp;quot; /&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/defaultProxy&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160; &amp;lt;/system.net&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;This, of course, assumes your script file is named wpad.dat and is hosted on your IIS server.&amp;#160; Adjust this value as appropriate for your environment.&lt;/p&gt;  &lt;p&gt;Arriving at this simple configuration recently proved to be a very challenging issue for me.&amp;#160; When I first tried this, my configuration looked like this:&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160; &amp;lt;system.net&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;defaultProxy useDefaultCredentials=&amp;quot;true&amp;quot;&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;proxy usesystemdefault=&amp;quot;False&amp;quot; scriptLocation=&amp;quot;&lt;font size="2" face="Courier New"&gt;http://&amp;lt;IIS Server or IP Address&amp;gt;/wpad.dat&lt;/font&gt;&lt;/font&gt;&lt;a href="http://150.123.236.121/wpad.dat"&gt;&lt;font size="2" face="Courier New"&gt;&lt;/font&gt;&lt;/a&gt;&lt;font size="2" face="Courier New"&gt;&amp;quot; &lt;font style="background-color: #ffff00"&gt;bypassonlocal=&amp;quot;True&amp;quot;&lt;/font&gt; /&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/defaultProxy&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;#160; &amp;lt;/system.net&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Notice, the only difference is the additional assignment of the &lt;strong&gt;bypassonlocal&lt;/strong&gt; attribute.&amp;#160; Which, at least in my experience, is a pretty common thing to do.&amp;#160; But, in this case, it didn’t work!&amp;#160; Why?&amp;#160; If you like debugging, read on…. &lt;/p&gt;  &lt;p&gt;I captured a &lt;a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=983b941d-06cb-4658-b7f6-3088333d062f&amp;amp;displaylang=en" target="_blank"&gt;netmon&lt;/a&gt; trace and what I found was that my application was trying to establish a direct TCP connection to the target URL rather than establishing a connection with the proxy server that my proxy script would return.&amp;#160; For example, &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-41-27-metablogapi/6318.image_5F00_6EC85A49.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-41-27-metablogapi/8176.image_5F00_thumb_5F00_5700FD16.png" width="826" height="106" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In a working scenario, you would expect to see something like this in a netmon trace.&amp;#160; Here, we establish a TCP connection with the proxy server, then issue an HTTP CONNECT on that connection, requesting a connection to the target URL, and finally setup SSL for secure transport.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-41-27-metablogapi/5430.image_5F00_47EA1E3C.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-41-27-metablogapi/3288.image_5F00_thumb_5F00_7FBC625F.png" width="827" height="90" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Going back to my failing scenario, I attached a debugger to my client and saw this exception – validating what I saw in the netmon trace.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-41-27-metablogapi/5023.image_5F00_6C9B35B3.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-41-27-metablogapi/3782.image_5F00_thumb_5F00_7A0148B9.png" width="823" height="69" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So, why is this happening?&amp;#160; I decided to look at the actual instance of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.webproxy.aspx" target="_blank"&gt;WebProxy&lt;/a&gt; that gets created when you configure .NET to use a proxy server and found a suspicious value for a ScriptEngine member.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-41-27-metablogapi/5367.image_5F00_240146E2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-41-27-metablogapi/3223.image_5F00_thumb_5F00_7131406D.png" width="822" height="266" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Yes, there should be a value there.&amp;#160; The ScriptEngine is what compiles and runs my proxy script identified in the &lt;strong&gt;scriptLocation&lt;/strong&gt; property above.&amp;#160; If there is not a ScriptEngine, then there can be no proxy.&amp;#160; If there is no proxy, then we try to connect directly to the target url, which is exactly what we see in the netmon trace above.&amp;#160; This is why we were not successful when trying to use the proxy script.&amp;#160; So, now the question becomes, why is the ScriptEngine null?&lt;/p&gt;  &lt;p&gt;If you think about it for a while, it starts to make some sense.&amp;#160; A proxy script has a single function that has to be implemented called &lt;strong&gt;FindProxyUrl&lt;/strong&gt;.&amp;#160; This function takes two parameters, one of which is the target url, &amp;lt;host&amp;gt;, that you ultimately want to connect to.&amp;#160; The implementation details for this function can obviously vary from one environment to the next.&amp;#160;&amp;#160; But, whether or not to connect &lt;em&gt;directly&lt;/em&gt; to the target url or go through one of the proxy servers that the script is programmed to return is ultimately a decision made in the script.&amp;#160; So, it is somewhat contradicting if you tell .NET to use a proxy script through the &lt;strong&gt;scriptLocation&lt;/strong&gt; property and also set the &lt;strong&gt;bypassonlocal&lt;/strong&gt; property.&amp;#160; &lt;/p&gt;  &lt;p&gt;After some collaboration with one of our Networking Escalation Engineers, it was pointed out to me that .NET will delete the ScriptEngine if it gets an instruction to set the &lt;strong&gt;bypassonlocal&lt;/strong&gt; property.&amp;#160; This happens whether you set &lt;b&gt;bypassonlocal&lt;/b&gt; to true or false.&amp;#160; Just the act of &lt;em&gt;setting&lt;/em&gt; &lt;b&gt;bypassonlocal&lt;/b&gt; results in the &lt;b&gt;WebProxy&lt;/b&gt; deleting the ScriptEngine. &lt;/p&gt;  &lt;p&gt;So, as I showed above, don’t use &lt;strong&gt;bypassonlocal&lt;/strong&gt; if you are also specifying the &lt;strong&gt;scriptLocation&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;If you want to learn more about how proxy scripts actually work, there is a nice article &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc300743.aspx" target="_blank"&gt;here&lt;/a&gt;.&amp;#160; It is dated, but still a very good read. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10146026" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term=".NET" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/-NET/" /><category term="system.net" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/system-net/" /></entry><entry><title>Optimizing Intermediary Services for throughput</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2010/03/22/optimizing-intermediary-services-for-throughput.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2010/03/22/optimizing-intermediary-services-for-throughput.aspx</id><published>2010-03-22T22:52:54Z</published><updated>2010-03-22T22:52:54Z</updated><content type="html">&lt;p&gt;I recently had the privilege of working with a couple of engineers (Naveed Zaheer and Manoj Kumar) in an internal lab setting to see how much throughput we could achieve through the &lt;a href="http://servicesengine.codeplex.com/" target="_blank"&gt;Managed Services Engine (MSE)&lt;/a&gt; and a downstream WCF service hosted in IIS.&lt;/p&gt;  &lt;p&gt;This post highlights some configuration settings that were applied during our work to achieve the results we were looking for.&amp;#160; The findings here are specific to the environment we were testing in, which was a controlled lab setting.&amp;#160; Any use of these settings should be tested in your own environment prior to placing them in a production environment.&lt;/p&gt;  &lt;p&gt;While these findings were specific to testing that was done for MSE, the findings here could be beneficial to anyone who has a service intermediary in their environment.&lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Environment&lt;/h1&gt;  &lt;p&gt;The figure below illustrates at a high level the environment we were testing in.&amp;#160; The users were simulated using 2 Visual Studio 2008 Test Agents simulating 100 users.&amp;#160; The MSE Server and IIS Target WCF Server were both dual-proc machines.&amp;#160; The target WCF Service was a singleton service and the method we were calling simply would sleep for 100 milliseconds and return.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/OptimizingManagedServicesEngineMSEforthr_F3D7/clip_image002_2.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/OptimizingManagedServicesEngineMSEforthr_F3D7/clip_image002_thumb.gif" width="636" height="207" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;MSE, for those not familiar with it, is a service intermediary that sits between a WCF service and its clients.&amp;#160; This intermediary piece virtualizes service endpoints for the clients to consume and brokers the calls to the physical WCF service.&amp;#160; For more information please refer to these resources.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=d0883acc-725a-45c4-860b-6a77e5af06cf" target="_blank"&gt;Service Virtualization – Executive Summary&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/info.aspx?na=40&amp;amp;p=1&amp;amp;SrcDisplayLang=en&amp;amp;SrcCategoryId=&amp;amp;SrcFamilyId=fe047afa-d472-4666-9b59-bbe398488112&amp;amp;u=http%3a%2f%2fmsdn.microsoft.com%2fen-us%2fmagazine%2fdd727511.aspx" target="_blank"&gt;MSDN Magazine: Service Virtualization With The Managed Services Engine&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=fe047afa-d472-4666-9b59-bbe398488112" target="_blank"&gt;An Introduction to Service Virtualization on the Microsoft .NET Platform&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;A CTP of the solution is available &lt;a href="http://servicesengine.codeplex.com/" target="_blank"&gt;here&lt;/a&gt;. This solution is also deliverable through &lt;a href="http://www.microsoft.com/microsoftservices/en/us/consulting.aspx" target="_blank"&gt;Microsoft Consulting Services&lt;/a&gt;.&lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Problem&lt;/h1&gt;  &lt;p&gt;Initial tests revealed that we could process ~ 55 requests/second.&amp;#160; This baseline number was concerning considering the user load of 100 users and the short duration (100 milliseconds) of the method being called. Simple and conservative math would tell you that even if it took a full second per call, we should be able to handle 100 requests / second.&lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Resolution&lt;/h1&gt;  &lt;h1&gt;&lt;/h1&gt;  &lt;h2&gt;Adjustment on the target WCF Service machine&lt;/h2&gt;  &lt;p&gt;The first thing we noticed was very limited throughput on the backend target WCF service server.&amp;#160; There was &lt;a href="http://msdn.microsoft.com/en-us/library/ms735114.aspx" target="_blank"&gt;WCF service throttling&lt;/a&gt; in place but increasing the settings didn’t improve the situation.&amp;#160; To simplify our testing, we eliminated the MSE server and went directly to the WCF Service hosted in IIS and still observed limited throughput.&amp;#160; To resolve this, we added the following configuration to the aspnet.config file.&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;lt;system.web&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;applicationPool maxConcurrentRequestsPerCPU=&amp;quot;5000&amp;quot; maxConcurrentThreadsPerCPU=&amp;quot;0&amp;quot; requestQueueLimit=&amp;quot;5000&amp;quot; /&amp;gt;      &lt;br /&gt;&amp;lt;/system.web&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;As a result, we saw the throughput on the target IIS Server increase to more than 4x what our baseline throughput was, achieving ~240 requests/second. Support for these settings in the aspnet.config file was added in .NET Framework 3.5 SP1.&amp;#160; The values we used for these settings are the default values for &lt;a href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;.NET Framework 4.0&lt;/a&gt;.&amp;#160; Further information on these settings are documented &lt;a href="http://msdn.microsoft.com/en-us/library/ee377050(BTS.10).aspx" target="_blank"&gt;here&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/dd560842(VS.100).aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The location of the aspnet.config file can be found here:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;32-bit: %WinDir%\Microsoft.NET\Framework\v2.0.50727\aspnet.config&lt;/li&gt;    &lt;li&gt;64-bit: %WinDir%\Microsoft.NET\Framework64\v2.0.50727\aspnet.config&lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;Adjustment on the MSE machine&lt;/h2&gt;  &lt;p&gt;Satisfied that we opened up the throughput to the target WCF service hosted in IIS, we re-introduced the MSE Server in the test cases and immediately saw end-to-end throughput go back down to close what our original baseline numbers were.&amp;#160; A dump of the MSE process further revealed that there were several threads doing this: &lt;/p&gt;  &lt;p&gt;&lt;sup&gt;&lt;font size="2" face="Courier New"&gt;&lt;/font&gt;&lt;/sup&gt;&lt;/p&gt;  &lt;p&gt;&lt;sup&gt;&lt;font size="2" face="Courier New"&gt;&lt;/font&gt;&lt;/sup&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;Child-SP RetAddr Call Site     &lt;br /&gt;000000004b1cb2a0 000007fef80ce018 System_ni!System.Net.AutoWebProxyScriptEngine.EnterLock      &lt;br /&gt;000000004b1cb2f0 000007fef80cc526 System_ni!System.Net.AutoWebProxyScriptEngine.GetProxies      &lt;br /&gt;000000004b1cb390 000007fef81228e7 System_ni!System.Net.WebProxy.GetProxiesAuto      &lt;br /&gt;000000004b1cb3f0 000007fef81226a4 System_ni!System.Net.ProxyScriptChain.GetNextProxy      &lt;br /&gt;000000004b1cb440 000007fef7c15342 System_ni!System.Net.ProxyChain+ProxyEnumerator.MoveNext      &lt;br /&gt;000000004b1cb4a0 000007fef7c1516d System_ni!System.Net.ServicePointManager.FindServicePoint      &lt;br /&gt;… stack truncated for brevity&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;The HTTP bindings in WCF, such as &lt;a href="http://msdn.microsoft.com/en-us/library/ms731361.aspx" target="_blank"&gt;basicHttpBinding&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/ms731299.aspx" target="_blank"&gt;wsHttpBinding&lt;/a&gt;, use the system wide proxy settings by default.&amp;#160; This was obviously restricting throughput in our scenario since so many threads were doing the same thing – which was, trying to acquire a proxy.&amp;#160; Checking the LAN settings revealed that the “Automatically detect settings” option was checked (see below).&amp;#160; Since our servers were all local, we unchecked this setting and re-ran the test and found that our throughput was back to ~ 240 requests/second.&amp;#160; After making this change, the overhead that MSE added to the full end-to-end call was almost negligible.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/OptimizingManagedServicesEngineMSEforthr_F3D7/clip_image004_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/OptimizingManagedServicesEngineMSEforthr_F3D7/clip_image004_thumb.jpg" width="244" height="104" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Removing the “Automatically detect settings” option system-wide is probably not the best solution.&amp;#160; There are other ways to achieve the same results.&amp;#160; One is to create a binding configuration and set the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.usedefaultwebproxy.aspx" target="_blank"&gt;UseDefaultWebProxy&lt;/a&gt; to false (see below).&amp;#160; This setting is true by default.&amp;#160; We tested this approach and got the same results as turning off the “Automatically detect settings” system wide setting. Therefore, our preference is to use this approach so as not to disrupt other applications that may be dependent on the system wide setting.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/OptimizingManagedServicesEngineMSEforthr_F3D7/clip_image006_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/OptimizingManagedServicesEngineMSEforthr_F3D7/clip_image006_thumb.jpg" width="244" height="207" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;There are other properties in the binding configuration that can be used to improve performance when a proxy is involved, such as the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.proxyaddress.aspx" target="_blank"&gt;ProxyAddress&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.httptransportbindingelement.bypassproxyonlocal.aspx" target="_blank"&gt;BypassProxyOnLocal&lt;/a&gt;. These settings were not tested in our case. However, if you have a proxy to consider and you want your connections to local services to not use the proxy, then setting these properties should result in similar performance improvements.&lt;/p&gt;  &lt;p&gt;Since resources, such as CPU, were still relatively low (less than 50% utilization) on our MSE and target servers, we wanted to see how much more we could handle. So, we increased the user load to 125 and saw no increase in overall throughput.&amp;#160; We increased it to 150 and again, saw no gain.&amp;#160; This pattern continued for up to 200 users.&amp;#160; Basically, we were seeing the same ~240 requests/second but this time, we had twice the number of users (200).&amp;#160; Why?&amp;#160; What is unique about 100 users in this scenario was the coincidence that 100 was the number of &lt;strong&gt;outbound connections&lt;/strong&gt; our MSE server was configured for (see below).&amp;#160; As you can see, we essentially exhausted all available connections through this service point.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/OptimizingManagedServicesEngineMSEforthr_F3D7/clip_image008_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/OptimizingManagedServicesEngineMSEforthr_F3D7/clip_image008_thumb.jpg" width="630" height="315" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To resolve this, we increased the connection limit in our configuration to 200 as shown here.&lt;/p&gt;  &lt;p&gt;&lt;font size="2" face="Courier New"&gt;&amp;lt;configuration&amp;gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;system.net&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;connectionManagement&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;add address = &amp;quot;*&amp;quot; maxconnection = &amp;quot;200&amp;quot; /&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/connectionManagement&amp;gt;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/system.net&amp;gt;      &lt;br /&gt;&amp;lt;/configuration&amp;gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;After doing this and re-running the test, we observed an overall throughput of ~ 430 requests / second with CPU leveling at about 65%.&lt;/p&gt;  &lt;p&gt;An important note here is that we did not see 2x the number of requests/second by doubling the user load.&amp;#160; At 100 users, we were handling ~ 240 requests/second.&amp;#160; At 200 users, we observed ~430 requests/second (a factor of ~1.8).&amp;#160; We also saw the MSE’s overall CPU utilization increase.&amp;#160; It is natural to see this trend however and the ratio will go lower with each increase.&amp;#160; When making adjustments like this you should carefully measure your application to make sure you’re achieving the optimal throughput.&amp;#160; Blindly increasing these values could have adverse effects if you’re not careful.&amp;#160; More information about connection management can be found &lt;a href="http://msdn.microsoft.com/en-us/library/ms998562.aspx#scalenetchapt10_topic9" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The last optimization suggestion that was noted was to consider using the &lt;a href="http://msdn.microsoft.com/en-us/library/ms229357(VS.80).aspx" target="_blank"&gt;server version&lt;/a&gt; of the CLR GC.&amp;#160; By default, the workstation version is used which is appropriate for single proc (sometimes up to dual proc) machines.&amp;#160; Since the MSE was running on a multi-proc machine, some performance gains “&lt;i&gt;could be realized&lt;/i&gt;” by switching to the server version.&amp;#160; We didn’t test this.&amp;#160; Nor did we see any concerns with memory pressure or CPU usage. This was just an observation.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9983292" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term="IIS/WAS" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/IIS_2F00_WAS/" /><category term=".NET" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/-NET/" /><category term="Managed Services Engine" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/Managed+Services+Engine/" /></entry><entry><title>Installing Windows Performance Toolkit (WPT)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2009/12/28/installing-windows-performance-toolkit-wpt.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2009/12/28/installing-windows-performance-toolkit-wpt.aspx</id><published>2009-12-28T06:23:53Z</published><updated>2009-12-28T06:23:53Z</updated><content type="html">&lt;p&gt;So, you want to install the &lt;a href="http://msdn.microsoft.com/en-us/performance/cc825801.aspx" target="_blank"&gt;Windows Performance Toolkit&lt;/a&gt;?&amp;#160; This is located in the Windows SDK which you can download &lt;a href="http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx" target="_blank"&gt;here&lt;/a&gt;.&amp;#160; If you’re like me, you may not want to blindly install the entire SDK.&amp;#160; The installer options that provide the WPT installers are the &lt;em&gt;‘Win32 Development Tools’&lt;/em&gt; and/or &lt;em&gt;‘.NET Development Tools’&lt;/em&gt; option under &lt;em&gt;‘Developer Tools’&lt;/em&gt; (see below). &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/InstallingWindowsPerformanceToolkitWPT_4D6/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/InstallingWindowsPerformanceToolkitWPT_4D6/image_thumb.png" width="464" height="397" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;After you have completed the installation of the SDK, then you should find your WPT installers in &lt;strong&gt;&amp;lt;WindowsSdkDir&amp;gt;\Bin&lt;/strong&gt; (see below).&amp;#160; Simply install the one that matches your platform.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/InstallingWindowsPerformanceToolkitWPT_4D6/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/InstallingWindowsPerformanceToolkitWPT_4D6/image_thumb_1.png" width="712" height="259" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9941497" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="Windows Performance Toolkit" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/Windows+Performance+Toolkit/" /></entry><entry><title>Self hosting an ADO.NET data service</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2009/08/31/self-hosting-an-ado-net-data-service.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2009/08/31/self-hosting-an-ado-net-data-service.aspx</id><published>2009-09-01T01:23:34Z</published><updated>2009-09-01T01:23:34Z</updated><content type="html">&lt;p&gt;All the samples I’ve seen for ADO.NET Data Services show hosting the service in IIS.&amp;#160; This is a natural choice, especially considering the rich hosting environment IIS provides and the tooling support provided by Visual Studio.&amp;#160; However, it is not the only option for hosting ADO.NET Data Services.&amp;#160; These services are just WCF services and therefore are capable of being hosted in any environment just like any other WCF service.&amp;#160; In this post, I will show how you can host an ADO.NET Data Service in a Windows Service.&lt;/p&gt;  &lt;p&gt;First, create the Windows Service project just like you normally would and add the service and process installers.&amp;#160; If you’re not sure how to do this, follow the steps explained &lt;a href="http://msdn.microsoft.com/en-us/library/9k985bc9(VS.80).aspx" target="_blank"&gt;here&lt;/a&gt;.&amp;#160; I named my Windows Service project &lt;em&gt;ADOServiceHost&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;In Solution Explorer, right-click the Windows Service project and select Add -&amp;gt; New Item.&amp;#160; Add an ADO.NET Entity Data Model and follow the steps to generate the model from an existing database.&amp;#160; I have the &lt;a href="http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=4004" target="_blank"&gt;AdventureWorksLT database for SQL Server 2005&lt;/a&gt; installed on my machine and I’m using that as the source for my model, which I named &lt;em&gt;AWDataModel&lt;/em&gt;.&amp;#160; You should now be able to explore the Entity Data Model by viewing the .edmx file that was created (see below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_thumb.png" width="590" height="460" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;In Solution Explorer, right-click the References folder in your Windows Service project and select Add Reference.&amp;#160; Add references to the System.Data.Services.dll and the System.ServiceModel.Web.dll assemblies.&lt;/p&gt;  &lt;p&gt;In Solution Explorer, right-click the Windows Service project and select Add –&amp;gt; New Item.&amp;#160; Add a C# Class which will be the class that is your data service.&amp;#160; I named mine &lt;em&gt;AWDataService.cs&lt;/em&gt;.&amp;#160; To make this an ADO.NET Data Service that exposes the Entity Data Model above, you have to derive from DataService&amp;lt;T&amp;gt; and you need to provide a static InitializeService method to specify things like entity access rules (see below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_thumb_1.png" width="662" height="373" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The last piece of code needed is the code to host the &lt;em&gt;AWDataService&lt;/em&gt; defined above.&amp;#160; In your Windows Service project, open the code for the service that the Windows Service template created by right-clicking on Service1.cs and selecting View Code (see below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_thumb_2.png" width="257" height="337" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;At the top of this file you will need to add a using clause to bring in the &lt;em&gt;System.Data.Services&lt;/em&gt; namespace.&amp;#160; Then, you can new up an instance of DataServiceHost and open it in the OnStart method.&amp;#160; Similarly, close the host in the OnStop method (see below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_thumb_3.png" width="596" height="415" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Build the solution.&lt;/p&gt;  &lt;p&gt;Open a Visual Studio.NET Command Prompt and navigate to the output folder for the Windows Service project.&amp;#160; Using InstallUtil.exe, install the Windows Service (see below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_thumb_4.png" width="587" height="96" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next, start the service.&amp;#160; You can do this from the service control panel services applet or from the command prompt.&amp;#160; The name of your service will be the &amp;quot;Display Name” you assigned it when you added the service installer above.&amp;#160; I named mine “AW .NET Data Service”.&amp;#160; To start from a command prompt, just use the net start command (see below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_14.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_thumb_6.png" width="592" height="97" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now that the service is running, you should be able to start interacting with the resources from your model using your browser (see below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_16.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/SelfhostinganADO.NETdataservice_F484/image_thumb_7.png" width="443" height="340" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9889588" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term="ADO.NET Data Services" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/ADO-NET+Data+Services/" /></entry><entry><title>ASP.NET Web Services to WCF services: Answering the question - Why?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2009/07/15/asp-net-web-services-to-wcf-services-answering-the-question-why.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2009/07/15/asp-net-web-services-to-wcf-services-answering-the-question-why.aspx</id><published>2009-07-15T20:31:00Z</published><updated>2009-07-15T20:31:00Z</updated><content type="html">&lt;P&gt;Windows Communication Foundation (WCF) is the platform for building distributed applications.&amp;nbsp; Developers are usually eager to adopt the latest of any technology because, well, it’s the latest.&amp;nbsp; There’s an element of coolness associated with building systems using the latest and greatest technology.&amp;nbsp; Management, on the other hand, often takes a different look at technology to understand what the “value” is that a technology will bring to the bottom line.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;So, in this post, I’m going to shine a light on why you would migrate to WCF from past technologies, such as ASP.NET Web Services.&lt;/P&gt;
&lt;H1&gt;Productivity&lt;/H1&gt;
&lt;P&gt;Developer productivity is something that translates directly to the bottom line and WCF nails this one on the head, especially with the Visual Studio 2008 release and even more with SP1 for Visual Studio 2008.&amp;nbsp; Thanks to the &lt;A href="http://msdn.microsoft.com/en-us/library/bb552363.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb552363.aspx"&gt;WCF Service Host&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/bb552364.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb552364.aspx"&gt;WCF Test Client&lt;/A&gt;, you can literally have a service running and tested in seconds (I can do it in about 10 seconds).&amp;nbsp; Of course, you have to make the service your own and add your business logic, but the tooling for WCF will give you a working service right out the box that is secure, interoperable, and provides better performance (see Performance below).&amp;nbsp; You can create an ASP.NET Web Service and test it in the browser in about the same amount of time, but your ASP.NET Web Service won’t come close to matching the features you get right away from a WCF Service.&amp;nbsp; I’ll cover many of these features in the sections to follow.&lt;/P&gt;
&lt;H1&gt;Security&lt;/H1&gt;
&lt;P&gt;In WCF, all the bindings (except basicHttpBinding) are secure by default.&amp;nbsp; This means that messages are encrypted, signed, and transmitted between authenticated parties, to thwart message tampering and information disclosure threats.&amp;nbsp; Secure message transfer is obtained through either &lt;A href="http://msdn.microsoft.com/en-us/library/ms729700.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms729700.aspx"&gt;transport security&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/ms733137.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms733137.aspx"&gt;message security&lt;/A&gt;, or combination of both.&amp;nbsp; &lt;A href="http://msdn.microsoft.com/en-us/library/ms731669.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms731669.aspx"&gt;Auditing of security events&lt;/A&gt; such as authentication and authorization is built in and can be leveraged by simply applying an &lt;A href="http://msdn.microsoft.com/en-us/library/ms731694.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms731694.aspx"&gt;auditing behavior&lt;/A&gt; to your service.&amp;nbsp; There is a wealth of security guidance and best practices for WCF that can be found &lt;A href="http://msdn.microsoft.com/en-us/library/ms731983.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms731983.aspx"&gt;here&lt;/A&gt; and &lt;A href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=WCFSecurity" target=_blank mce_href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=WCFSecurity"&gt;here&lt;/A&gt;.&amp;nbsp; In today’s hostile online world, more and more businesses are realizing the significant costs that can be incurred by insecure systems.&amp;nbsp; Since WCF provides security by default it helps mitigate security risks and the associated costs.&lt;/P&gt;
&lt;H1&gt;Interoperability&lt;/H1&gt;
&lt;P&gt;Providing an implementation of the WS-* specifications was one of the key drivers for WCF since it’s first release in .NET Framework 3.0.&amp;nbsp; In .NET Framework 3.5, this story got even better providing first class support for &lt;A href="http://msdn.microsoft.com/en-us/netframework/cc950529.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/netframework/cc950529.aspx"&gt;REST&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/bb412202.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb412202.aspx"&gt;Syndication&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/bb412173.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb412173.aspx"&gt;AJAX&lt;/A&gt; and providing data serialization to support things like JSON, POX, RSS, ATOM.&amp;nbsp; With all of these options, WCF enables you to expand the reach of your service, opening the door to potential new business opportunities.&amp;nbsp; &lt;/P&gt;
&lt;H1&gt;Performance&lt;/H1&gt;
&lt;P&gt;WCF offers &lt;A href="http://msdn.microsoft.com/en-us/library/bb310550.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/bb310550.aspx"&gt;better performance&lt;/A&gt;, about 25% – 50% faster than ASP.NET Web Services.&lt;/P&gt;
&lt;H1&gt;Features&lt;/H1&gt;
&lt;P&gt;WCF offers more &lt;A href="http://msdn.microsoft.com/en-us/library/ms729846.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms729846.aspx"&gt;hosting options&lt;/A&gt; unlike ASP.NET Web Services that require you host in IIS.&amp;nbsp; WCF services can be hosted in IIS, IIS7/WAS on Windows Server 2008, Windows Services, WinForms or WPF (good choice if your service is part of a peer-to-peer application).&amp;nbsp; Basically, any managed process can be a host for WCF Services.&lt;/P&gt;
&lt;P&gt;WCF offers more &lt;A href="http://msdn.microsoft.com/en-us/library/ms729350.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms729350.aspx"&gt;transports&lt;/A&gt; than just HTTP.&amp;nbsp; Out of the box you get bindings support for&amp;nbsp;HTTP, TCP, Named Pipes and MSMQ.&amp;nbsp; &lt;/P&gt;
&lt;H1&gt;Extensible Architecture&lt;/H1&gt;
&lt;P&gt;If for some reason WCF doesn’t offer something you need, then you can extend the architecture.&amp;nbsp; For example, if you need support for a protocol that’s not already provided, then you can create your own and just add it.&amp;nbsp; This &lt;A href="http://msdn.microsoft.com/en-us/library/ms751494.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms751494.aspx"&gt;UDP sample&lt;/A&gt; is an example.&lt;/P&gt;
&lt;P&gt;The release of .NET Framework 3.5 (looking at it through a WCF lens) is validation of the extensibility of WCF.&amp;nbsp; For example, in this release, programming WCF services for the web was the primary focus, allowing us to expose services through non-SOAP endpoints.&amp;nbsp; Here we saw the introduction of things like the &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webgetattribute.aspx"&gt;WebGetAttribute&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.webinvokeattribute.aspx"&gt;WebInvokeAttribute&lt;/A&gt; and the &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.aspx"&gt;WebHttpBehavior&lt;/A&gt; that are simply implementations of &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.ioperationbehavior.aspx"&gt;IOperationBehavior&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.aspx"&gt;IEndpointBehavior&lt;/A&gt;.&amp;nbsp; These interfaces are basically extensibility points that have existed since WCF’s initial release in .NET Framework 3.0.&lt;/P&gt;
&lt;P&gt;So, if for some reason you need to add new functionality that WCF doesn’t already provide, then you can rest assured that your ability to extend WCF to meet your needs is a real and supported path.&lt;/P&gt;
&lt;H1&gt;Integration&lt;/H1&gt;
&lt;P&gt;Leverage the investments made in previous technologies.&amp;nbsp; Management never likes to hear that you have to re-write everything before you can start to realize the benefits of a newer technology.&amp;nbsp; WCF offers a great integration story with respect to ASP.NET Web Services.&amp;nbsp; It also offers tools and support for integration with existing COM+ applications and MSMQ applications.&lt;/P&gt;
&lt;H1&gt;More Effective Troubleshooting&lt;/H1&gt;
&lt;P&gt;Should you need to troubleshoot a WCF service, then you have a wealth of features and tools you can take advantage of.&amp;nbsp; &lt;A href="http://msdn.microsoft.com/en-us/library/ms731859.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms731859.aspx"&gt;Message logging&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/ms730342.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms730342.aspx"&gt;tracing&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/ms735098.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms735098.aspx"&gt;performance counters&lt;/A&gt;, and &lt;A href="http://msdn.microsoft.com/en-us/library/ms735120.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms735120.aspx"&gt;WMI Support&lt;/A&gt; are available through simple configuration file changes and the &lt;A href="http://msdn.microsoft.com/en-us/library/ms732023.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/ms732023.aspx"&gt;Service Trace Viewer&lt;/A&gt; makes it very easy to interpret message logs and trace logs.&amp;nbsp; In most cases, you can effectively &lt;A href="http://msdn.microsoft.com/en-us/library/aa751795.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/aa751795.aspx"&gt;troubleshoot issues&lt;/A&gt; without having to resort to more heavy-handed approaches that typically require debugging tools be installed into production environments.&lt;/P&gt;
&lt;H1&gt;Return On Investment (ROI)&lt;/H1&gt;
&lt;P&gt;The decision to adopt a new technology has to offer the business a return on the investment – otherwise, why do it.&amp;nbsp; Hopefully by now, you’ve realized that the investment is relatively small with respect to WCF because it does so much for you.&amp;nbsp; Management often wants to know that the decision to adopt a technology is one that will be backed by the vendor providing it.&amp;nbsp; WCF is that technology moving forward.&amp;nbsp; Technologies that preceded WCF (.NET Remoting, ASP.NET Web Services, Messaging, COM+) will continue to be supported.&amp;nbsp; However, the investment being made moving forward will be in WCF.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9834481" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term=".NET" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/-NET/" /></entry><entry><title>WCF Instancing, Concurrency, and Throttling – Part 3</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2009/06/26/wcf-instancing-concurrency-and-throttling-part-3.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2009/06/26/wcf-instancing-concurrency-and-throttling-part-3.aspx</id><published>2009-06-26T22:06:00Z</published><updated>2009-06-26T22:06:00Z</updated><content type="html">&lt;P&gt;In part &lt;A href="http://blogs.msdn.com/rickrain/archive/2009/06/15/wcf-instancing-concurrency-and-throttling-part-1.aspx" mce_href="http://blogs.msdn.com/rickrain/archive/2009/06/15/wcf-instancing-concurrency-and-throttling-part-1.aspx"&gt;1&lt;/A&gt; and &lt;A href="http://blogs.msdn.com/rickrain/archive/2009/06/17/wcf-instancing-concurrency-and-throttling-part-2.aspx" mce_href="http://blogs.msdn.com/rickrain/archive/2009/06/17/wcf-instancing-concurrency-and-throttling-part-2.aspx"&gt;2&lt;/A&gt;, I talked about instancing and concurrency. In this post, the 3&lt;SUP&gt;rd&lt;/SUP&gt; and final post on this subject, I’m going to show an example of how you can use throttling to achieve optimal throughput for a service. But first…&lt;/P&gt;
&lt;P&gt;&lt;B&gt;What is throttling?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Throttling is a way for you to limit (“throttle”) the throughput of your service so that resources (memory, CPU, network, etc.) are kept at healthy levels. How you throttle a service will depend largely on the resources a particular machine has. For example, a service deployed to a machine with 1 processor, 2G RAM, and &lt;A href="http://en.wikipedia.org/wiki/Fast_Ethernet" mce_href="http://en.wikipedia.org/wiki/Fast_Ethernet"&gt;Fast Ethernet&lt;/A&gt; would be throttled less aggressively if deployed to a machine with 4 processors, 16G RAM, and &lt;A href="http://en.wikipedia.org/wiki/Gigabit_Ethernet" mce_href="http://en.wikipedia.org/wiki/Gigabit_Ethernet"&gt;Gigabit Ethernet&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;&lt;B&gt;How is throttling achieved?&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;In WCF, throttling is achieved by applying the &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspx"&gt;ServiceThrottlingBehavior&lt;/A&gt; to the service. This service behavior provides 3 knobs (&lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.aspx"&gt;MaxConcurrentCalls&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentinstances.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentinstances.aspx"&gt;MaxConcurrentInstances&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentsessions.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentsessions.aspx"&gt;MaxConcurrentSessions&lt;/A&gt;) that can be dialed up/down. I’m going to assume you are already familiar with these. If not, then please review these links before proceeding.&lt;/P&gt;
&lt;P&gt;For this topic of discussion, I’m going to use the same service I described in &lt;A href="http://blogs.msdn.com/rickrain/archive/2009/06/17/wcf-instancing-concurrency-and-throttling-part-2.aspx" mce_href="http://blogs.msdn.com/rickrain/archive/2009/06/17/wcf-instancing-concurrency-and-throttling-part-2.aspx"&gt;part 2&lt;/A&gt;, which simulated some long-running work by sleeping for 5 seconds. The service is PerCall/Multiple Concurrency and hosted in a console application with one endpoint using WsHttpBinding default settings. I’m also going to be using the &lt;A href="http://msdn.microsoft.com/en-us/library/ms182571.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms182571.aspx"&gt;load testing&lt;/A&gt; tools that are part of the &lt;A href="http://msdn.microsoft.com/en-us/library/ms182409.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms182409.aspx"&gt;Visual Studio Test Edition&lt;/A&gt; to see how my throttling adjustments impact the throughput of the service. My test harness is going to simulate 100 concurrent users using a constant load pattern for a period of 1 minute. Each simulated user will instantiate a proxy to the service and then proceed to call the service repeatedly using that proxy. In other words, I’m not incurring the overhead of recreating the client proxy and re-negotiating the security context for each and every call. I’m only incurring this overhead once for each of the 100 users.&lt;/P&gt;
&lt;P&gt;
&lt;TABLE border=1 cellSpacing=0 cellPadding=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H1&gt;Load Test 1&lt;/H1&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H2&gt;Throttle Settings&lt;/H2&gt;
&lt;P&gt;None. For this first test, I’m just going to see what results I get without applying any throttling behaviors. &lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H2&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image001_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image001_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image001 border=0 alt=clip_image001 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image001_thumb.png" width=741 height=67 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image001_thumb.png"&gt;&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image002_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image002_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image002 border=0 alt=clip_image002 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image002_thumb.png" width=468 height=160 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image002_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image003_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image003_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image003 border=0 alt=clip_image003 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image003_thumb.png" width=434 height=154 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image003_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H2&gt;Conclusion&lt;/H2&gt;
&lt;P&gt;Right away there are a few things that catch my eye.&lt;/P&gt;
&lt;P&gt;1. Total Tests were only 106. Considering that I had 100 users, that’s not a very impressive number (about 1 test per user).&lt;/P&gt;
&lt;P&gt;2. The average test time for the 60 second run was 32.4 seconds. Again, since my service should only take about 5 seconds to return a result, this too is unacceptable.&lt;/P&gt;
&lt;P&gt;3. The average test time grew as the test progressed. At 55 seconds into the test, we measured 51.9 seconds as the average!&lt;/P&gt;
&lt;P&gt;4. Finally, the processor wasn’t working very hard at all (less than 20% for most of the test).&lt;/P&gt;
&lt;P&gt;If you don’t apply any throttling behavior to your service, then you essentially get WCF’s default throttling settings, which are&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image004_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image004_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image004 border=0 alt=clip_image004 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image004_thumb.png" width=252 height=103 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image004_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Considering these numbers, the results above begin to make some sense. First, look at the MaxConcurrentSessions setting. It defaults to 10. However, our test harness is simulating 100 concurrent users. Since our binding is a binding with session, we’re limited to just 10 concurrent users. Since each test takes about 5 seconds to run, a single user can only perform about 12 calls over a 60 second period. Multiply 12 (calls a user can make per 60 second period) by 10 (MaxConcurrentSessions) and you get 120 tests total. Now, you have to remember that WsHttpBinding is a secure binding so there is the initial overhead of establishing the security context. Plus, there is additional overhead beyond the 5 seconds we sleep during the service call. So, the number of calls a single user can make in a 60 second period is actually a little less than 12. As we see on this first run, it was about 10.6 calls over a 60 second period. So, our 106 Total Tests is the result of our 10 concurrent users running about 10.6 tests during the 60 second period.&lt;/P&gt;
&lt;P&gt;So, for the next run, we need to increase the MaxConcurrentSessions.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE border=1 cellSpacing=0 cellPadding=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H1&gt;Load Test 2&lt;/H1&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H2&gt;Throttle Settings&lt;/H2&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image005_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image005_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image005 border=0 alt=clip_image005 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image005_thumb.png" width=244 height=95 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image005_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image006_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image006_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image006 border=0 alt=clip_image006 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image006_thumb.png" width=741 height=71 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image006_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image007_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image007_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image007 border=0 alt=clip_image007 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image007_thumb.png" width=416 height=136 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image007_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image008_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image008_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image008 border=0 alt=clip_image008 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image008_thumb.png" width=436 height=138 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image008_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H2&gt;Conclusion&lt;/H2&gt;
&lt;P&gt;Some improvement.&lt;/P&gt;
&lt;P&gt;1. Total tests increased from 106 to 164.&lt;/P&gt;
&lt;P&gt;2. Average test time improved from 32.4 seconds to 26.9 seconds. Still, for a service call that should take just over 5 seconds, this is unacceptable. Our goal is to get this number as close as possible to 5 seconds. &lt;/P&gt;
&lt;P&gt;3. The average test time is still growing.&lt;/P&gt;
&lt;P&gt;4. The processor is still not working very hard. Interestingly though, our processor did level out nicely on this run as compared to the last run. This mainly has to do with the fact that the overhead of establishing the security context for all users was incurred at the beginning of the test, which is why you see the first recording of processor time being higher (about 75%) in this run.&lt;/P&gt;
&lt;P&gt;What these results show is that we’re being limited by the number of concurrent calls (16) our service allows. Yes, we’re allowing 100 users at a time through the channel layer. However, only 16 users are getting their calls serviced because we’re limited to 16 concurrent calls. MaxConcurrentInstances does not apply in this case because for PerCall services, WCF will take the lower of MaxConcurrentCalls and MaxConcurrentInstances and use that number for both. So, doing the math of 16 users making approximately 10.x calls per 60 second period, our result of 164 total tests makes sense.&lt;/P&gt;
&lt;P&gt;Since memory and processor are extremely low, I’ll bump these settings up to 100 each and rerun the test.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;
&lt;TABLE border=1 cellSpacing=0 cellPadding=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H1&gt;Load Test 3&lt;/H1&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;P&gt;&lt;B&gt;Throttle Settings&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image009_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image009_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image009 border=0 alt=clip_image009 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image009_thumb.png" width=261 height=102 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image009_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image010_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image010_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image010 border=0 alt=clip_image010 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image010_thumb.png" width=749 height=71 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image010_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image011_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image011_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image011 border=0 alt=clip_image011 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image011_thumb.png" width=489 height=200 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image011_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image012_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image012_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image012 border=0 alt=clip_image012 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image012_thumb.png" width=487 height=172 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image012_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top width=638&gt;
&lt;H2&gt;Conclusion&lt;/H2&gt;
&lt;P&gt;Much better performance on this run.&lt;/P&gt;
&lt;P&gt;1. Total tests increased from 164 to 571.&lt;/P&gt;
&lt;P&gt;2. Average test time improved from 26.9 seconds to 9.92 seconds.&lt;/P&gt;
&lt;P&gt;3. The average test time is now trending downward. In fact, the last recording at the 1 minute mark showed an average test time of 5.29 seconds.&lt;/P&gt;
&lt;P&gt;4. The processor is doing much more. However, it stays well below 50% for most of the test.&lt;/P&gt;
&lt;P&gt;I’m much more pleased with these results. We’re getting a lot more throughput with these settings. You have to look more at the numbers near the end of the test to realize this because of the overhead we’re experiencing of 100 users all hitting the service at exactly the same time. However, once things get going the indicators start to level off nicely. Or do they? Looking at the processor it looks like it is growing. I suspect it is because of the short duration of the test though. So, I reran the test again for a period of &lt;STRONG&gt;2 minutes&lt;/STRONG&gt; just to verify that it didn’t continue to grow. Here’s the results of that test run.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image013_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image013_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image013 border=0 alt=clip_image013 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image013_thumb.png" width=760 height=70 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image013_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image014_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image014_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image014 border=0 alt=clip_image014 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image014_thumb.png" width=479 height=172 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_C63D/clip_image014_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Suspicion verified - I’m satisfied with that! Not only does the processor level off nicely at about 50%, but as you should expect, my Average Test Time improved from 9.92 seconds to 6.77 seconds.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Final Thoughts&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The purpose here was simply to show how you can influence the throughput of your service by making some simple throttling adjustments. Every service will be different though and the use cases for each application load test will be unique. So, don’t assume these settings would work the same for your service. Also, my test scenario was very basic – constant load and repeated synchronous calls from the client. It might be more realistic to have a step up pattern whereby the number of users increased gradually up to 100. It might also be more likely to have some think times in between each call to the service.&amp;nbsp; I also ran all this on one machine which is not typically representative of a production environment.&amp;nbsp; The point is, when you are trying to determine your throughput, you need to consider a specific use case and then configure your test settings accordingly.&lt;/P&gt;
&lt;P&gt;The last thing I want to mention is that my test harness did not simulate a multi-threaded client. Yet, my service is capable of multiple concurrency. If I were to change the test to simulate a multi-threaded client where the client makes 2 concurrent calls on different threads, what throttling settings would you need to adjust? The answer is MaxConcurrentCalls and MaxConcurrentInstances. You would need to increase these to 200 to allow all 100 users to make 2 concurrent calls. Of course, you would also want to test this to see if you get the results you expect and that your processor load stays healthy. If not, you can “throttle” these back a bit until you reach the numbers you want. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9805800" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term="Visual Studio" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/Visual+Studio/" /></entry><entry><title>WCF Instancing, Concurrency, and Throttling – Part 2</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2009/06/17/wcf-instancing-concurrency-and-throttling-part-2.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2009/06/17/wcf-instancing-concurrency-and-throttling-part-2.aspx</id><published>2009-06-17T17:19:46Z</published><updated>2009-06-17T17:19:46Z</updated><content type="html">&lt;p&gt;From a developers perspective, code is either &lt;a href="http://en.wikipedia.org/wiki/Thread-safe"&gt;thread-safe&lt;/a&gt; or it is not. WCF will assume your service is not thread-safe unless you tell it otherwise by applying the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx"&gt;ConcurrencyMode&lt;/a&gt; behavior. Your options for concurrency are Single (default), Multiple, and Reentrant. Depending on your implementation details for achieving thread-safety, you can really open up the throughput of your service by setting the ConcurrencyMode to Multiple or Reentrant.&lt;/p&gt;  &lt;p&gt;The options for concurrency are, for the most part, self explanatory. So, please follow the links above if this is a concept new to you. In this post, I’m going to discuss a couple of specific scenarios; Reentrant Services and PerCall/Multi-Threaded Services&lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;Reentrant Services&lt;/h1&gt;  &lt;p&gt;Making your service reentrant constrains the runtime to allow only one thread of execution on your service at any point in time (that is, it is still single-threaded). However, if your service operation makes an outbound WCF call then the lock on the instance context will be released, allowing another message to be dispatched to your service while the outbound call occurs. When the outbound call completes (returns back to your service), its thread will block until it can re-acquire the lock on the instance context.&lt;/p&gt;  &lt;p&gt;The conditions for which reentrant concurrency applies are&lt;/p&gt;  &lt;p&gt;1. your service is single-threaded, and&lt;/p&gt;  &lt;p&gt;2. your service makes calls to other WCF services downstream &lt;u&gt;OR&lt;/u&gt; your service calls back to the client through a &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.callbackcontract.aspx"&gt;callback contract&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If either of these conditions don’t apply to your service, then you would not gain anything by making your service reentrant.&lt;/p&gt;  &lt;h1&gt;&amp;#160;&lt;/h1&gt;  &lt;h1&gt;PerCall / Multi-Threaded Services (over a binding with session)&lt;/h1&gt;  &lt;p&gt;For PerCall services, every message results in a new instance of your service, so generally there is not a concurrency issue unless you are accessing a shared resource between instances. However, there is a scenario where setting ConcurrencyMode to Multiple on a PerCall service can increase throughput to your service if the following conditions apply:&lt;/p&gt;  &lt;p&gt;1. The &lt;strong&gt;client is multi-threaded&lt;/strong&gt; and is making calls to your service from multiple threads &lt;strong&gt;using the same proxy&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;2. The binding between the client and the service is &lt;strong&gt;a binding that has session&lt;/strong&gt; (for example, netTcpBinding, wsHttpBinding w/Reliable Session, netNamedPipeBinding, etc.).&lt;/p&gt;  &lt;p&gt;If these conditions apply and all you do is set your InstanceContextMode to PerCall, leaving the ConcurrencyMode to its default value (Single), then your multi-threaded client will not get the expected performance benefit of making concurrent calls to your service because there is a lock on the session in the channel layer. To illustrate, consider the following service code. This service just simply returns back some data from the service side to the client. One piece of data to notice is the MsgReceivedTimeStamp, which will indicate when the service instance actually receives the message. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_8326/clip_image002_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_8326/clip_image002_thumb.jpg" width="644" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next, assume we have a client application that caches a proxy to be used by multiple threads. If this client were to call the service simultaneously on 3 different threads using a &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx"&gt;BackgroundWorker&lt;/a&gt;, then the total response time would be about 15 seconds (5 seconds for each call). Output from such an application might look like this.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_8326/clip_image004_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_8326/clip_image004_thumb.jpg" width="566" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Clearly, this is not the behavior a client-side developer would expect. The results here are not any different than if we were to make 3 calls to the service sequentially. What we would like to see is all 3 threads dispatched at the same time such that the total response time is about 5 seconds (not 15 seconds). To achieve this, we can set the ConcurrencyMode to Multiple as shown here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_8326/clip_image006_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_8326/clip_image006_thumb.jpg" width="644" height="333" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Running the client against the new service will yield the results we’re looking for. That is, all 3 calls were dispatched to the service at roughly the same time and we still have a unique InstanceContext (or service instance) for each message as shown here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_8326/clip_image008_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_8326/clip_image008_thumb.jpg" width="568" height="484" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Writing thread-safe code and applying the correct ConcurrencyMode can result in significantly improved throughput for your service. In the next post, I’ll talk about how and why you can throttle your service.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9769461" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /></entry><entry><title>WCF Instancing, Concurrency, and Throttling – Part 1</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2009/06/15/wcf-instancing-concurrency-and-throttling-part-1.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2009/06/15/wcf-instancing-concurrency-and-throttling-part-1.aspx</id><published>2009-06-16T00:30:12Z</published><updated>2009-06-16T00:30:12Z</updated><content type="html">&lt;p&gt;Building distributed systems using WCF has so many advantages. One of the things I hear consistently from customers is that it allows them to focus their development efforts on writing business logic code and less on having to write “plumbing” code. Still, writing effective services requires that we think about things like service level agreements (SLA) and from a developer’s perspective this often raises questions like…&lt;/p&gt;  &lt;p&gt;Under what circumstances should instances of the service be created?&lt;/p&gt;  &lt;p&gt;How long should a particular instance exist?&lt;/p&gt;  &lt;p&gt;What level of concurrency (single-threaded or multi-threaded) needs to be supported?&lt;/p&gt;  &lt;p&gt;What are the scalability requirements for the service?&lt;/p&gt;  &lt;p&gt;Does the service need to manage state between calls?&lt;/p&gt;  &lt;p&gt;Building services that address these questions are only part of the solution. Informing WCF how our service should be hosted to leverage these implementation details is another. For example, if we’ve built our service such that the operations are multi-threaded, then we will want WCF to host our service differently than if it were a single-threaded service. WCF provides behaviors that we can apply declaratively in our code to customize how our service is hosted. These are &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.instancecontextmode.aspx"&gt;InstanceContextMode&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.concurrencymode.aspx"&gt;ConcurrencyMode&lt;/a&gt; and both are applied via the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.aspx"&gt;ServiceBehaviorAttribute&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;InstanceContextMode determines when an instance of your service is created and for how long it will exist. Your choices are PerCall, PerSession, or Single. A common question I hear often is: “Why would you ever want to use PerCall instancing and incur the overhead of creating a service for every message?” For which I usually reply: “What overhead?”. True, a new instance of your service class is recreated for every message. However, that equates to just creating an instance of a class. Unless your service class has some expensive initialization code in the constructor (for example, querying a database or building large object graphs in memory), the PerCall instancing model is very efficient. The overhead of building up the Channel layer (for example, listening on endpoints) and Service Model layer (for example, applying behaviors to customize the runtime) occurs one time for each &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehost.aspx"&gt;ServiceHost&lt;/a&gt; instance. The following diagram illustrates this idea.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_E80F/clip_image002_2.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/WCFInstancingConcurrencyandThrottlingPar_E80F/clip_image002_thumb.jpg" width="644" height="373" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So, when would you choose one instancing mode over another? That depends on the requirements for your service. However, here are some (not all) common things to consider.&lt;/p&gt;  &lt;h1&gt;PerCall&lt;/h1&gt;  &lt;p&gt;You may consider this instancing mode in these circumstances. &lt;/p&gt;  &lt;p&gt;- If your service is stateless&lt;/p&gt;  &lt;p&gt;- If your service has light-weight initialization code (or none at all).&lt;/p&gt;  &lt;p&gt;- If your service is single threaded.&lt;/p&gt;  &lt;h1&gt;PerSession (default)&lt;/h1&gt;  &lt;p&gt;You may consider this instancing mode in these circumstances. &lt;/p&gt;  &lt;p&gt;- If your service needs to maintain some state between calls from the same client.&lt;/p&gt;  &lt;p&gt;- If your service has light-weight initialization code (or none at all). Even though you are only getting a new instance for each client proxy, you still want to be careful about having expensive initialization code in a constructor.&lt;/p&gt;  &lt;p&gt;By default, WCF will use PerSession provided the client and service are communicating over a binding that supports session. Otherwise, the service will behave as a PerCall service. Which raises the question: How can a developer place a constraint on the service such that the service’s endpoints support sessions? The answer is in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicecontractattribute.sessionmode.aspx"&gt;ServiceContractAttribute.SessionMode&lt;/a&gt; property that can be applied to your service contract. Using this property you can “require” sessions for your service. If any endpoints configured for your service don’t support session then the service will fail to start. This is your way, as a developer, to place a constraint on the administrator, to configure your service with endpoints that support your requirements (sessions in this case). Be advised that there are 4 different &lt;a href="http://msdn.microsoft.com/en-us/library/ms733040.aspx"&gt;types of sessions in WCF&lt;/a&gt; and setting this property requires only that the binding support one of these types of session. It does not let you define the type of session you require.&lt;/p&gt;  &lt;h1&gt;Single&lt;/h1&gt;  &lt;p&gt;You may consider this instancing mode in these circumstances. &lt;/p&gt;  &lt;p&gt;- If your service needs to maintain some state between clients.&lt;/p&gt;  &lt;p&gt;- Your service has expensive initialization code.&amp;#160; That is, initializing for every client (PerSession) or every call (PerCall) would be too costly.&lt;/p&gt;  &lt;p&gt;- You don’t anticipate needing to &lt;a href="http://en.wikipedia.org/wiki/Scale_out#Scale_horizontally_.28scale_out.29"&gt;scale out&lt;/a&gt; your service.&lt;/p&gt;  &lt;p&gt;If your service will be deployed in a server farm, then be sure to review the &lt;a href="http://msdn.microsoft.com/en-us/library/ms730128.aspx"&gt;WCF Load Balancing&lt;/a&gt; guidance for scenarios that may apply to your service.&lt;/p&gt;  &lt;p&gt;In the next posting, I will say a few things about Concurrency.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9756018" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /></entry><entry><title>Making asynchronous service calls from a WinForm client</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2009/03/18/making-asynchronous-service-calls-from-a-winform-client.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2009/03/18/making-asynchronous-service-calls-from-a-winform-client.aspx</id><published>2009-03-18T19:35:00Z</published><updated>2009-03-18T19:35:00Z</updated><content type="html">&lt;P&gt;It’s well known that long blocking calls in the main user interface (UI) thread of a WinForm client application should be avoided. As users, we certainly get annoyed when the application stops responding. Yet, even today, we see this over-and-over again in so many applications. When making a call to a service the amount of time the call takes to complete can be unpredictable. Even if your service responds immediately, you have the potential for network latency, authentication hand-shaking, etc. to extend the time for a complete end-to-end call. Calling services in an asynchronous fashion solves this problem. In this post I’m going to show an easy way to make an asynchronous call to a service and how to use some user interface (UI) best practices for handling the result of such a call.&lt;/P&gt;
&lt;P&gt;I’m going to start with just an out-of-the-box WCF service using the WCF Service Library template and make one small change (sleep for 5 seconds) in the GetData method to simulate a long running call.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image001_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image001_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image001 border=0 alt=clip_image001 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image001_thumb.png" width=526 height=152 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image001_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Next, I’ll create a very basic WinForm client project. The UI for this client will allow me to select data to send to the GetData method and will show the results in the ListBox control. There are two buttons that I will use to invoke the service; one for a synchronous call and another for an asynchronous call.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image002_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image002_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image002 border=0 alt=clip_image002 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image002_thumb.png" width=361 height=220 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image002_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I also added a NotifyIcon control to my form which you don’t see. This is what I’m going to use to notify the user that the call has completed. It will display a notification in the Windows taskbar (much like the way Windows Update notifies you when updates are available for Windows).&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image003_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image003_2.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=clip_image003 border=0 alt=clip_image003 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image003_thumb.png" width=163 height=73 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image003_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Since I’m using the NotifyIcon, I’ll go ahead and add an icon as a resource to the WinForm client project. You can do this easily by double-clicking the Resources node in Solution Explorer.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image004_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image004_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image004 border=0 alt=clip_image004 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image004_thumb.png" width=318 height=244 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image004_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This will open the Resource Designer where you can select to add a new icon from the toolbar.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image005_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image005_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image005 border=0 alt=clip_image005 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image005_thumb.png" width=273 height=181 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image005_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The icon designer will appear and you can design your icon(s) as I’ve done here.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image006_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image006_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image006 border=0 alt=clip_image006 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image006_thumb.png" width=281 height=172 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image006_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Once that is complete, simply set the Icon property in your NotifyIcon to the icon you created. You may also want to set the Balloon Tip Title like I’ve done here or you can set it at runtime later if you prefer.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image007_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image007_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image007 border=0 alt=clip_image007 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image007_thumb.png" width=312 height=193 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image007_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;When I add my service reference I’ll be using an “Advanced” option to generate asynchronous methods to call to the service. This feature is available if you click on the Advanced… button in the Add Service Reference dialog.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image008_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image008_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image008 border=0 alt=clip_image008 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image008_thumb.png" width=539 height=441 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image008_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;When you do this, you will be given the opportunity to have SvcUtil generate asynchronous operations for you as part of the client proxy. IMO, this option should be checked anyway and not tucked away behind an “Advanced” button, but that’s just me…&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image009_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image009_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image009 border=0 alt=clip_image009 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image009_thumb.png" width=461 height=148 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image009_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I’ll start by adding the code for the synchronous call to the service behind the “Call Service Synchronously” button.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image010_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image010_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image010 border=0 alt=clip_image010 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image010_thumb.png" width=631 height=130 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image010_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;When you run the client and press the button you will eventually (after about 5 seconds) see the results displayed in the ListBox control. If during this time you try to move the form or interact with other controls on the form you won’t be able to because the client UI will be blocked while the call completes.&lt;/P&gt;
&lt;P&gt;A solution to this annoying situation is just to call the service asynchronously as shown here in the code behind the “Call Service Asynchronously” button. The work done by svcutil.exe when generating the proxy makes this a trivial task using the GetDataAsync method to call our service and the GetDataCompleted event handler to retrieve the results.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image011_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image011_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image011 border=0 alt=clip_image011 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image011_thumb.png" width=892 height=113 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image011_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;All that remains now is to use the NotifyIcon control to notify the user when the call has completed. If we didn’t encounter an error then I’m going to make the balloon tip icon an “information” icon and show the result in the text. I’ll also add it to the ListBox control on our main form. Otherwise, I’ll show an “error” icon and the error message returned.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image012_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image012_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image012 border=0 alt=clip_image012 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image012_thumb.png" width=649 height=384 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image012_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Finally, I’m going to wire up the click event for the icon itself where I will stop showing the icon in the taskbar and bring focus to the main form. You may want to do the same for the BalloonTipClicked event, or associate a ContextMenu with the control and drive other behaviors from it. The possibilities are abundant for you to explore.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image013_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image013_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image013 border=0 alt=clip_image013 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image013_thumb.png" width=623 height=116 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image013_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The last thing to do now is test it. I’m going to run my application, invoke the service asynchronously. In doing so, I will still be able to interact with the form, move it around on my desktop, etc. because the main UI thread is not blocked.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image014_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image014_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image014 border=0 alt=clip_image014 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image014_thumb.png" width=358 height=220 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image014_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;When the results are ready, I will get a nice notification in the taskbar like this and the data will be in my ListBox on my main form. After 10 seconds the balloon tip will go away but the icon will stay in the taskbar until I click on it. At which time, the main form will be activated and the notification icon disabled.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image015_2.png" mce_href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image015_2.png"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; DISPLAY: inline; BORDER-TOP: 0px; BORDER-RIGHT: 0px" title=clip_image015 border=0 alt=clip_image015 src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image015_thumb.png" width=345 height=101 mce_src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/MakingasynchronousservicecallsfromaWinFo_A0BA/clip_image015_thumb.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9487253" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term=".NET" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/-NET/" /></entry><entry><title>XmlSerializer Faults</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2008/10/03/xmlserializer-faults.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2008/10/03/xmlserializer-faults.aspx</id><published>2008-10-03T19:44:22Z</published><updated>2008-10-03T19:44:22Z</updated><content type="html">&lt;p&gt;There's a new WCF feature in the .NET Framework 3.5 SP1 release that I just recently learned about.&amp;#160; It has to do with serialization of SOAP faults when using the XmlSerializer for your service rather than the default DataContractSerializer.&lt;/p&gt;  &lt;p&gt;Consider this scenario: You have elected to use the XmlSerializer for your service because of some rather complicated schema that the DataContractSerializer doesn't support.&amp;#160; You also have some rather complicated schema used to define fault contracts in your service.&amp;#160; Prior to SP1, WCF would serialize any faults you returned from your service using the DataContractSerializer rather than the XmlSerializer even though you applied the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.xmlserializerformatattribute.aspx" target="_blank"&gt;XmlSerializerFormatAttribute&lt;/a&gt; to your service, potentially breaking the serialization between your service and client(s).&lt;/p&gt;  &lt;p&gt;In SP1, support for &lt;a href="http://msdn.microsoft.com/en-us/library/cc681334.aspx" target="_blank"&gt;XmlSerializer Faults&lt;/a&gt; was added via the &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.xmlserializerformatattribute.supportfaults.aspx" target="_blank"&gt;SupportFaults&lt;/a&gt; property.&amp;#160; There is a link to a sample in the &lt;a href="http://msdn.microsoft.com/en-us/library/cc681334.aspx" target="_blank"&gt;XmlSerializer Faults&lt;/a&gt; document.&amp;#160; Unfortunately, at the time of this writing that sample does not appear to exist - I've searched!&amp;#160; So, I'm going to expand on the topic here.&lt;/p&gt;  &lt;p&gt;SupportFaults is a boolean property that simply says this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;If true, then WCF will use the XmlSerializer to serialize the fault.&lt;/li&gt;    &lt;li&gt;If false, then WCF will use the DataContractSerializer to serialize the fault.&amp;#160; This is the default.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;As an example, consider the following service definition:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/XmlSerializerFaults_DBB7/image_2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="336" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/XmlSerializerFaults_DBB7/image_thumb.png" width="472" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Our service is using the XmlSerializer because of the XmlSerializerFormat attribute that is present.&lt;/p&gt;  &lt;p&gt;Our fault contract returns a typed SOAP fault, UnknownStockFault, to the client in the event that an unknown ticker symbol is passed in.&amp;#160; In this definition are some XML serialization attributes (XmlAttribute and XmlIgnore) that the XmlSerializer understands.&amp;#160; &lt;/p&gt;  &lt;p&gt;When your service returns this fault, it will be serialized by the DataContractSerializer (not the XmlSerializr) like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/XmlSerializerFaults_DBB7/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="148" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/XmlSerializerFaults_DBB7/image_thumb_1.png" width="774" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;When in fact, you were probably expecting this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/XmlSerializerFaults_DBB7/image_6.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="121" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/XmlSerializerFaults_DBB7/image_thumb_2.png" width="645" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Notice that &amp;quot;Symbol&amp;quot; is an attribute of the &amp;lt;UnknownStockFault&amp;gt; element and that the &amp;quot;ErrorCode&amp;quot; is missing.&lt;/p&gt;  &lt;p&gt;So, how do you achieve the latter?&amp;#160; By using the new SupportFaults property.&amp;#160; For example:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/XmlSerializerFaults_DBB7/image_8.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="148" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/XmlSerializerFaults_DBB7/image_thumb_3.png" width="462" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8975684" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>"Zermatt" Resources for Developers and Architects</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2008/09/24/zermatt-resources-for-developers-and-architects.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2008/09/24/zermatt-resources-for-developers-and-architects.aspx</id><published>2008-09-25T01:42:00Z</published><updated>2008-09-25T01:42:00Z</updated><content type="html">&lt;P&gt;I am captivated by the work going on in the identity space and as a result have created a collection of resources that I particularly like.&amp;nbsp; If you are interested in this space too and want to know where to go for information, consider these resources.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;H4&gt;Downloads&lt;/H4&gt;
&lt;P&gt;&lt;A href="https://connect.microsoft.com/Downloads/DownloadDetails.aspx?SiteID=642&amp;amp;DownloadID=12937" target=_blank mce_href="https://connect.microsoft.com/Downloads/DownloadDetails.aspx?SiteID=642&amp;amp;DownloadID=12937"&gt;Zermatt Developer Identity Framework&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;Articles / publications / white papers&lt;/H4&gt;
&lt;P&gt;&lt;A href="http://download.microsoft.com/download/9/4/f/94fc4796-151a-4cb8-a23d-f8d987d9cf4a/ZermattForDevelopers.pdf" target=_blank mce_href="http://download.microsoft.com/download/9/4/f/94fc4796-151a-4cb8-a23d-f8d987d9cf4a/ZermattForDevelopers.pdf"&gt;Microsoft Code Name "Zermatt" white paper for developers&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb882216.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb882216.aspx"&gt;Digital Identity for .NET Applications: A Technology Overview&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://go.microsoft.com/?linkid=9391256" mce_href="http://go.microsoft.com/?linkid=9391256"&gt;The Architecture Journal #16: Identity and Access&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;Videos&lt;/H4&gt;
&lt;P&gt;&lt;A href="http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032385483&amp;amp;EventCategory=4&amp;amp;culture=en-US&amp;amp;CountryCode=US" target=_blank mce_href="http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032385483&amp;amp;EventCategory=4&amp;amp;culture=en-US&amp;amp;CountryCode=US"&gt;MSDN WebCast: Overview of Developer Identity Framework (Zermatt), 9/26/08&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://channel9.msdn.com/shows/Going+Deep/Vittorio-Bertocci-and-Caleb-Baker-Understanding-CardSpace-and-the-Complexities-of-Identity/" target=_blank mce_href="http://channel9.msdn.com/shows/Going+Deep/Vittorio-Bertocci-and-Caleb-Baker-Understanding-CardSpace-and-the-Complexities-of-Identity/"&gt;Vittorio Bertocci and Caleb Baker: Understanding CardSpace and the Complexities of Identity&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://beta.channel9.msdn.com/posts/donovanf/Demystified-Series-Active-Directory-Federation-Services-AD-FS-Part-1/" mce_href="http://beta.channel9.msdn.com/posts/donovanf/Demystified-Series-Active-Directory-Federation-Services-AD-FS-Part-1/"&gt;Demystified Series: Active Directory Federation Services (AD FS) Part 1&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://channel9.msdn.com/posts/donovanf/Demystified-Series-Active-Directory-Federation-Services-AD-FS-Part-2/" mce_href="http://channel9.msdn.com/posts/donovanf/Demystified-Series-Active-Directory-Federation-Services-AD-FS-Part-2/"&gt;Demystified Series: Active Directory Federation Services (AD FS) Part 2&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;Books&lt;/H4&gt;
&lt;P&gt;&lt;A href="http://www.amazon.com/dp/0321496841" mce_href="http://www.amazon.com/dp/0321496841"&gt;Understanding Windows CardSpace: An Introduction to the Concepts and Challenges of Digital Identities&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;Blogs&lt;/H4&gt;
&lt;P&gt;&lt;A href="http://www.identityblog.com/" target=_blank mce_href="http://www.identityblog.com/"&gt;Kim Cameron's Identity Blog&lt;/A&gt;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://www.identityblog.com/?p=1007" mce_href="http://www.identityblog.com/?p=1007"&gt;Laws of Identity&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/vbertocci/default.aspx" target=_blank mce_href="http://blogs.msdn.com/vbertocci/default.aspx"&gt;Vittorio Bertocci&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://identity-des.com/" target=_blank mce_href="http://identity-des.com/"&gt;Don Schmidt&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://self-issued.info/" target=_blank mce_href="http://self-issued.info/"&gt;Mike Jones&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;Wiki&lt;/H4&gt;
&lt;P&gt;&lt;A href="http://en.wikipedia.org/wiki/Identity_Metasystem" target=_blank mce_href="http://en.wikipedia.org/wiki/Identity_Metasystem"&gt;Identity Metasystem&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;Test Drive It!&lt;/H4&gt;
&lt;P&gt;&lt;A href="http://www.federatedidentity.net/default.aspx" target=_blank mce_href="http://www.federatedidentity.net/default.aspx"&gt;Microsoft Identity Lab&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8964193" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="Identity" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/Identity/" /></entry><entry><title>Base addresses and IIS/WAS hosted services</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2008/08/23/base-addresses-and-iis-was-hosted-services.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2008/08/23/base-addresses-and-iis-was-hosted-services.aspx</id><published>2008-08-23T09:37:54Z</published><updated>2008-08-23T09:37:54Z</updated><content type="html">&lt;p&gt;If you have ever hosted a WCF service in IIS/WAS then you know that the .svc file for your service is the base address.&amp;#160; For example, if you create a web site project called MyService using the WCF Service template, then your base address for that service will be http://localhost/MyService/Service.svc.&amp;#160; That is why there is not a base address specified in the configuration for your service.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="296" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_thumb_1.png" width="559" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;It is also why the default service endpoint (wsHttpBinding) you get from Visual Studio's WCF Service template leaves the address property empty.&amp;#160; It is simply using the base address as the address for the endpoint.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="253" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_thumb.png" width="369" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Of course, any subsequent http endpoints you add will need a unique address relative to the base address in order for them to be reachable.&lt;/p&gt;  &lt;p&gt;Now, what happens when you decide to add support for other non-http protocols (tcp for example) to your service hosted in IIS/WAS?&amp;#160; Do you need to specify a base address, such as net.tcp://localhost/MyService/Service.svc in order to use relative addresses in any tcp endpoints you add?&amp;#160; That is a question I debated with a good friend recently for which I took the position - yes, you would.&amp;#160; After all, how else are your relative addresses going to resolve to reachable address if there is not a base address?&amp;#160; &lt;/p&gt;  &lt;p&gt;Well, it turns out I was wrong.&amp;#160; You do not have to add the base address for tcp (or any other protocol for that matter) because IIS/WAS is adding it for you when you enable these protocols for your service.&amp;#160; To verify this, I created a new Web Site project using the WCF Service template and added a method to return the BaseAddresses property from ServiceHost.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="47" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_thumb_2.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="76" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_thumb_3.png" width="530" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Then, I used the WCF Test Client to test my service and as expected, I found the http and https base addresses for my service.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_10.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="106" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_thumb_4.png" width="570" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Next, I opened IIS Manager and enabled some other non-http protocols.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_12.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="196" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_thumb_5.png" width="498" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Without adding any endpoints to my services, I then re-ran the WCF Test Client and to my surprise the base addresses for these other protocols were already there!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_14.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="145" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/BaseaddressesandIISWAShostedservices_2657/image_thumb_6.png" width="577" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;If I now add a tcp or pipe endpoint to my service, I can just enter a relative address for the endpoint because IIS/WAS has already provided the base address for these protocols.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8889962" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term="IIS/WAS" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/IIS_2F00_WAS/" /></entry><entry><title>Visual Studio 2008 Service Pack 1</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2008/08/14/visual-studio-2008-service-pack-1.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2008/08/14/visual-studio-2008-service-pack-1.aspx</id><published>2008-08-14T17:42:00Z</published><updated>2008-08-14T17:42:00Z</updated><content type="html">&lt;p&gt;Now available &lt;a href="http://msdn.microsoft.com/en-us/vstudio/cc533448.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;My installation took about 2 hours and 15 minutes to download and install.&amp;#160; Make sure you set aside some time for updating your development machine.&lt;/p&gt;  &lt;p&gt;In this post, I am going to talk about some (not all) of the features I particularly like with regard to Windows Communication Foundation (WCF).&amp;#160; Refer to the &lt;a href="http://msdn.microsoft.com/en-us/vstudio/products/cc533447.aspx"&gt;MSDN documentation&lt;/a&gt; for more details about all the changes in this service pack.&amp;#160; I've basically split this post into two categories:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;em&gt;Tooling Updates&lt;/em&gt;, where I describe features specific to tools.&amp;#160; For example, the IDE, WCF Test Client, etc. &lt;/li&gt;    &lt;li&gt;&lt;em&gt;API changes&lt;/em&gt;, where I describe changes to classes, methods, properties, etc. &lt;/li&gt; &lt;/ol&gt;  &lt;h2&gt;&lt;strong&gt;Tooling Updates&lt;/strong&gt;&lt;/h2&gt;  &lt;h3&gt;WCF Project Options&lt;/h3&gt;  &lt;p&gt;It is no longer necessary to manually edit your project file as described &lt;a href="http://blogs.msdn.com/rickrain/archive/2008/02/14/Preventing-the-WCF-Service-Host-from-launching-in-Visual-Studio-2008.aspx"&gt;here&lt;/a&gt; to prevent the &lt;a href="http://msdn.microsoft.com/en-us/library/bb552363.aspx"&gt;WCF Service Host&lt;/a&gt; from starting when you want to debug your service in a custom host application in the same solution.&amp;#160; Now, you just pop over to your project settings, click on the WCF Options tab and uncheck the option to start the WCF Service Host.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image9.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="308" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image9_thumb.png" width="444" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;WCF Test Client&lt;/h3&gt;  &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/bb552364.aspx"&gt;WCF Test Client&lt;/a&gt; has also picked up some very nice new features that I'll describe here.&lt;/p&gt;  &lt;h5&gt;Can stand up on its own&lt;/h5&gt;  &lt;p&gt;Previously, to start the WCF Test Client, you would press F5 and the IDE would take care of launching it (and the WCF Service Host) for you.&amp;#160; Or, if you wanted to use the client to test against a service outside of your solution, you could do so as long as you passed in the base address (as a command line parameter) of a running service so that the WCF Test Client could get to the metadata. &lt;/p&gt;  &lt;p&gt;Now, we can start the WCF Test Client without having to pass in the base address.&amp;#160; When the WCF Test Client window opens, go to the &lt;strong&gt;File&lt;/strong&gt; menu and select &lt;strong&gt;Add Service...&lt;/strong&gt; to enter the metadata address for the service(s) you want to test against.&amp;#160; There's even a nice list of previous services you have tested that you can access from the &lt;strong&gt;Recent Services&lt;/strong&gt; menu option.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="138" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image_thumb.png" width="239" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If you want to test multiple services from the same instance of the WCF Test Client, go right ahead.&amp;#160; This new UI makes it really easy.&amp;#160; You no longer have to open a separate instance of the WCF Test Client for each service.&lt;/p&gt;  &lt;p&gt;Another nice addition is the ability to edit the client configuration file.&amp;#160; Just right-click the &lt;strong&gt;Config File&lt;/strong&gt; node in the tree view and select &lt;strong&gt;Edit with SvcConfigEditor&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image_6.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="248" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image_thumb_2.png" width="320" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;From the &lt;a href="http://msdn.microsoft.com/en-us/library/ms732009.aspx"&gt;Service Configuration Editor&lt;/a&gt; you can make your modifications as you normally would.&amp;#160; When you are finished and you want to test those changes out, right-click on the service node in the tree view and select &lt;strong&gt;Refresh Service&lt;/strong&gt; to test out your new configuration settings.&amp;#160; Remember, these are client side configuration settings you're editing, not the service's configuration.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image1.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="189" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image1_thumb.png" width="301" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h5&gt;Can support MessageContracts&lt;/h5&gt;  &lt;p&gt;Yes, you can now test your services that expose &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.messagecontractattribute.aspx"&gt;[MessageContract]&lt;/a&gt;'s.&amp;#160; This is not something I do much of but knowing that I don't have to write a test client in these situations is worthy of an applause.&lt;/p&gt;  &lt;h5&gt;Can support XmlSerializer&lt;/h5&gt;  &lt;p&gt;The WCF Test Client can now support services that use the &lt;a href="http://msdn.microsoft.com/en-us/library/ms733901.aspx"&gt;XmlSerializer&lt;/a&gt; for serializing data.&lt;/p&gt;  &lt;h5&gt;Support for sessions&lt;/h5&gt;  &lt;p&gt;Suppose you have a service that requires sessions.&amp;#160; Again, in the past you pretty much had to write your own client to test such a service if your service maintained state between calls.&amp;#160; Now, the WCF Test Client maintains the same proxy internally when making calls to a service.&amp;#160; That is, the first time you invoke the service from your client a proxy is created.&amp;#160; The next time you invoke the service, that same proxy instance is used (ie: the same session).&amp;#160; So, for example, if I have a service operation (lets just call it AddNumber) that adds a number (how about 2) to running total and I invoke that operation 5 times, I can expect the result to be 10 as shown here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image6%5B1%5D.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="252" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image6%5B1%5D_thumb.png" width="448" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So, what if I want to create a new session?&amp;#160; Very simple - just check the &lt;strong&gt;Start a new proxy&lt;/strong&gt; checkbox and invoke the service.&amp;#160; This will create new proxy internally and therefore a new instance of the service with the running total initialized to 0.&amp;#160; After the call, the result will be 2 as shown here.&amp;#160; To continue using the new session, uncheck the &lt;strong&gt;Start a new proxy&lt;/strong&gt; checkbox.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image11.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="254" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image11_thumb.png" width="445" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In light of all these new capabilities, I've promoted the WCF Test Client to my Quick Launch window so I can quickly test a service (or services) without having to load up the IDE.&lt;/p&gt;  &lt;h3&gt;Publish WCF Service Wizard&lt;/h3&gt;  &lt;p&gt;There is a new wizard for WCF projects to facilitate publishing of WCF services.&amp;#160; You can access this from the &lt;strong&gt;Build&lt;/strong&gt; menu in Visual Studio 2008, or by right-clicking your WCF service library project and selecting &lt;strong&gt;Publish&lt;/strong&gt;.&amp;#160; This makes publishing ( to IIS for example ) extremely easy.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image15.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="196" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image15_thumb.png" width="340" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you create a &lt;strong&gt;WCF Service Library&lt;/strong&gt; project initially and later want to then publish that service to IIS, this option will setup the virtual directories in IIS for you and it will also create the .svc file you will need for that hosting environment.&lt;/p&gt;  &lt;h2&gt;API Changes&lt;/h2&gt;  &lt;h3&gt;Plain Old CLR Objects (POCO)&lt;/h3&gt;  &lt;p&gt;This is a great new feature that eases the migration from ASP.NET Web Services to WCF.&amp;#160; Aaron describes this nicely in &lt;a href="http://www.pluralsight.com/community/blogs/aaron/archive/2008/05/13/50934.aspx"&gt;DataContracts without attributes (POCO support) in .NET 3.5 SP1&lt;/a&gt; so I won't explain it here.&amp;#160; When I first heard of this it smelled non-SOA to me because you don't explicitly define your data.&amp;#160; However, I have come to realize the value of this new feature when it comes to migrating existing ASP.NET Web Services to WCF.&amp;#160; Otherwise, I prefer the explicitness of using [DataContract]'s to define your data.&lt;/p&gt;  &lt;h3&gt;System.ServiceModel.Web.UriTemplate&lt;/h3&gt;  &lt;p&gt;The &lt;a href="http://msdn.microsoft.com/en-us/library/system.uritemplate.aspx"&gt;UriTemplate&lt;/a&gt; class took on some changes, many of which are used by other parts of the framework.&amp;#160; But, a couple of notables for us WCF folks are described here.&lt;/p&gt;  &lt;p&gt;There is a new &lt;a href="http://msdn.microsoft.com/en-us/library/system.uritemplate.defaults.aspx"&gt;Defaults&lt;/a&gt; property now that enables you to define default values for parameters defined in the template string.&amp;#160; This allows us to do things like this in our service cotracts:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image_17.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="58" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image_thumb_3.png" width="385" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you access the service from your browser and omit the parameter in your URI, then your method will receive this default value.&lt;/p&gt;  &lt;p&gt;Compound template segments were also added which allows you to do things like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image_19.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="66" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/VisualStudio2008ServicePack1_A8C5/image_thumb_7.png" width="332" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;From your browser, you would be able to invoke the operation using a URI like this.&lt;/p&gt;  &lt;p&gt;http://localhost/myproducts/product(12)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8866948" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term="Visual Studio" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/Visual+Studio/" /></entry><entry><title>Preventing the WCF Service Host from launching in Visual Studio 2008</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2008/02/14/preventing-the-wcf-service-host-from-launching-in-visual-studio-2008.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2008/02/14/preventing-the-wcf-service-host-from-launching-in-visual-studio-2008.aspx</id><published>2008-02-15T04:47:00Z</published><updated>2008-02-15T04:47:00Z</updated><content type="html">&lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;One of the great new features of Visual Studio 2008 is the new tools for WCF developers.&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;No longer is it necessary to code up your own test host and test client applications to test your service.&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;This functionality is provided for you automatically thanks to the&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;a class="" title="WCF Service Host" href="http://msdn2.microsoft.com/en-us/library/bb552363.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb552363.aspx"&gt;WCF Service Host&lt;/a&gt;&lt;/span&gt; and &lt;a class="" title="WCF Test Client" href="http://msdn2.microsoft.com/en-us/library/bb552364.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb552364.aspx"&gt;WCF Test Client&lt;/a&gt;.&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;This significantly improves developer productivity with regard to the development of the service.&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;Unfortunately, if you&amp;#8217;re going to be hosting your service in a custom host, such as a windows application or console application (probably for debugging purposes since these are generally not practical choices for hosting) then you will run into a little snag if you add that project to the same solution. &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;The snag you are going to run into is the WCF Service Host running at the same time as your custom host application when you press F5 to run your application.&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;When your custom host application initializes the WCF stack, you will likely see an AddressAlreadyInUseException.&amp;#160; This is happening because the WCF Service Host is already listening on the same address.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt" mce_keep="true"&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;Unfortunately, there is not a switch in the Visual Studio environment that resolves this problem.&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;So, you have to go to the project file for your service and make a small change, which I&amp;#8217;ll describe here. &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;&lt;font face="Calibri" size="3"&gt;1.&lt;/font&gt;&lt;span style="font: 7pt &amp;#39;Times New Roman&amp;#39;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;&lt;strong&gt;Right-click the WCF service project&lt;/strong&gt; (not the custom host project) in Solution Explorer and select &lt;strong&gt;Open Folder in Windows Explorer&lt;/strong&gt;. &lt;/font&gt;&lt;/font&gt;    &lt;p mce_keep="true"&gt;&lt;/p&gt;   &lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;&lt;font face="Calibri" size="3"&gt;2.&lt;/font&gt;&lt;span style="font: 7pt &amp;#39;Times New Roman&amp;#39;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;In Windows Explorer, &lt;strong&gt;right-click the project file&lt;/strong&gt; (.csproj) and select &lt;strong&gt;Open With | Notepad&lt;/strong&gt; (if Notepad is not an option you may need to browse to it). &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p mce_keep="true"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;&lt;font face="Calibri" size="3"&gt;3.&lt;/font&gt;&lt;span style="font: 7pt &amp;#39;Times New Roman&amp;#39;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;In Notepad, look for the &lt;strong&gt;&amp;lt;ProjectTypeGuids&amp;gt;&lt;/strong&gt; element and &lt;strong&gt;delete&lt;/strong&gt; it.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&amp;#160;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;a href="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/PreventingtheWCFServiceHostfromlaunching_B13C/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="196" alt="image" src="http://blogs.msdn.com/blogfiles/rickrain/WindowsLiveWriter/PreventingtheWCFServiceHostfromlaunching_B13C/image_thumb_1.png" width="547" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;&lt;font face="Calibri" size="3"&gt;4.&lt;/font&gt;&lt;span style="font: 7pt &amp;#39;Times New Roman&amp;#39;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;In Notepad select &lt;strong&gt;File | Save&lt;/strong&gt; on the menu to save the change and then &lt;strong&gt;File | Exit&lt;/strong&gt; to close Notepad.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;&lt;font face="Calibri" size="3"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&amp;#160;&lt;/p&gt;  &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;&lt;font face="Calibri" size="3"&gt;5.&lt;/font&gt;&lt;span style="font: 7pt &amp;#39;Times New Roman&amp;#39;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;Go back to your &lt;strong&gt;Visual Studio 2008&lt;/strong&gt; window.&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;When you activate the window, you will see a dialog prompting you to reload the project file.&lt;span style="mso-spacerun: yes"&gt;&amp;#160; &lt;/span&gt;Click the &lt;strong&gt;Reload&lt;/strong&gt; button to reload the project file. &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p mce_keep="true"&gt;&lt;span style="mso-bidi-font-family: calibri; mso-bidi-theme-font: minor-latin"&gt;&lt;span style="mso-list: ignore"&gt;&lt;font face="Calibri" size="3"&gt;6.&lt;/font&gt;&lt;span style="font: 7pt &amp;#39;Times New Roman&amp;#39;"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;font size="3"&gt;&lt;font face="Calibri"&gt;Press &lt;strong&gt;F5&lt;/strong&gt; to run your custom host application. &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7704642" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author><category term="WCF" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/WCF/" /><category term="Visual Studio" scheme="http://blogs.msdn.com/b/rickrain/archive/tags/Visual+Studio/" /></entry><entry><title>Visual C++ 6.0: How do I create symbols files (.pdb) for release builds?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2004/11/05/253101.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2004/11/05/253101.aspx</id><published>2004-11-06T01:43:00Z</published><updated>2004-11-06T01:43:00Z</updated><content type="html">&lt;p&gt;&lt;font face="Verdana"&gt;I seem to be getting asked this question alot lately.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana"&gt;In Visual C++ 6.0, symbol files are generated automatically for debug build configurations&amp;nbsp;of your project.&amp;nbsp; For release build configurations, they are not.&amp;nbsp; Does this mean that you cannot generate symbol files for release builds?&amp;nbsp; No, it is just not enabled by default.&amp;nbsp; Here are the steps necessary to generate symbol files for release builds.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana"&gt;Open the Project Settings dialog for your project.&amp;nbsp; Change the 'Settings For' drop down box to your 'Release' build configuration.&amp;nbsp; Note: It is possible that you will have multiple 'Release' build configurations.&amp;nbsp; &lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana"&gt;Next, click on the 'C/C++' tab and change the 'Debug info:' drop down box to 'Program Database'.&amp;nbsp; For example,&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana"&gt;Finally, click on the 'Link' tab and change the 'Category' drop down box to 'General'.&amp;nbsp; Then, click the 'Generate debug info' checkbox.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana"&gt;When you build your project with this configuration you will have symbol files in the output folder.&lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=253101" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>ATL: What is the difference between the _ATL_DEBUG_REFCOUNT and _ATL_DEBUG_INTERFACES macros?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/rickrain/archive/2004/10/14/242498.aspx" /><id>http://blogs.msdn.com/b/rickrain/archive/2004/10/14/242498.aspx</id><published>2004-10-15T01:07:00Z</published><updated>2004-10-15T01:07:00Z</updated><content type="html">&lt;p&gt;&lt;font face="Verdana" size="2"&gt;I have just always used &lt;font face="Courier New"&gt;_ATL_DEBUG_INTERFACES&lt;/font&gt; and never really considered using &lt;font face="Courier New"&gt;_ATL_DEBUG_REFCOUNT&lt;/font&gt;.&amp;nbsp; After investigating this further, this is what I found (referring to ATL v7.1):&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;From Atldef.h:&lt;br /&gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Courier New" size="2"&gt;#ifdef _ATL_DEBUG_REFCOUNT&lt;br /&gt;#ifndef _ATL_DEBUG_INTERFACES&lt;br /&gt;#define _ATL_DEBUG_INTERFACES&lt;br /&gt;#endif&lt;br /&gt;#endif&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;So, if you use &lt;font face="Courier New"&gt;_ATL_DEBUG_REFCOUNT&lt;/font&gt;, it is going to automatically define &lt;font face="Courier New"&gt;_ATL_DEBUG_INTERFACES&lt;/font&gt; for you if you haven't done so already.&amp;nbsp; This is the only reference to &lt;font face="Courier New"&gt;_ATL_DEBUG_REFCOUNT&lt;/font&gt; in the ATL source. So, to answer the question - there is no difference.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font face="Verdana" size="2"&gt;&amp;nbsp;&lt;br /&gt;I suspect that prior to ATL v3.0, all the &lt;font face="Courier New"&gt;_ATL_DEBUG_INTERFACES&lt;/font&gt; that are sprinkled throughout the ATL code were previously &lt;font face="Courier New"&gt;_ATL_DEBUG_REFCOUNT&lt;/font&gt; references.&amp;nbsp; Then when v3.0 came along, they changed the naming convention and called it &lt;font face="Courier New"&gt;_ATL_DEBUG_INTERFACES&lt;/font&gt;.&amp;nbsp; So, it looks like &lt;font face="Courier New"&gt;_ATL_DEBUG_REFCOUNT&lt;/font&gt; is there simply for ‘backward compatibility’ to ATL v2.x.&lt;br /&gt;&lt;/font&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=242498" width="1" height="1"&gt;</content><author><name>Rick Rainey [MSFT]</name><uri>http://blogs.msdn.com/rickrain/ProfileUrlRedirect.ashx</uri></author></entry></feed>