<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Alik Levin's : Implementation</title><link>http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx</link><description>Tags: Implementation</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>ASP.NET Performance: Fast AJAX, Faster AJAX</title><link>http://blogs.msdn.com/alikl/archive/2008/10/29/asp-net-performance-fast-ajax-faster-ajax.aspx</link><pubDate>Wed, 29 Oct 2008 00:43:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9021016</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/9021016.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=9021016</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=9021016</wfw:comment><description>&lt;table cellspacing="5" cellpadding="2" width="557" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="226"&gt;&amp;#160;&lt;a href="http://practicethis.com/" target="_blank"&gt;&lt;img title="Alik Levin" height="50" alt="Alik Levin" src="http://blogs.microsoft.co.il/blogs/mcs/WindowsLiveWriter/d20b00ba5cce_FD44/image_5.png" width="50" border="0" /&gt;&lt;/a&gt;&amp;#160;&amp;#160;&amp;#160; AJAX improves significantly both user experience and performance. It can be further improved by using down level capabilities that .Net framework offers. Specifically, consuming Web Services and WCF directly from client script. The best part is that ASP.NET AJAX comes with built in libraries - server and client - that make coding fun while significantly improving the web application's performance.&lt;/td&gt;        &lt;td valign="top" width="314"&gt;&lt;script type="text/javascript"&gt;

 
&lt;!-- 
lqm_channel=1;
lqm_publisher=253;
lqm_zone=1;
lqm_format=6;
//--&gt;&lt;/script&gt;&lt;script src="http://a.lakequincy.com/s.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h3&gt;Customer Case Study&lt;/h3&gt;  &lt;p&gt;The customer was using hand crafted XmlHttp requests from client scripts requesting the data from ASPX pages. While the goal was achieved - the amount of information sent to the server was minimal and the user interface was responsive - the coding was not really fun. Also, since the requests were sent to regular ASPX pages the whole ASPX pipeline was executing unnecessarily utilizing CPU for nothing. The customer did not want to use Update Panel control. Although it boosts coding productivity, it also adds some burden on the network. Network utilization should have been kept to the minimum. &lt;/p&gt;  &lt;h3&gt;Analysis&lt;/h3&gt;  &lt;p&gt;After quick research I found two great resources that directed me to the solution that would satisfy both requirements:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Coding productivity. &lt;/li&gt;    &lt;li&gt;Minimum of data in transit on the wire. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The first one is from Chris Hay&amp;#160; - &lt;a href="http://silverlightuk.blogspot.com/2008/10/remix08-uk-aspnet-front-end-performance.html"&gt;remix08 UK ASP.NET Front End Performance Slides&lt;/a&gt; and the other one is from Jeff Prosise - &lt;a href="http://download.microsoft.com/download/f/2/a/f2a04d97-4472-4d3d-bc5a-ecec0d073f24/03_Power_%20ASP_NET_AJAX_Programming.ppt"&gt;Power ASP.NET AJAX Programming&lt;/a&gt;. They both outline the usage of Script-Callable Web Services. There are three simple steps to follow:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Declare your Web Service as Script-Callable by adding class level attribute:&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;pre class="code"&gt;[System.Web.Script.Services.&lt;span style="color: #2b91af"&gt;ScriptService&lt;/span&gt;]
&lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;AJAXCallableWebService &lt;/span&gt;: System.Web.Services.&lt;span style="color: #2b91af"&gt;WebService
&lt;/span&gt;{
    [&lt;span style="color: #2b91af"&gt;WebMethod&lt;/span&gt;]
    &lt;span style="color: blue"&gt;public string &lt;/span&gt;HelloWorld(&lt;span style="color: blue"&gt;string &lt;/span&gt;name)
    {
        &lt;span style="color: blue"&gt;return &lt;/span&gt;&lt;span style="color: #a31515"&gt;&amp;quot;Hello, &amp;quot; &lt;/span&gt;+ name;
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Declare service reference inside the ScriptManager:&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ScriptManager &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;ScriptManager1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;server&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Services&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ServiceReference &lt;/span&gt;&lt;span style="color: red"&gt;InlineScript&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;true&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;~/AJAXCallableWebService.asmx&amp;quot; /&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Services&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ScriptManager&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Call a Web Service from the client script:&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;script &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text/javascript&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;language&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;javascript&amp;quot;&amp;gt;
function &lt;/span&gt;callAjax()
{
    &lt;span style="color: blue"&gt;var &lt;/span&gt;text = document.getElementById(&lt;span style="color: #a31515"&gt;&amp;quot;Text1&amp;quot;&lt;/span&gt;).value
    
    AJAXCallsWebService.AJAXCallableWebService.HelloWorld(text,onSuccess);
}
&lt;span style="color: blue"&gt;function &lt;/span&gt;onSuccess(result)
{
    document.getElementById(&lt;span style="color: #a31515"&gt;&amp;quot;result&amp;quot;&lt;/span&gt;).innerText = result;
}
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;span &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;result&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;span&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Button1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;button&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;button&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;onclick&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;callAjax()&amp;quot; /&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Text1&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text&amp;quot; /&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h3&gt;Sample Visual Studio Solution&lt;/h3&gt;

&lt;p&gt;Grab the sample solution implemented using Visual Studio 2008 form my SkyDrive &lt;a href="http://cid-dd25b83e4ca261f7.skydrive.live.com/self.aspx/Visual%20Studio%20Projects/AJAXCallsWebService.zip"&gt;here&lt;/a&gt;:&lt;/p&gt;
&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/AJAXCallsWebService.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;

&lt;h3&gt;Related Materials&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/02/18/how-to-consume-wcf-using-ajax-without-asp-net.aspx"&gt;How To Consume WCF Using AJAX Without ASP.NET&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/12/31/asp-net-ajax-control-toolkit-basic-sample-for-dynamicpopulate-control.aspx"&gt;ASP.NET AJAX Control Toolkit - Basic Sample For DynamicPopulate Control&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;a onclick="window.location = &amp;#39;http://www.reddit.com/submit?url=&amp;#39; + encodeURIComponent(window.location); return false" href="http://www.reddit.com/submit"&gt;&lt;img alt="submit to reddit" src="http://www.reddit.com/static/spreddit11.gif" border="0" /&gt; &lt;/a&gt;

&lt;p&gt;&lt;strong&gt;This template is made with &lt;a href="http://practicethis.com/" target="_blank"&gt;PracticeThis.com&lt;/a&gt; plugin for Windows Live Writer&lt;/strong&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9021016" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/alikl/archive/tags/AJAX/default.aspx">AJAX</category></item><item><title>ASP.NET Performance: Dynamically Loaded Assemblies Cause Application Recycles (Problem and Solution)</title><link>http://blogs.msdn.com/alikl/archive/2008/10/08/asp-net-performance-dynamically-loaded-assemblies-cause-application-recycles-problem-and-solution.aspx</link><pubDate>Wed, 08 Oct 2008 16:21:41 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8991289</guid><dc:creator>alikl</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8991289.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8991289</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8991289</wfw:comment><description>&lt;table cellspacing="5" cellpadding="2" width="557" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="226"&gt;&amp;#160;&lt;a href="http://practicethis.com/" target="_blank"&gt;&lt;img title="Alik Levin" height="50" alt="Alik Levin" src="http://blogs.microsoft.co.il/blogs/mcs/WindowsLiveWriter/d20b00ba5cce_FD44/image_5.png" width="50" border="0" /&gt;&lt;/a&gt;&amp;#160;&amp;#160;&amp;#160; In my speak - dynamically loaded assemblies are those assemblies that were compiled during run time dynamically via CodeProvider like CSharpCodeProvider directly or by using types that use this class internally. Assemblies that are loaded dynamically using reflection via Load/LoadFrom method are out of the scope of this post. &lt;/td&gt;        &lt;td valign="top" width="314"&gt;&lt;script type="text/javascript"&gt;
 
&lt;!-- 
lqm_channel=1;
lqm_publisher=253;
lqm_zone=1;
lqm_format=6;
//--&gt;&lt;/script&gt;&lt;script src="http://a.lakequincy.com/s.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h3&gt;Customer Case Study&lt;/h3&gt;  &lt;p&gt;The customer complained on periodic restarts/recycles of the ASP.NET application. We observed relative entries in the Event Log that showed up systematically on timely basis. We also observed memory utilization growth in Task Manager. After reaching 500 MB of memory utilization the application would recycle spawning another w3wp.exe to accept new incoming requests while draining the old w3wp.exe.&lt;/p&gt;  &lt;h3&gt;Analysis&lt;/h3&gt;  &lt;p&gt;After short discussion with the dev team about the design of the application we thought that the memory leak might be caused by improper usage of XmlSerializer that generate dynamic assemblies. Tess published &lt;a href="http://blogs.msdn.com/tess/archive/2008/03/17/net-debugging-demos-lab-6-memory-leak-review.aspx"&gt;fantastic walk through&lt;/a&gt; specifically dedicated to this case. Using either perfmon (.NET CLR Loading\Current Assemblies) or Process Explorer (see pic below)we observed unusual number (thousands) of loaded assemblies (notice Assemblies column). Also, notice the csc.exe in red - this is CSharp compiler that is invoked on each request:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.NETPerformanceDynamicallyLoadedAssem_928B/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="226" alt="Process Explorer ASP.NET Performance Dynamically Loaded Assemblies" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.NETPerformanceDynamicallyLoadedAssem_928B/image_thumb.png" width="567" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We decided to take a memory dump to deeply investigate the case. Following are the steps that we took while analyzing the dump using WinDBG to identify the root cause:&lt;/p&gt;  &lt;h4&gt;Step 1 - Dumping memory heap to identify object allocated on heap&lt;/h4&gt;  &lt;p&gt;This is the fragment of the long list of objects. Our attention was caught by unusually large number of reflected assemblies.&lt;/p&gt;  &lt;ul&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/ul&gt;  &lt;p&gt;&lt;b&gt;!dumpheap &amp;#8211;stat      &lt;br /&gt;&lt;/b&gt;&lt;b&gt;&lt;font color="#ff0000"&gt;9,019&lt;/font&gt;&lt;/b&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 216,456 System.Reflection.Assembly     &lt;br /&gt;112&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 4,032 System.Xml.Serialization.TempAssembly     &lt;br /&gt;104&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 5,408 System.Xml.Serialization.TypeDesc&lt;/p&gt;  &lt;p&gt;After 3 minutes the number of dynamic assemblies is larger by more 350 assemblies (from subsequent dump):&lt;/p&gt;  &lt;p&gt;&lt;b&gt;!dumpheap &amp;#8211;stat      &lt;br /&gt;&lt;/b&gt;&lt;b&gt;&lt;font color="#ff0000"&gt;9,379&lt;/font&gt;&lt;/b&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 225,096 System.Reflection.Assembly     &lt;br /&gt;114&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 4,104 System.Xml.Serialization.TempAssembly     &lt;br /&gt;102&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 5,304 System.Xml.Serialization.TypeDesc&lt;/p&gt;  &lt;h4&gt;Step 2 - Dumping appdomains to identify loaded assemblies&lt;/h4&gt;  &lt;p&gt;Another cross check to make sure we are dealing with tons of loaded assemblies.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;!dumpdomain -stat&amp;#160; &lt;br /&gt;&lt;/b&gt;&amp;#160;&amp;#160;&amp;#160; Domain&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Num Assemblies&amp;#160;&amp;#160; Size Assemblies&amp;#160;&amp;#160;&amp;#160; Name     &lt;br /&gt;0x793f15d8&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 1&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2,142,208&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System Domain     &lt;br /&gt;0x793f2aa8&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 56&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 16,012,288&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Shared Domain     &lt;br /&gt;0x000ab7d8&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 2,498,560&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DefaultDomain     &lt;br /&gt;0x000d3368&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;b&gt;&lt;font color="#ff0000"&gt;9,018&lt;/font&gt;&lt;/b&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 55,447,040&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; /LM/W3SV......&lt;/p&gt;  &lt;p&gt;Total 4 Domains, Total Size 76,100,096&lt;/p&gt;  &lt;h4&gt;Step 3 - Dumping all dynamic assemblies&lt;/h4&gt;  &lt;p&gt;How many of the assemblies are dynamic? (dda stands for dumpdynamicassemblies)&lt;/p&gt;  &lt;p&gt;&lt;b&gt;!dda&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="1"&gt;Domain: 0x793f15d8      &lt;br /&gt;-------------------       &lt;br /&gt;Domain: .       &lt;br /&gt;-------------------       &lt;br /&gt;Domain: DefaultDomain       &lt;br /&gt;-------------------       &lt;br /&gt;Domain: /LM/W3SVC/1/ROOT/......       &lt;br /&gt;-------------------       &lt;br /&gt;Assembly: 0x19058818 [RegexAssembly133_0] Dynamic Module: 0x16f4c220 loaded at: 0x0 Size: 0x0((null))       &lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;Assembly: 0x19058818 [RegexAssembly133_0] Dynamic Module: 0x190696a0 loaded at: 0x0 Size: 0x0((null))      &lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;Assembly: 0x19103ee8 [-0g5u8-v] Dynamic Module: 0x1920d6f8 loaded at: 0x19911000 Size: 0xc000((null))      &lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;Assembly: 0x190c9a40 [cvmmynwf] Dynamic Module: 0x190dc0d0 loaded at: 0x19a71000 Size: 0x4000((null))      &lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;Assembly: 0x1911bad8 [0ikhy_lx] Dynamic Module: 0x1911aa98 loaded at: 0x19f21000 Size: 0xc00((null))      &lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;.......      &lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;Assembly: 0x43199720 [nv1lvdiy] Dynamic Module: 0x431b3190 loaded at: 0x4cf61000 Size: 0xc00((null))      &lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;Assembly: 0x2d2bf008 [rk6dabem] Dynamic Module: 0x2d2bf258 loaded at: 0x4cf71000 Size: 0xc00((null))      &lt;br /&gt;&lt;/font&gt;&lt;font size="1"&gt;--------------------------------------&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Total &lt;font color="#ff0000"&gt;8,911 Dynamic Assemblies&lt;/font&gt;, Total size: 0x1d5b600(30,782,976) bytes.&lt;/b&gt;&lt;/p&gt;  &lt;h4&gt;Step 4 - Saving dynamic assembly to physical DLL&lt;/h4&gt;  &lt;p&gt;Save assemblies to the filesystem&lt;/p&gt;  &lt;p&gt;&lt;b&gt;!savemodule 0x2d2bc4c8 C: \0x1c344438.dll&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.NETPerformanceDynamicallyLoadedAssem_928B/clip_image002_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="86" alt="clip_image002" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.NETPerformanceDynamicallyLoadedAssem_928B/clip_image002_thumb.jpg" width="490" border="0" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;To save all the assemblies to the file system use the following command: &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;!dda -save C:\MODULES&lt;/strong&gt;&lt;/p&gt;  &lt;h4&gt;Step 5 - Using Reflector to reverse engineer the DLL:&lt;/h4&gt;  &lt;p&gt;Use Reflector to inspect the implementation/source code of the dynamic assemblies.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.NETPerformanceDynamicallyLoadedAssem_928B/clip_image001_2.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="220" alt="clip_image001" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.NETPerformanceDynamicallyLoadedAssem_928B/clip_image001_thumb.jpg" width="403" border="0" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;  &lt;h4&gt;Step 6 - Using Reflector to find&amp;#160; ExpressionEvaluator class&lt;/h4&gt;  &lt;p&gt;Try to locate the class in the static assemblies hopefully hitting the code that generates it:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.NETPerformanceDynamicallyLoadedAssem_928B/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="178" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.NETPerformanceDynamicallyLoadedAssem_928B/image_thumb_1.png" width="529" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h4&gt;Step 7 - Bingo! Each constructor for ExpressionEvaluator invokes compiler&lt;/h4&gt;  &lt;p&gt;ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();    &lt;br /&gt;...     &lt;br /&gt;CompilerResults results = compiler.CompileAssemblyFromSource(options, builder.ToString());    &lt;br /&gt;...    &lt;br /&gt;this._Compiled = results.CompiledAssembly.CreateInstance(&amp;quot;NavServices._ExpressionEvaluator&amp;quot;);&lt;/p&gt;  &lt;p&gt;This is actually the code that causes Process Explorer to show csc.exe under w3wp.exe (see red line in the first pic). And this is the code that caused number of loaded assemblies to grow. And this is the code that caused the application restarts.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;h3&gt;Acknowledgements&lt;/h3&gt;  &lt;p&gt;During this investigation the following resources were used. Big THANK-YOU goes to:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Tess - &lt;a href="http://blogs.msdn.com/tess/archive/2006/02/15/net-memory-leak-xmlserializing-your-way-to-a-memory-leak.aspx"&gt;.NET Memory Leak: XmlSerializing your way to a Memory Leak&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Tom - &lt;a title="http://blogs.msdn.com/tom/archive/2007/12/05/dynamic-assemblies-and-what-to-do-about-them.aspx" href="http://blogs.msdn.com/tom/archive/2007/12/05/dynamic-assemblies-and-what-to-do-about-them.aspx"&gt;Dynamic Assemblies and what to do about them&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Johan - &lt;a href="http://blogs.msdn.com/johan/archive/2007/11/13/getting-started-with-windbg-part-i.aspx"&gt;Getting started with windbg - part I&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Cuko - &lt;a href="http://blogs.msdn.com/baleixo/archive/2008/07/18/outofmemory-compiledassembly.aspx"&gt;OutOfMemory &amp;amp; CompiledAssembly&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;Related Materials&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a title="http://blogs.msdn.com/ace_team/archive/2008/08/11/asp-net-performance-high-cpu-utilization-case-studies-and-solutions.aspx" href="http://blogs.msdn.com/ace_team/archive/2008/08/11/asp-net-performance-high-cpu-utilization-case-studies-and-solutions.aspx"&gt;ASP.NET Performance: High CPU Utilization Case Studies And Solutions&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/07/20/use-free-tools-from-iis-resource-kit-to-warm-up-your-asp-net-1-1-application-by-batch-compilation.aspx"&gt;Use FREE Tools From IIS Resource Kit To Warm Up Your ASP.NET 1.1 Application By Batch Compilation&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;This template is made with &lt;a href="http://practicethis.com/" target="_blank"&gt;PracticeThis.com&lt;/a&gt; plugin for Windows Live Writer&lt;/strong&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8991289" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category></item><item><title>Improve ASP.NET 2.0 Performance With PageAsyncTask - Multithreading For The Masses</title><link>http://blogs.msdn.com/alikl/archive/2008/10/02/improve-asp-net-2-0-performance-with-pageasynctask-multithreading-for-the-masses.aspx</link><pubDate>Thu, 02 Oct 2008 11:31:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8973165</guid><dc:creator>alikl</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8973165.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8973165</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8973165</wfw:comment><description>&lt;table cellspacing="5" cellpadding="2" width="557" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="186"&gt;&amp;#160;&lt;a href="http://practicethis.com/" target="_blank"&gt;&lt;img title="Alik Levin" height="50" alt="Alik Levin" src="http://blogs.microsoft.co.il/blogs/mcs/WindowsLiveWriter/d20b00ba5cce_FD44/image_5.png" width="50" border="0" /&gt;&lt;/a&gt;&amp;#160;&amp;#160;&amp;#160; Multithreading is tough. This is what &lt;a href="http://www.wintellect.com/CS/blogs/jrobbins/default.aspx"&gt;John Robbins&lt;/a&gt; says about it in his excellent book &lt;a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;amp;location=http%3A%2F%2Fwww.amazon.com%2FDebugging-Microsoft-NET-2-0-Applications%2Fdp%2F0735622027%2F&amp;amp;tag=practhis-20&amp;amp;linkCode=ur2&amp;amp;camp=1789&amp;amp;creative=9325"&gt;Debugging Microsoft .NET 2.0 Applications&lt;/a&gt;&lt;img style="margin: 0px; border-top-style: none! important; border-right-style: none! important; border-left-style: none! important; border-bottom-style: none! important" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=practhis-20&amp;amp;l=ur2&amp;amp;o=1" width="1" border="0" /&gt;:           &lt;br /&gt;          &lt;br /&gt;&amp;quot;Don't do it... Make sure there's no other way you can structure your program before you decide to incorporate multithreading into your application... you are easily adding a minimum of an extra month of development and testing to your schedule&amp;quot;. I agree with it completely. But there are times multithreading is unavoidable. Especially when more and more Services popping up in the wild...&lt;/td&gt;        &lt;td valign="top" width="354"&gt;&lt;img height="365" alt="" src="http://i.msdn.microsoft.com/cc163725.fig02(en-us).gif" width="354" /&gt;           &lt;br /&gt;          &lt;br /&gt;From &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163725.aspx"&gt;Asynchronous Pages in ASP.NET 2.0&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h3&gt;Customer Case Study&lt;/h3&gt;  &lt;p&gt;I am working with the customer to improve their ASP.NET 2.0 application performance. The application issues multiple requests to the backend middleware that is exposed as a web service. The application cannot get a hold on the actual proxies rather it is provided with the components that wrap the web services proxies. The application needs to issue concurrent&amp;#160; requests. Serial request would result in serious latency which is unacceptable by end users.&lt;/p&gt;  &lt;h3&gt;Analysis&lt;/h3&gt;  &lt;p&gt;Since we cannot get hold on web services proxies we cannot utilize available asynchronous methods available with it: BeginMyMethod/EndMyMethod and MyMethodAsync/MyMethodCompleted. But we definitely can utilize another option available with ASP.NET 2.0 - registering asynchronous tasks using PageAsyncTask class.&lt;/p&gt;  &lt;p&gt;The following information is based on the following materials:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163725.aspx"&gt;Asynchronous Pages in ASP.NET 2.0&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.pageasynctask.aspx"&gt;PageAsyncTask Class&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;PageAsyncTask Implementation Steps&lt;/h3&gt;  &lt;p&gt;This is the summary of the steps to implement and register PageAsyncTask:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Create a class that contains lengthy operation&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Declare AsyncTaskDelegate&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Add OnBegin, OnEnd, OnTimeout methods to the class&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Mark the calling page as Async=&amp;quot;true&amp;quot;&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Register the PageAsyncTasks in the ASPX page and execute it&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You can grab the Visual Studio 2008 project with the implementation from my SkyDrive &lt;a href="http://cid-dd25b83e4ca261f7.skydrive.live.com/self.aspx/Visual%20Studio%20Projects/MultipleCallsSynchronizedViaAsync.zip"&gt;here&lt;/a&gt;:&lt;/p&gt; &lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/MultipleCallsSynchronizedViaAsync.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;h3&gt;Related Materials&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/06/23/improve-asp-net-performance-with-multithreading-using-thread-or-threadpool-objects.aspx"&gt;Improve ASP.NET Performance With Multithreading Using Thread Or ThreadPool Objects&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/ace_team/archive/2008/02/14/do-you-really-need-a-distributed-architecture.aspx"&gt;Do You Really Need A Distributed Architecture?&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="1"&gt;This template is made with &lt;/font&gt;&lt;a href="http://practicethis.com/" target="_blank"&gt;&lt;font size="1"&gt;PracticeThis.com&lt;/font&gt;&lt;/a&gt;&lt;font size="1"&gt; plugin for Windows Live Writer&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8973165" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Threading/default.aspx">Threading</category></item><item><title>ASP.NET Data Binding Performance – Collection Is More Expensive Than Datatable</title><link>http://blogs.msdn.com/alikl/archive/2008/08/01/ASP.NET-Data-Binding-Performance-_1320_-Collection-Is-More-Expensive-Than-Datatable.aspx</link><pubDate>Fri, 01 Aug 2008 14:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8794452</guid><dc:creator>alikl</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8794452.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8794452</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8794452</wfw:comment><description>&lt;A href="http://practicethis.com/" target=_blank mce_href="http://practicethis.com/"&gt;&lt;IMG title="Alik Levin" height=50 alt="Alik Levin" src="http://blogs.microsoft.co.il/blogs/mcs/WindowsLiveWriter/d20b00ba5cce_FD44/image_5.png" width=50 border=0 mce_src="http://blogs.microsoft.co.il/blogs/mcs/WindowsLiveWriter/d20b00ba5cce_FD44/image_5.png"&gt;&lt;/A&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; In my previous post -&amp;nbsp; &lt;A href="http://blogs.msdn.com/alikl/archive/2008/07/31/best-asp-net-performance-winner-for-data-binding-hands-up-to-response-write.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2008/07/31/best-asp-net-performance-winner-for-data-binding-hands-up-to-response-write.aspx"&gt;Best ASP.NET Performance Winner For Data Binding - Hands Up To Response.Write()&lt;/A&gt; – I’ve conducted several simple performance tests for data binding to GridView in ASP.NET page. What surprised me most is that eliminating massive loops and collection enumerations did not help in reducing CPU utilization. When we measured the execution times for both scenarios, DataBind() method revealed the secret. 
&lt;H3&gt;Reporting Execution Times&lt;/H3&gt;
&lt;P&gt;We used System.Diagnostics.Trace to report execution times.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;UseCustomCollection.aspx.cs&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   1:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"1. STARTING"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   2:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   3:&lt;/SPAN&gt; DataGrid datagrid = SampleServices.GenerateDynamicDataGridControl();&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   4:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;.Controls.Add(datagrid);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   5:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   6:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"2. GRID CREATED AND ADDED TO PAGE"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   7:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   8:&lt;/SPAN&gt; MyCollection myCollection = (MyCollection)SampleServices.GenerateCollection(200);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   9:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  10:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"3. CUSTOM COLLECTION CREATED"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  11:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  12:&lt;/SPAN&gt; datagrid.DataSource = myCollection;&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  13:&lt;/SPAN&gt; datagrid.DataBind();&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  14:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  15:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"5. DONE"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;STRONG&gt;UseDataTable.aspx.cs&lt;/STRONG&gt;&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   1:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"1. STARTING"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   2:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   3:&lt;/SPAN&gt; DataGrid datagrid = SampleServices.GenerateDynamicDataGridControl();&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   4:&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;this&lt;/SPAN&gt;.Controls.Add(datagrid);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   5:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   6:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"2. GRID CREATED AND ADDED TO PAGE"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   7:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   8:&lt;/SPAN&gt; MyCollection myCollection = (MyCollection)SampleServices.GenerateCollection(200);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;   9:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  10:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"3. CUSTOM COLLECTION CREATED"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  11:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  12:&lt;/SPAN&gt; DataTable datatable = SampleServices.ConvertCollectionTableIntoDataTalbe(myCollection);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  13:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  14:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"4. CUSTOM COLLECTION CONVERTED INTO DATATABLE"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  15:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  16:&lt;/SPAN&gt; datagrid.DataSource = datatable;&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  17:&lt;/SPAN&gt; datagrid.DataBind();&lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  18:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: white; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #606060"&gt;  19:&lt;/SPAN&gt; System.Diagnostics.Trace.WriteLine(&lt;SPAN style="COLOR: #006080"&gt;"5. DONE"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note, that &lt;STRONG&gt;UseCustomCollection.aspx.cs&lt;/STRONG&gt; misses step “4. CUSTOM COLLECTION CONVERTED INTO DATATABLE”. &lt;/P&gt;
&lt;H3&gt;Collecting Execution Times&lt;/H3&gt;
&lt;P&gt;We used &lt;A href="http://blogs.msdn.com/alikl/archive/2007/07/16/use-sysinternals-debugview-to-diagnose-the-application.aspx" target=_blank mce_href="http://blogs.msdn.com/alikl/archive/2007/07/16/use-sysinternals-debugview-to-diagnose-the-application.aspx"&gt;DebugView&lt;/A&gt; to collect reported execution times.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Testpost_13B58/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Testpost_13B58/image_2.png"&gt;&lt;IMG title=image style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=209 alt=image src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Testpost_13B58/image_thumb.png" width=539 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/Testpost_13B58/image_thumb.png"&gt;&lt;/A&gt;&amp;nbsp; &lt;/P&gt;
&lt;H3&gt;Analysis&lt;/H3&gt;
&lt;P&gt;Applying simple mathematics we can see that converting Collection to Datatable takes 0.00081015 seconds.&amp;nbsp; This is the gain we get when skipping this step in &lt;STRONG&gt;UseCustomCollection.aspx.cs&lt;/STRONG&gt;. &lt;/P&gt;
&lt;P&gt;Now lets examine DataBind() in both cases:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;UseCustomCollection.aspx.cs &lt;/STRONG&gt;0.00268023 seconds &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;UseDataTable.aspx.cs&lt;/STRONG&gt; 0.00215912 seconds &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;I know it is not a huge improvement for binding datatable vs. collection, but the tests we conducted always showed this gap. That is why eliminating the type transformation from collection to datatable that included enumeration and looping did not really help and we ended up with similar results of ~65% CPU utilization:&lt;/P&gt;
&lt;TABLE class="" cellSpacing=5 cellPadding=2 width=400 border=0&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=200&gt;&lt;STRONG&gt;UseDataTable.aspx&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=200&gt;&lt;STRONG&gt;UseCustomCollection.aspx&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="" vAlign=top width=200&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_2.png"&gt;&lt;IMG title=image height=372 alt=image src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb.png" width=225 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb.png"&gt;&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=200&gt;&lt;A href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_4.png" mce_href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_4.png"&gt;&lt;IMG title="ASP.NET Data Binding Performance" height=369 alt="ASP.NET Data Binding Performance" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb_1.png" width=241 border=0 mce_src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb_1.png"&gt;&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;H3&gt;Conclusion&lt;/H3&gt;
&lt;P&gt;Binding custom collection is expensive performance wise since internally it uses reflection and reflection is expensive thing to do. Looping is expensive performance wise too but it is cheaper than reflection. &lt;/P&gt;
&lt;H3&gt;Related Materials&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2008/07/20/use-free-tools-from-iis-resource-kit-to-warm-up-your-asp-net-1-1-application-by-batch-compilation.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2008/07/20/use-free-tools-from-iis-resource-kit-to-warm-up-your-asp-net-1-1-application-by-batch-compilation.aspx"&gt;Use FREE Tools From IIS Resource Kit To Warm Up Your ASP.NET 1.1 Application By Batch Compilation&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2008/05/05/asp-net-performance-engineering-stress-test-your-architecture-design-and-code.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2008/05/05/asp-net-performance-engineering-stress-test-your-architecture-design-and-code.aspx"&gt;ASP.NET Performance Engineering - Stress Test Your Architecture, Design, And Code&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2008/04/28/performance-sin-chatty-database-access-and-loops-plus-another-free-performance-tool.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2008/04/28/performance-sin-chatty-database-access-and-loops-plus-another-free-performance-tool.aspx"&gt;Performance Sin - Chatty Database Access And Loops (Plus Another Free Performance Tool)&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2008/03/09/stress-test-asp-net-web-application-with-free-wcat-tool.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2008/03/09/stress-test-asp-net-web-application-with-free-wcat-tool.aspx"&gt;Stress Test ASP.NET Web Application With Free WCAT Tool&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.msdn.com/alikl/archive/2008/01/21/performance-code-review-tool-practices-checker.aspx" mce_href="http://blogs.msdn.com/alikl/archive/2008/01/21/performance-code-review-tool-practices-checker.aspx"&gt;Performance Code Review Tool – Practices Checker&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8794452" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Planning+Phase/default.aspx">Planning Phase</category></item><item><title>Best ASP.NET Performance Winner For Data Binding - Hands Up To Response.Write()</title><link>http://blogs.msdn.com/alikl/archive/2008/07/31/best-asp-net-performance-winner-for-data-binding-hands-up-to-response-write.aspx</link><pubDate>Thu, 31 Jul 2008 15:29:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8793251</guid><dc:creator>alikl</dc:creator><slash:comments>21</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8793251.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8793251</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8793251</wfw:comment><description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://practicethis.com/" target="_blank"&gt;&lt;img title="Alik Levin" height="50" alt="Alik Levin" src="http://blogs.microsoft.co.il/blogs/mcs/WindowsLiveWriter/d20b00ba5cce_FD44/image_5.png" width="50" border="0" /&gt;&lt;/a&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; To achieve best performance you need to make decisions based on trade-off between coolness, coding productivity, and personal engineering values. I never thought I would be recommending my customer considering using old fashion Response.Write() in his Internet facing ASP.NET web application in order to significantly improve the application’s performance. &lt;/p&gt;  &lt;h3&gt;Customer Case Study&lt;/h3&gt;  &lt;p&gt;During load/stress testing customer’s ASP.NET web application we identified high CPU utilization (up to 90%). After quick investigation we noticed that &lt;strong&gt;%Time in GC&lt;/strong&gt; performance counter is less than optimal. Our assumption was that the application uses memory allocation techniques that are less than optimal. From &lt;a href="http://blogs.msdn.com/maoni/archive/2004/06/03/148029.aspx" target="_blank"&gt;GC Performance Counters&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;quot;First thing you may want to look at is &lt;b&gt;“% Time in GC”&lt;/b&gt;... What is a health value for this counter? It’s hard to say. It depends on what your app does. But if you are seeing a really high value (like 50% or more) then it’s a reasonable time to look at what’s going on inside of the managed heap.&amp;quot;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Another resource we used is timeless patterns &amp;amp; practices’ Chapter &lt;a href="http://msdn.microsoft.com/en-us/library/ms998579.aspx" target="_blank"&gt;15 — Measuring .NET Application Performance&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;.&lt;b&gt;NET CLR Memory\% Time in GC&lt;/b&gt;&lt;/p&gt;    &lt;p&gt;&amp;quot;…The most common cause of a high value is making too many allocations, which may be the case if you are allocating on a per-request basis for ASP.NET applications. You need to study the allocation profile for your application if this counter shows a higher value.&amp;quot; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;So we headed to looking into the code and this is what we found out.&lt;/p&gt;  &lt;h3&gt;Analysis&lt;/h3&gt;  &lt;p&gt;During &lt;a href="http://msdn.microsoft.com/en-us/library/ms998574.aspx" target="_blank"&gt;performance code inspection&lt;/a&gt; we identified massive usage of collections. The collections were used to transfer the data between the logical layers and then the collections were transferred into datatables to be bindable for DataGrid (yes, it is .Net 1.1 app). &lt;/p&gt;  &lt;p&gt;Eureka! We just spotted 3 performance anti-patterns. Massive memory allocation, massive loops, massive type conversions. I’ve shown it to 4 very respected professionals and everyone was saying the same – current situation is pure performance anti-pattern. Here are few suggestions that came up:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Bind collections directly to DataGrid eliminating additional memory allocations and loops. &lt;/li&gt;    &lt;li&gt;Create Datatable directly from XML skipping collection creation step eliminating additional memory allocations and loops. &lt;/li&gt;    &lt;li&gt;Use Xslt transformation transforming original Xml into Html table using Xslt elminating memory allocations and loops for both collections and datatables. &lt;/li&gt;    &lt;li&gt;Use Response.Write() as it’s suggested by &lt;a href="http://msdn.microsoft.com/en-us/library/ms998549.aspx" target="_blank"&gt;patterns &amp;amp; practices&lt;/a&gt;: &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&amp;quot;Use the &lt;b&gt;Response.Write&lt;/b&gt; method. It is one of the fastest ways to return output back to the browser.&amp;quot;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Case close? Not really...&lt;/p&gt;  &lt;p&gt;Secretly I’ve built Visual Studio 2003 project with these implementations and ran simple stress test using &lt;a href="http://blogs.msdn.com/alikl/archive/2008/07/20/use-free-tools-from-iis-resource-kit-to-warm-up-your-asp-net-1-1-application-by-batch-compilation.aspx" target="_blank"&gt;TinyGet&lt;/a&gt; utility. The results left us all a bit surprised.&lt;/p&gt;  &lt;h3&gt;Converting Collection To Datatable (Current Situation)&lt;/h3&gt;  &lt;p&gt;&lt;strong&gt;The code:&lt;/strong&gt;&lt;/p&gt;  &lt;div&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #008000"&gt;//create custom collection&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; MyCollection myCollection = (MyCollection)SampleServices.GenerateCollection(200);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; &lt;span style="color: #008000"&gt;//convert collection to datatable&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; DataTable datatable = SampleServices.ConvertCollectionTableIntoDataTalbe(myCollection);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; &lt;span style="color: #008000"&gt;//bind datatalbe to dynamically created datagrid&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt; datagrid.DataSource = datatable;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt; datagrid.DataBind();&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;&lt;strong&gt;The stress test:&lt;/strong&gt;&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;tinyget.exe&amp;#160; -srv:192.168.50.68 -uri:/dynamiccontrolsloadingrelease/UseDataTable.aspx -loop:100 -threads:15&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;&lt;strong&gt;The result:&lt;/strong&gt;&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_2.png"&gt;&lt;img title="image" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="353" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb.png" width="213" border="0" /&gt;&lt;/a&gt; &lt;/div&gt;

&lt;h3&gt;Bind Collection Directly To Grid&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The code:&lt;/strong&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; MyCollection myCollection = (MyCollection)SampleServices.GenerateCollection(200);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; &lt;span style="color: #008000"&gt;//bind datatalbe to dynamically created datagrid&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; datagrid.DataSource = myCollection;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; datagrid.DataBind();&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The stress test:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;tinyget.exe&amp;#160; -srv:192.168.50.68 -uri:/dynamiccontrolsloadingrelease/UseCustomCollection.aspx -loop:100 -threads:15&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The result:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_4.png"&gt;&lt;img title="image" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="372" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb_1.png" width="243" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;h3&gt;Create Datatable From Xml&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The code:&lt;/strong&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; xml = SampleServices.GenerateXml(200);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; StringReader theReader = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringReader(xml);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; DataSet theDataSet = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataSet();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt; theDataSet.ReadXml(theReader);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;  &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; datagrid.DataSource = theDataSet.Tables[0].DefaultView;;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt; datagrid.DataBind();&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The stress test:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;tinyget.exe&amp;#160; -srv:192.168.50.68 -uri:/dynamiccontrolsloadingrelease/LoadXmlIntoDataTable.aspx -loop:100 -threads:15 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The result:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_6.png"&gt;&lt;img title="image" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="434" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb_2.png" width="279" border="0" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;

&lt;h3&gt;Use Xslt Transformation To Create Html Table&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The code:&lt;/strong&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; Xml1.DocumentContent = SampleServices.GenerateXml(200);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; Xml1.TransformSource=&lt;span style="color: #006080"&gt;@&amp;quot;xsl.xml&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The stress test:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;tinyget.exe&amp;#160; -srv:192.168.50.68 -uri:/dynamiccontrolsloadingrelease/XmlXslTransformation.aspx -loop:100 -threads:15 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The result:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_8.png"&gt;&lt;img title="image" 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/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb_3.png" width="245" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h3&gt;Use Response.Write()&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;The code:&lt;/strong&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; MyCollection myCollection = (MyCollection)SampleServices.GenerateCollection(200);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; &lt;span style="color: #008000"&gt;// Put user code to initialize the page here&lt;/span&gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt; Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;table&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt;(MyModelItem item &lt;span style="color: #0000ff"&gt;in&lt;/span&gt;  myCollection)&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   9:&lt;/span&gt;     Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;tr&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  10:&lt;/span&gt;     Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt; +  item.Address  + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  11:&lt;/span&gt;     Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt; +  item.City  + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  12:&lt;/span&gt;     Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt; +  item.Education+ &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  13:&lt;/span&gt;     Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt; +  item.Family  + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  14:&lt;/span&gt;     Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt; +  item.Name  + &lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;td&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  15:&lt;/span&gt;     Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/tr&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  16:&lt;/span&gt; }&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;  17:&lt;/span&gt; Response.Write(&lt;span style="color: #006080"&gt;&amp;quot;&amp;lt;/table&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The stress test:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;tinyget.exe&amp;#160; -srv:192.168.50.68 -uri:/dynamiccontrolsloadingrelease/ResponseWrite.aspx -loop:100 -threads:15 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The result:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;/strong&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_10.png"&gt;&lt;img title="image" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="219" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/c1810fdf4ec4_8814/image_thumb_4.png" width="227" border="0" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;

&lt;h3&gt;Sample Visual Studio 2003 Project&lt;/h3&gt;

&lt;p&gt;Interested in testing it yourself? Grab the source code from my SkyDrive &lt;a href="http://cid-dd25b83e4ca261f7.skydrive.live.com/self.aspx/Visual%20Studio%20Projects/DynamicControlsLoading.zip" target="_blank"&gt;here&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/DynamicControlsLoading.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;After conducting this simple test these are the conclusions I’ve made:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;“Don't be afraid to challenge the pros, even in their own backyard.&amp;quot; - &lt;a href="http://jtaylorgoodlife.blogspot.com/2007/06/how-to-get-things-done-colin-powell.html" target="_blank"&gt;How to Get Things Done - Colin Powell Version&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;Testing IS DA thing. Assumptions are good but nothing speaks louder than facts. &lt;/li&gt;

  &lt;li&gt;Test early - avoid massive rework afterwards. Create POC's (Proof of concept) early in architecture/design stages. &lt;/li&gt;

  &lt;li&gt;Best performance comes on expense of productivity and coolness. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Related Materials&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/07/20/use-free-tools-from-iis-resource-kit-to-warm-up-your-asp-net-1-1-application-by-batch-compilation.aspx"&gt;Use FREE Tools From IIS Resource Kit To Warm Up Your ASP.NET 1.1 Application By Batch Compilation&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/05/05/asp-net-performance-engineering-stress-test-your-architecture-design-and-code.aspx"&gt;ASP.NET Performance Engineering - Stress Test Your Architecture, Design, And Code&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/04/28/performance-sin-chatty-database-access-and-loops-plus-another-free-performance-tool.aspx"&gt;Performance Sin - Chatty Database Access And Loops (Plus Another Free Performance Tool)&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/03/09/stress-test-asp-net-web-application-with-free-wcat-tool.aspx"&gt;Stress Test ASP.NET Web Application With Free WCAT Tool&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/01/21/performance-code-review-tool-practices-checker.aspx"&gt;Performance Code Review Tool – Practices Checker&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8793251" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Planning+Phase/default.aspx">Planning Phase</category></item><item><title>Use FREE Tools From IIS Resource Kit To Warm Up Your ASP.NET 1.1 Application By Batch Compilation</title><link>http://blogs.msdn.com/alikl/archive/2008/07/20/use-free-tools-from-iis-resource-kit-to-warm-up-your-asp-net-1-1-application-by-batch-compilation.aspx</link><pubDate>Sun, 20 Jul 2008 18:24:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8758682</guid><dc:creator>alikl</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8758682.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8758682</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8758682</wfw:comment><description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;Have you noticed that when ASP.NET web application is accessed for the first time the response is slow? The reason for such behavior is batch compilation that occurs on the first hit.&lt;/p&gt;  &lt;p&gt;ASP.NET batch compilation is the process of compiling ASP.NET markup (content of aspx files) into temporary dll’s. Compilation requires invoking compiler (csc.exe for C#) – that is pretty heavy activity. &lt;a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" target="_blank"&gt;Process Explorer&lt;/a&gt; shows it clearly:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.1BatchCompilationWarmYourWebApplicat_11CE0/image_2.png"&gt;&lt;img title="ASP.NET Batch compilation" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="57" alt="ASP.NET Batch compilation" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.1BatchCompilationWarmYourWebApplicat_11CE0/image_thumb.png" width="550" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;ASP.NET batch compilation occurs on per folder basis. Said that, if your application divided into multiple sub-folders that contain ASP.NET pages each time any of the folders accessed for the first time the batch compilation is invoked.&lt;/p&gt;  &lt;p&gt;Note that starting with &lt;font color="#ff0000"&gt;&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc163675.aspx" target="_blank"&gt;ASP.NET 2.0 compilation model&lt;/a&gt;&lt;/font&gt; has changed. Also, there is a tool &lt;a href="http://msdn.microsoft.com/en-us/library/ms229863(VS.80).aspx" target="_blank"&gt;Aspnet_compiler.exe&lt;/a&gt; that allows pre-compile your ASP.NET web application to improve performance.&lt;/p&gt;  &lt;h3&gt;Customer’s case study&lt;/h3&gt;  &lt;p&gt;Customer’s web application is built with ASP.NET 1.1. It is divided into multiple subfolders reflecting logical modules that are hosted across about 20 application pools. The application connects to Oracle database. &lt;/p&gt;  &lt;p&gt;QA team complains that the application responds slowly each time any of the modules (subfolders) accessed for the first time.&lt;/p&gt;  &lt;p&gt;Using Process Explorer and profiler we identified three main latency points:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Creating the application pool – w3wp.exe. &lt;/li&gt;    &lt;li&gt;Batch compiling the application for each subfolder. &lt;/li&gt;    &lt;li&gt;Creating Oracle connection pool when Oracle is accessed for the first time. &lt;/li&gt; &lt;/ul&gt;  &lt;h3&gt;The solution&lt;/h3&gt;  &lt;p&gt;We decided to create a Warmer – solution that will hit each subfolder’s page in unattended manner thus warming up the application before the first user hits it.&lt;/p&gt;  &lt;p&gt;For the solution we used free tools from &lt;font color="#ff0000"&gt;&lt;strong&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=56FC92EE-A71A-4C73-B628-ADE629C89499&amp;amp;displaylang=en" target="_blank"&gt;IIS resource&lt;/a&gt;&lt;/strong&gt;&lt;/font&gt; kit:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=890cd06b-abf8-4c25-91b2-f8d975cf8c07&amp;amp;displaylang=en" target="_blank"&gt;LogPrser.exe&lt;/a&gt;&lt;/strong&gt; to identify the URL’s of the pages to hit. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;&lt;a href="http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/993a8a36-5761-448f-889e-9ae58d072c09.mspx?mfr=true" target="_blank"&gt;TinyGet.exe&lt;/a&gt;&lt;/strong&gt; to actually hit the pages identified by LogParser. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;To identify what pages to hit we took IIS log files from QA environment and than we ran the following query using LogParser:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;LogParser.exe &amp;quot;SELECT DISTINCT STRCAT('XXX', cs-uri-stem) AS cs-uri-stem-strcat INTO 'C:\result.txt' FROM 'C:\yourIISlogFile.log' WHERE INDEX_OF(cs-uri-stem, 'aspx') &amp;gt; 0&amp;quot; -o:w3c&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Notice XXX – it has nothing to do with XXX rated content rather it is a placeholder to replace it with tinyget command.&lt;/p&gt;  &lt;p&gt;Open resulting yourIISlogFile.log file in Notepad, hit Ctrl+H for “Replace” and replace all occurrences of XXX with the following command:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;tinyget -srv:www.YourServer.com -uri:&lt;/p&gt;    &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.1BatchCompilationWarmYourWebApplicat_11CE0/image_10.png"&gt;&lt;img title="ASP.NET Batch Compilation" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="193" alt="ASP.NET Batch Compilation" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.1BatchCompilationWarmYourWebApplicat_11CE0/image_thumb_4.png" width="365" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;yourIISlogFile.log before the Replace:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.1BatchCompilationWarmYourWebApplicat_11CE0/image_6.png"&gt;&lt;img title="image" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="158" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.1BatchCompilationWarmYourWebApplicat_11CE0/image_thumb_2.png" width="271" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;yourIISlogFile.log after the Replace:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.1BatchCompilationWarmYourWebApplicat_11CE0/image_8.png"&gt;&lt;img title="image" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="127" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ASP.1BatchCompilationWarmYourWebApplicat_11CE0/image_thumb_3.png" width="584" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Remove the header and save the file with BAT extension&amp;#160; - your Warmer is ready for action. Run it each time you deploy new version.&lt;/p&gt;  &lt;p&gt;Do not forget to remove old temporary files in ASP.NET temporary folder:&lt;/p&gt;  &lt;p&gt;C:\Windows\Microsoft.NET\Framework\&amp;lt;&amp;lt;NET FX VERSION&amp;gt;&amp;gt;\Temporary ASP.NET Files\&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;CAUTION&lt;/em&gt;.&lt;/strong&gt; This action may potentially corrupt your application if you do not provide proper exception handling. On one hand it is good check to make. on other hand – be aware of it and do not do it on production sites unless you are completely sure it will not corrupt the application.&lt;/p&gt;  &lt;h3&gt;Related materials&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2006/04/11/442448.aspx"&gt;Don’t run production ASP.NET Applications with debug=”true” enabled&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/tess/archive/2006/04/13/575364.aspx"&gt;ASP.NET Memory: If your application is in production… then why is debug=true&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/03/09/stress-test-asp-net-web-application-with-free-wcat-tool.aspx"&gt;Stress Test ASP.NET Web Application With Free WCAT Tool&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/04/21/free-performance-tool-analyze-iis-logs-like-a-pro-with-funnel-web-analyzer.aspx" target="_blank"&gt;Free Performance Tool - Analyze IIS Logs Like A Pro With Funnel Web Analyzer&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/11/02/identify-asp-net-web-services-and-wcf-performance-issues-by-examining-iis-logs.aspx"&gt;Identify ASP.NET, Web Services, And WCF Performance Issues By Examining IIS Logs&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8758682" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Deployment+Phase/default.aspx">Deployment Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category></item><item><title>Pitfalls With .Net Multithreading And COM Objects – Threads Must Have Compatible Apartment Models (MTA vs. STA)</title><link>http://blogs.msdn.com/alikl/archive/2008/06/20/pitfalls-with-net-multithreading-and-com-objects-threads-must-have-compatible-apartment-models-mta-vs-sta.aspx</link><pubDate>Fri, 20 Jun 2008 10:09:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8624899</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8624899.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8624899</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8624899</wfw:comment><description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;Be alert when implementing multithreading .Net in conjunction with COM objects. Thread apartment models matter.&lt;/p&gt;  &lt;p&gt;.Net threads have Multi Threaded Apartment (MTA) model by default. COM objects have Single Thread Apartment (STA). Calling on COM objects on .Net threads that you spawn may cause unpredicted result. &lt;/p&gt;  &lt;p&gt;Multithreading in .Net is easily implemented based on either Thread or ThreadPool objects. Thread.Start() method spawns new thread which has Multi Threaded Apartment (MTA) model . ThreadPool.QueueUserWorkItem(myMethod) queues myMethod to be executed on available thread managed by it.&lt;/p&gt;  &lt;h3&gt;Thread object and COM&lt;/h3&gt;  &lt;p&gt;When spawning your own threads with Thread.Start() set Thread’s apartment model to STA if you plan calling COM object on it:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; Thread t = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Thread(DoWork);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; t.SetApartmentState(ApartmentState.STA);&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt; t.Start();&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Note, spawning your own threads with Thread.Start() utilizes resources – mainly CPU, spawning too much threads may cause performance hit. Consider using ThreadPool object.&lt;/p&gt;

&lt;h3&gt;ThreadPool object and COM&lt;/h3&gt;

&lt;p&gt;All threads managed by ThreadPool objects are MTA threads. Apartment model of ThreadPool’s threads cannot be changed. Do not call COM objects on ThreadPool’s threads.&lt;/p&gt;

&lt;h3&gt;Possible designs and solutions&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;ASP.NET.&lt;/strong&gt; Calling COM objects in ASP.NET pages configure &lt;a href="http://msdn.microsoft.com/en-us/library/zwk9h2kb.aspx"&gt;AspCompat=true&lt;/a&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;“Most COM components will work with ASP.NET…”&lt;/p&gt;

  &lt;p&gt;“…The AspCompat attribute forces the page to execute in STA mode. The runtime throws an exception if the compatibility tag is omitted and an STA component is referenced on the page.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Client side (like WinForms)multithreading&lt;/strong&gt;. Use ThreadPool with its MTA threads. Spawn another thread with Thread.Start() setting its apartment model to STA. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;Custom server side multithreading&lt;/strong&gt;. I’d consider using Remoting infrastructure. In case your server application should serve messages that are not covered by Remoting’s built in mechanisms I’d consider building my own &lt;a href="http://msdn.microsoft.com/en-us/library/aa309086(VS.71).aspx"&gt;Channel sink&lt;/a&gt;. &lt;/li&gt;

  &lt;li&gt;&lt;strong&gt;And the last but not the least&lt;/strong&gt;. Do not forget to call Marshal.ReleaseComObject(obj) to dispose the COM objects created on your the threads. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Related materials&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms998551.aspx"&gt;Chapter 7 — Improving Interop Performance&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms998565.aspx" target="_blank"&gt;Chapter 11 — Improving Remoting Performance&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms979193.aspx" target="_blank"&gt;How To: Improve Serialization Performance&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8624899" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Planning+Phase/default.aspx">Planning Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Threading/default.aspx">Threading</category></item><item><title>WCF Security - Input/Data Validation Using Schemas</title><link>http://blogs.msdn.com/alikl/archive/2008/05/25/wcf-security-input-data-validation-using-schemas.aspx</link><pubDate>Sun, 25 May 2008 17:52:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8551021</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8551021.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8551021</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8551021</wfw:comment><description>&lt;p&gt;WCF offers very flexible approach of Input and Data Validation based on XML Schemas. The approach is flexible since the validation rules are expressed in form of XML schema and can be changed at any time without recompiling the solution.&lt;/p&gt;  &lt;p&gt;I followed the steps detailed in &lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Perform%20Message%20Validation%20with%20Schemas%20in%20WCF&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To: Perform Message Validation with Schema Validation in WCF&lt;/a&gt; and ended up with another working sample (imagine that!).&lt;/p&gt;  &lt;p&gt;It took me a bit to struggle with the schema thing and then &lt;a href="http://msdn.microsoft.com/en-us/library/ms788993.aspx" target="_blank"&gt;enabling debugging&lt;/a&gt; info on the service side (remember, WCF is secure by default) to understand what's going on and why it fails time after time.&lt;/p&gt;  &lt;p&gt;In the end me and WCF made friends and I'd thought it'd be good to share with you the Visual Studio project. Download it &lt;a href="http://cid-dd25b83e4ca261f7.skydrive.live.com/self.aspx/Visual%20Studio%20Projects/WCFInputValidationSchema.zip" target="_blank"&gt;here&lt;/a&gt; from my SkyDrive and save yourself some time. &lt;/p&gt;  &lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/WCFInputValidationSchema.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;  &lt;h3&gt;My related posts&lt;/h3&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/05/25/wcf-security-input-data-validation-sample-visual-studio-project.aspx"&gt;WCF Security - Input/Data Validation Sample Visual Studio Project&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Enjoy.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8551021" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category></item><item><title>WCF Security - Input/Data Validation Sample Visual Studio Project</title><link>http://blogs.msdn.com/alikl/archive/2008/05/25/wcf-security-input-data-validation-sample-visual-studio-project.aspx</link><pubDate>Sun, 25 May 2008 14:17:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8550886</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8550886.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8550886</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8550886</wfw:comment><description>&lt;p&gt;Input and Data Validation is one of the &lt;a href="http://shapingsoftware.com/2008/04/07/security-frame/" target="_blank"&gt;core security principles&lt;/a&gt;. &lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/04/how-to-hack-wcf-new-technology-old-hacking-tricks.aspx" target="_blank"&gt;WCF is no exception&lt;/a&gt;. To get most out of WCF in secure way one must implement proper Input and Data Validation.&lt;/p&gt;  &lt;p&gt;I was following instructions on &lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Perform%20Input%20Validation%20in%20WCF&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To &amp;#8211; Perform Input Validation in WCF&lt;/a&gt; compiled by patterns&amp;amp;practice team lead by &lt;a href="http://blogs.msdn.com/jmeier" target="_blank"&gt;JD Meier&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In a nutshell the process consists of creating 3 classes and tweaking a config file a &amp;quot;bit&amp;quot;.&lt;/p&gt;  &lt;p&gt;From the guide:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Step 4 &amp;#8211; Create a Class That Implements the Validation Logic &lt;/li&gt;    &lt;li&gt;Step 5 &amp;#8211; Create a Class That Implements a Custom Endpoint Behavior &lt;/li&gt;    &lt;li&gt;Step 6 &amp;#8211; Create a Class That Implements a Custom Configuration Element &lt;/li&gt;    &lt;li&gt;Step 7 &amp;#8211; Add the Custom Behavior to the Configuration File &lt;/li&gt;    &lt;li&gt;Step 8 &amp;#8211; Create an Endpoint Behavior and Map It to Use the Custom Behavior &lt;/li&gt;    &lt;li&gt;Step 9 &amp;#8211; Configure the Service Endpoint to Use the Endpoint Behavior &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I ended up with working sample built with Visual Studio 2008. I though it'd be good idea to share it to help you boost your productivity.&lt;/p&gt;  &lt;p&gt;Grab the Visual Studio project on my SkyDrive &lt;a href="http://cid-dd25b83e4ca261f7.skydrive.live.com/self.aspx/Visual%20Studio%20Projects/WCFInputValidation.zip" target="_blank"&gt;here&lt;/a&gt;. &lt;/p&gt; &lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/WCFInputValidation.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;Enjoy&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8550886" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Input+Validation/default.aspx">Input Validation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category></item><item><title>ASP.NET Performance Sin - Serving Images Dynamically (Or Another Reason To Love Fiddler)</title><link>http://blogs.msdn.com/alikl/archive/2008/05/02/asp-net-performance-sin-serving-images-dynamically-or-another-reason-to-love-fiddler.aspx</link><pubDate>Fri, 02 May 2008 16:12:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8450457</guid><dc:creator>alikl</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8450457.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8450457</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8450457</wfw:comment><description>&lt;p&gt;Serving images dynamically may cause performance hit. Dynamically served images require more HTTP requests which violates &lt;a href="http://stevesouders.com/bio.html" target="_blank"&gt;Steve Souders'&lt;/a&gt; performance rule #1 - &lt;a href="http://developer.yahoo.com/performance/rules.html#num_http"&gt;Make Fewer HTTP Requests&lt;/a&gt;. The latency is also caused by parallelism (or parallel downloading) limitations as described in detail here &lt;a href="http://yuiblog.com/blog/2007/04/11/performance-research-part-4/"&gt;Performance Research, Part 4: Maximizing Parallel Downloads in the Carpool Lane&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;Static Images&lt;/h3&gt;  &lt;p&gt;Below are the series of images that served dynamically and static.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="244" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/PerformanceSinServingImagesDynamically_BD45/image_11.png" width="157" border="0" /&gt; &lt;/p&gt;  &lt;p&gt;Static images displayed using GridView's ImageFiled column type. ImageField generates the following HTML mark-up:&lt;/p&gt;  &lt;div&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;img&lt;/span&gt; &lt;span style="color: #ff0000"&gt;src&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;IMAGES/Birds/icon-penguin.gif&amp;quot;&lt;/span&gt; &lt;span style="color: #ff0000"&gt;style&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;border-width:0px;&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Browser interprets it as a static image and is ready to cache it for further reuse.&lt;/p&gt;

&lt;h3&gt;Serving Images Dynamically&lt;/h3&gt;

&lt;p&gt;Below is the sample code that implements dynamic image serving. I witness in the field different variation but the pattern (I'd call it anti-pattern) remains the same. ASP.NET and HTML mark-up that is usually part of repeater control looks similar to the following:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #800000"&gt;img&lt;/span&gt; &lt;span style="color: #ff0000"&gt;src&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&amp;quot;ServeImage.ashx?FN = &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;%#DataBinder.GetPropertyValue(Container.DataItem, &amp;quot;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;Image&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;)%&amp;gt;&amp;quot;&lt;/span&gt; &lt;span style="color: #0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;&lt;/span&gt;&amp;#160;&lt;/p&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;ASHX file's code that actually serves the image looks similar to this:&lt;/p&gt;

&lt;div&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ProcessRequest(HttpContext context)
{
    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; imageFileName = &lt;/p&gt;&lt;p&gt;           context.Request.MapPath(&lt;span style="color: #006080"&gt;@&amp;quot;IMAGES\&amp;quot; + context.Request.QueryString[&amp;quot;&lt;/span&gt;FN&lt;span style="color: #006080"&gt;&amp;quot;]);

    context.Response.ContentType = &amp;quot;&lt;/span&gt;image/jpeg&amp;quot;;
    context.Response.WriteFile(imageFileName);
    context.Response.Flush();
    context.Response.Close();

}&lt;/p&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3&gt;Network Analysis&lt;/h3&gt;

&lt;p&gt;Using one of my most favorite tools - &lt;a href="http://www.fiddler2.com/fiddler2/" target="_blank"&gt;Fiddler&lt;/a&gt; - it is easy to reveal browser's view on the traffic:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/PerformanceSinServingImagesDynamically_BD45/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="100" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/PerformanceSinServingImagesDynamically_BD45/image_thumb_1.png" width="539" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is expiration attribute attached to static images while dynamically served images do not have such attribute. &lt;/p&gt;

&lt;p&gt;Subsequent call the the same page that gets the same images reveals the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/PerformanceSinServingImagesDynamically_BD45/image_8.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="149" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/PerformanceSinServingImagesDynamically_BD45/image_thumb_3.png" width="538" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All dynamically served images are not cached and utilize the network on each request. &lt;/p&gt;

&lt;p&gt;Further investigation shows, using &lt;a href="http://blogs.msdn.com/alikl/archive/2007/10/17/improve-web-application-performance-by-reducing-number-of-http-requests-fiddler-to-the-rescue.aspx" target="_blank"&gt;Fiddler's P and C fantastic feature&lt;/a&gt;, that overall network utilization caused by these dynamically served images is about 350 KB, which could be saved by caching the images.&lt;/p&gt;

&lt;h3&gt;Recommendations&lt;/h3&gt;

&lt;p&gt;Avoid serving images dynamically. Follow best practices outlined at &lt;a href="http://developer.yahoo.com/performance/" target="_blank"&gt;Exceptional Performance&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#num_http" target="_blank"&gt;Make Fewer HTTP Requests&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#dns_lookups" target="_blank"&gt;Reduce DNS Lookups&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#redirects" target="_blank"&gt;Avoid Redirects&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#cacheajax" target="_blank"&gt;Make Ajax Cacheable&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#postload" target="_blank"&gt;Post-load Components&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#preload" target="_blank"&gt;Preload Components&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#min_dom" target="_blank"&gt;Reduce the Number of DOM Elements&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#split" target="_blank"&gt;Split Components Across Domains&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#iframes" target="_blank"&gt;Minimize the Number of iframes&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://developer.yahoo.com/performance/rules.html#no404" target="_blank"&gt;No 404s&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;My relative posts&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/04/28/performance-sin-chatty-database-access-and-loops-plus-another-free-performance-tool.aspx"&gt;Performance Sin - Chatty Database Access And Loops (Plus Another Free Performance Tool)&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2008/02/02/performance-sin-using-exceptions-to-control-flow.aspx"&gt;Performance Sin - Using Exceptions To Control Flow&lt;/a&gt;&amp;#160; &lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8450457" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Test+Phase/default.aspx">Test Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Tools/default.aspx">Tools</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Planning+Phase/default.aspx">Planning Phase</category></item><item><title>patterns &amp; practices WCF Security Guidance Project - live on Codeplex</title><link>http://blogs.msdn.com/alikl/archive/2008/04/02/patterns-practices-wcf-security-guidance-project-live-on-codeplex.aspx</link><pubDate>Wed, 02 Apr 2008 10:53:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8350230</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/8350230.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=8350230</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=8350230</wfw:comment><description>&lt;p&gt;patterns &amp;amp; practices has recently released &lt;a href="http://www.codeplex.com/WCFSecurity/" target="_blank"&gt;WCF Security Guidance Project&lt;/a&gt;. &lt;a href="http://blogs.msdn.com/jmeier/" target="_blank"&gt;JD&lt;/a&gt;, the program manager behind the effort, &lt;a href="http://blogs.msdn.com/jmeier/archive/2008/03/27/patterns-and-practices-wcf-security-guidance-now-available.aspx" target="_blank"&gt;has been blogging about it&lt;/a&gt; too.It is evolving project but the initial content is fantastic already. It has &lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=Application%20Scenarios&amp;amp;referringTitle=Home" target="_blank"&gt;Application Scenarios&lt;/a&gt;, &lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=Video%20Index&amp;amp;referringTitle=Home" target="_blank"&gt;Video Index&lt;/a&gt;, but my favorites are How-To's:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Create%20and%20Install%20Temporary%20Certificates%20in%20WCF%20for%20Message%20Security%20During%20Development&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Create and Install Temporary Certificates in WCF for Message Security During Development&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Create%20and%20Install%20Temporary%20Certificates%20in%20WCF%20for%20Transport%20Security%20during%20Development&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Create and Install Temporary Certificates in WCF for Transport Security during Development&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Impersonate%20the%20Original%20Caller%20in%20WCF%20calling%20from%20Web%20Application&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Impersonate the Original Caller in WCF calling from Web Application&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Impersonate%20the%20Original%20Caller%20in%20WCF%20calling%20from%20Windows%20Forms&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Impersonate the Original Caller in WCF calling from Windows Forms&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Use%20netTcpBinding%20with%20Windows%20Authentication%20and%20Transport%20Security%20in%20WCF%20from%20Windows%20Forms&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Use netTcpBinding with Windows Authentication and Transport Security in WCF from Windows Forms&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Use%20SQL%20Role%20Provider%20with%20Username%20Authentication%20in%20WCF%20calling%20from%20Windows%20Forms&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Use SQL Role Provider with Username Authentication in WCF calling from Windows Forms&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Use%20SQL%20Role%20Provider%20with%20Windows%20Authentication%20in%20WCF%20calling%20from%20Windows%20Forms&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Use SQL Role Provider with Windows Authentication in WCF calling from Windows Forms&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Use%20Username%20Authentication%20with%20the%20SQL%20Membership%20Provider%20and%20Message%20Security%20in%20WCF%20from%20Windows%20Forms&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Use Username Authentication with the SQL Membership Provider and Message Security in WCF from Windows Forms&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Use%20wsHttpBinding%20with%20Windows%20Authentication%20and%20Message%20Security%20in%20WCF%20from%20Windows%20Forms&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Use wsHttpBinding with Windows Authentication and Message Security in WCF from Windows Forms&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.codeplex.com/WCFSecurity/Wiki/View.aspx?title=How%20To%20-%20Use%20wsHttpBinding%20with%20Windows%20Authentication%20and%20Transport%20Security%20in%20WCF%20calling%20from%20Windows%20Forms&amp;amp;referringTitle=How%20Tos" target="_blank"&gt;How To - Use wsHttpBinding with Windows Authentication and Transport Security in WCF calling from Windows Forms&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Pure love.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8350230" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Practices/default.aspx">Practices</category></item><item><title>How To Consume WCF Using AJAX Without ASP.NET</title><link>http://blogs.msdn.com/alikl/archive/2008/02/18/how-to-consume-wcf-using-ajax-without-asp-net.aspx</link><pubDate>Mon, 18 Feb 2008 23:35:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7779790</guid><dc:creator>alikl</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/alikl/comments/7779790.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=7779790</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=7779790</wfw:comment><description>&lt;p&gt;How to consume WCF services directly from Html client? How to add AJAX-like functionally to application that does not natively support ASP.NET AJAX like classic ASP, ASP.NET 1.1, or PHP?&lt;/p&gt;  &lt;p&gt;WCF that ships with .Net 3.5 provides capability to consume it from any JavaScript enabled client via XML or JSON encoding. There is new built in webHttpBinding that supports either JSON or XML encoded messages to be sent to WCF services.The functionality can dramatically improve performance and user experience.&lt;/p&gt;  &lt;p&gt;This post summarizes the steps to create and consume basic WCF service using webHttpBinding binding. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Summary of Steps &lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Step 1 &amp;#8211; Create WCF service.&lt;/b&gt; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Step 2 &amp;#8211; Configure WCF end point.&lt;/b&gt; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Step 3 &amp;#8211; Create JavaScript to invoke WCF service.&lt;/b&gt; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Step 4 &amp;#8211; Test the solution.&lt;/b&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Next section describes each and every step in details&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Step 1 &amp;#8211; Create WCF service&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Open Visual Studio and create new WCF service project by choosing &amp;quot;WCF Service Application&amp;quot; template under &amp;quot;Web&amp;quot; project type. Name it Wcf2Ajax. Open IService1.cs file and create OperationContract as follows:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; [ServiceContract]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt;  &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IService1&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;  {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;      [OperationContract]&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;      &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Sum2Integers(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; n1, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; n2);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Open Service1.svc.cs file and add public method that accepts to integers and returns the sum of it. This is the functionality that will be exposed by the WCF service and consumed by JavaScript enabled client:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Service1 : IService1&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   3:&lt;/span&gt;     &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Sum2Integers(&lt;span style="color: #0000ff"&gt;int&lt;/span&gt; n1, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; n2)&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   5:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; result = num1 + num2;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   7:&lt;/span&gt;         &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; result.ToString();&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt;   8:&lt;/span&gt;     }&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;b&gt;Step 2 &amp;#8211; Configure WCF end point&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Open web.config file and add &amp;lt;binding&amp;gt; section to &amp;lt;system.serviceModel section. Add &amp;lt;webHttpBinding&amp;gt; to binding section:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;system.serviceModel&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;bindings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;webHttpBinding&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;binding &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;AjaxBinding&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;webHttpBinding&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;bindings&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Add AjaxBehavior to &amp;lt;behaviors&amp;gt; section to support WCF invocation via AJAX:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;behaviors&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;endpointBehaviors&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;behavior &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;AjaxBehavior&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;enableWebScript&lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;behavior&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Configure WCF service's endpoint to use newly created binding:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;endpoint &lt;/span&gt;&lt;span style="color: red"&gt;address&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ajaxEndpoint&lt;/span&gt;&amp;quot; 
          &lt;span style="color: red"&gt;behaviorConfiguration&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;AjaxBehavior&lt;/span&gt;&amp;quot; 
          &lt;span style="color: red"&gt;binding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;webHttpBinding&lt;/span&gt;&amp;quot; 
          &lt;span style="color: red"&gt;bindingConfiguration&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;AjaxBinding&lt;/span&gt;&amp;quot; 
          &lt;span style="color: red"&gt;contract&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Wcf2Ajax.IService1&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;b&gt;Step 3 &amp;#8211; Create JavaScript to invoke WCF service&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Add Html file to the solution by right clicking on the solution node in solution explorer and choosing &amp;quot;New Item...&amp;quot; and then &amp;quot;HTML Page&amp;quot; template. Name it WCFConsumer.htm. Add few HTML controls - two text boxes to accept two integers, one pure HTML button to trigger WCF call, and &amp;lt;span&amp;gt; element to present the result:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;num1&amp;quot; /&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;num2&amp;quot; /&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;br&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;button&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;onclick&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;CallWcfAjax()&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;Call WCF via AJAX&amp;quot; /&amp;gt;
&lt;/span&gt;Result &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;span &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;result&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;span&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Add &amp;lt;script&amp;gt; block to &amp;lt;header&amp;gt; section and add JavaSctip that builds HTTP request and wires invocation function to some event, say button click:&lt;/p&gt;

&lt;pre class="code"&gt;    &lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;script &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;
    function &lt;/span&gt;CallWcfAjax()
    {
        &lt;span style="color: blue"&gt;var &lt;/span&gt;xmlHttp = &lt;span style="color: blue"&gt;new &lt;/span&gt;ActiveXObject(&lt;span style="color: #a31515"&gt;&amp;quot;Microsoft.XmlHttp&amp;quot;&lt;/span&gt;);

        &lt;span style="color: blue"&gt;var &lt;/span&gt;url = &lt;span style="color: #a31515"&gt;&amp;quot;Service1.svc/ajaxEndpoint/&amp;quot;&lt;/span&gt;;
        url = url + &lt;span style="color: #a31515"&gt;&amp;quot;Sum2Integers&amp;quot;&lt;/span&gt;;

        &lt;span style="color: blue"&gt;var &lt;/span&gt;body = &lt;span style="color: #a31515"&gt;'{&amp;quot;n1&amp;quot;:'&lt;/span&gt;;
        body = body + document.getElementById(&lt;span style="color: #a31515"&gt;&amp;quot;num1&amp;quot;&lt;/span&gt;).value + &lt;span style="color: #a31515"&gt;',&amp;quot;n2&amp;quot;:'&lt;/span&gt;;
        body = body + document.getElementById(&lt;span style="color: #a31515"&gt;&amp;quot;num2&amp;quot;&lt;/span&gt;).value + &lt;span style="color: #a31515"&gt;'}'&lt;/span&gt;;
          
        &lt;span style="color: green"&gt;// Send the HTTP request
        &lt;/span&gt;xmlHttp.open(&lt;span style="color: #a31515"&gt;&amp;quot;POST&amp;quot;&lt;/span&gt;, url, &lt;span style="color: blue"&gt;true&lt;/span&gt;);
        xmlHttp.setRequestHeader(&lt;span style="color: #a31515"&gt;&amp;quot;Content-type&amp;quot;&lt;/span&gt;, &lt;span style="color: #a31515"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;);
        xmlHttp.send(body);

        &lt;span style="color: green"&gt;// Create result handler 
        &lt;/span&gt;xmlHttp.onreadystatechange= &lt;span style="color: blue"&gt;function &lt;/span&gt;X()
        {
        
             &lt;span style="color: blue"&gt;if&lt;/span&gt;(xmlHttp.readyState == 4)
             {
                  &lt;span style="color: #a31515"&gt;&lt;font color="#333333"&gt;result.innerText&lt;/font&gt;&lt;/span&gt; = xmlHttp.responseText;
             }
        }
    }
    &lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;b&gt;Step 4 &amp;#8211; Test the solution&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Build the solution and navigate to WCFConsumer.htm. Provide two integers to both text boxes and hit &amp;quot;Call WCF via Ajax&amp;quot; button. You should expect for result similar as depicted below:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ConsumeWCFServiceByAnyJavaScriptEnabledC_710F/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="123" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ConsumeWCFServiceByAnyJavaScriptEnabledC_710F/image_thumb.png" width="381" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Parse the result to your needs.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;b&gt;My related post&lt;/b&gt;

&lt;p&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/12/31/asp-net-ajax-control-toolkit-basic-sample-for-dynamicpopulate-control.aspx"&gt;ASP.NET AJAX Control Toolkit - Basic Sample For DynamicPopulate Control&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/10/03/ajax-security-client-side-validation-is-for-usability-only-not-for-security.aspx"&gt;AJAX Security - Client Side Validation Is For Usability Only, Not For Security&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/07/26/wcf-security-in-intranet-scenario-thoughts-on-cons-and-pros.aspx"&gt;WCF Security In Intranet Scenario : Thoughts On Cons and Pros&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;Related resources&lt;/b&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/bb885100.aspx" target="_blank"&gt;Creating WCF AJAX Services without ASP.NET&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Download Visual Studio 2008 project with the sample from my SkyDrive&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;
&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/Wcf2Ajax.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7779790" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/WCF/default.aspx">WCF</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Planning+Phase/default.aspx">Planning Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/AJAX/default.aspx">AJAX</category></item><item><title>Chain Of Responsibility Design Pattern – Focus On Security, Performance, And Operations</title><link>http://blogs.msdn.com/alikl/archive/2008/01/14/chain-of-responsibility-design-pattern-focus-on-security-performance-and-operations.aspx</link><pubDate>Mon, 14 Jan 2008 18:50:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7108994</guid><dc:creator>alikl</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/alikl/comments/7108994.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=7108994</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=7108994</wfw:comment><description>&lt;p&gt;The pattern is also called Intercepting Filter, Pipeline, AOP, and may be few more&amp;#8230; I am confused by the name for this design pattern. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://thinkexist.com/quotation/life_is_really_simple-but_we_insist_on_making_it/201092.html" target="_blank"&gt;&amp;#8220;Life is really simple, but we insist on making it complicated.&amp;#8221;&lt;/a&gt; - Confucius &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;No matter how they call it I like the idea of decoupling actions while processing one after another. Here is the definition from &lt;a href="http://www.dofactory.com/Patterns/PatternChain.aspx" target="_blank"&gt;data &amp;amp; object factory&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Intercepting Filter visual from MSDN&amp;#8217;s &lt;a href="http://msdn.microsoft.com/msdnmag/issues/05/07/DesignPatterns/#S10" target="_blank"&gt;Discover the Design Patterns You're Already Using in the .NET Framework&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ChainOfResponsibilityDesignPatternFocusO_DFF4/clip_image005_2.gif"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="82" alt="clip_image005" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ChainOfResponsibilityDesignPatternFocusO_DFF4/clip_image005_thumb.gif" width="233" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;.Net framework implements Chain Of Responsibility design pattern for many its internal mechanisms. My favorite is HttpModule. I like it so much I decided to build my own pipeline.&lt;/p&gt;  &lt;p&gt;This post summarizes my steps I took to create my own simple implementation for this design pattern. I did not do any research purposely online and wanted to get my hands dirty without bias.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;The goal&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;My goal was creating simple code that can be adopted and extended:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The code should be very simple &lt;/li&gt;    &lt;li&gt;The code should provide pipeline infrastructure to invoke aspects/filters &lt;/li&gt;    &lt;li&gt;The code should allow dynamic invocation of any arbitrary number of aspects &lt;/li&gt;    &lt;li&gt;The code should include no optimization to stay simple &lt;/li&gt;    &lt;li&gt;The code should demonstrate practical idea and not be state of the art, production ready to go one. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;What I needed&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Provide generic mechanism that will execute arbitrary logic &amp;#8211; the Pipeline. &lt;/li&gt;    &lt;li&gt;The logic is encapsulated in decoupled components &amp;#8211; Aspects. &lt;/li&gt;    &lt;li&gt;Aspects can be independently configured without rebuilding the application. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;The design&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ChainOfResponsibilityDesignPatternFocusO_DFF4/clip_image006_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="227" alt="clip_image006" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ChainOfResponsibilityDesignPatternFocusO_DFF4/clip_image006_thumb.png" width="423" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Summary of steps&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Step #1 &amp;#8211; Create base classes and interfaces.&lt;/b&gt; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Step #2 &amp;#8211; Create concrete implementation of specific Pipeline.&lt;/b&gt; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Step #3 &amp;#8211; Modify config file.&lt;/b&gt; &lt;/li&gt;    &lt;li&gt;&lt;b&gt;Step #4 &amp;#8211; Test the solution.&lt;/b&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Following section describes each step in details&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;Step #1 &amp;#8211; Create base classes and interfaces.&lt;/b&gt; I needed two bases classes - BasePipeline and IAspect. BasePipeline is responsible to perform generic actions of:       &lt;ul&gt;       &lt;li&gt;Consulting configuration file. &lt;/li&gt;        &lt;li&gt;Loading the configured aspects. &lt;/li&gt;        &lt;li&gt;And invoking them one by one. &lt;/li&gt;     &lt;/ul&gt;      &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;LoadPipelineAspects()
{
    aspects = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;IAspect&lt;/span&gt;&amp;gt;();

    &lt;span style="color: #2b91af"&gt;Configuration &lt;/span&gt;config = &lt;/pre&gt;

    &lt;pre class="code"&gt;                  &lt;span style="color: #2b91af"&gt;ConfigurationManager&lt;/span&gt;.OpenExeConfiguration(&lt;/pre&gt;

    &lt;pre class="code"&gt;                  &lt;span style="color: #2b91af"&gt;ConfigurationUserLevel&lt;/span&gt;.None);

    &lt;span style="color: blue"&gt;string  &lt;/span&gt;piplineConfig = &lt;/pre&gt;

    &lt;pre class="code"&gt;            config.AppSettings.Settings[pipelineName].Value;

    &lt;span style="color: blue"&gt;string&lt;/span&gt;[] aspectNames = piplineConfig.Split(&lt;span style="color: #a31515"&gt;','&lt;/span&gt;);

    &lt;span style="color: blue"&gt;for &lt;/span&gt;(&lt;span style="color: blue"&gt;int &lt;/span&gt;i = 0; i &amp;lt; aspectNames.Length; i++)
    {

        &lt;span style="color: #2b91af"&gt;Type &lt;/span&gt;t = &lt;span style="color: #2b91af"&gt;Type&lt;/span&gt;.GetType(aspectNames[i]);

        &lt;span style="color: #2b91af"&gt;IAspect &lt;/span&gt;aspect=(&lt;span style="color: #2b91af"&gt;IAspect&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;Activator&lt;/span&gt;.CreateInstance(t);

        aspects.Add(aspect);

    }
}&lt;/pre&gt;
IAspect interface serves as a contract between BasePipline and aspect's concrete implementation. Take a look at the design diagram. When the client invokes HandleRequest method on concrete Pipeline implementation it invokes underneath generic implementation of the method of its base - BasePipeline: 

    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public virtual bool &lt;/span&gt;HandleRequest(&lt;span style="color: blue"&gt;object &lt;/span&gt;request) 
{

    &lt;span style="color: blue"&gt;foreach &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IAspect &lt;/span&gt;item &lt;span style="color: blue"&gt;in &lt;/span&gt;aspects)
    {
        item.ProcessRequest(request);
    }
    &lt;span style="color: blue"&gt;return true&lt;/span&gt;;
}&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Step #2 &amp;#8211; Create concrete implementations.&lt;/b&gt; Concrete implementations of both types SimplePipeline and SimpleAspect are nothing fancy. SimplePipeline calls into its base but reserves the right to add any additions without interfering with any other concrete implementations: 

    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public override bool &lt;/span&gt;HandleRequest(&lt;span style="color: blue"&gt;object &lt;/span&gt;request)
{
    &lt;span style="color: blue"&gt;base&lt;/span&gt;.HandleRequest(request);

    &lt;span style="color: blue"&gt;return true&lt;/span&gt;;
} &lt;/pre&gt;
To indicate what aspect is running I simply spit out aspect's name for aspect's ProcessRequest. That is the place where the whole logic should be performed - DB access, Web Services calls, request modifications etc : 

    &lt;br /&gt;

    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public bool &lt;/span&gt;ProcessRequest(&lt;span style="color: blue"&gt;object &lt;/span&gt;request)
{
    &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color: #a31515"&gt;&amp;quot;processing from SimpleAspect1&amp;quot;&lt;/span&gt;);
    &lt;span style="color: blue"&gt;return true&lt;/span&gt;;
}&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Step #3 &amp;#8211; Modify config file.&lt;/b&gt; Config file - app.config or web.config in my case - holds the information about what aspects should be called for specific pipeline: 

    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;appSettings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;key &lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;br /&gt;&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MyPipeline.SimplePipeline&lt;/span&gt;&amp;quot; 
 &lt;span style="color: red"&gt;value &lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MyPipeline.SimpleAspect1,MyPipeline.SimpleAspect2&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;appSettings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

    &lt;p&gt;The &lt;span style="color: red"&gt;key &lt;/span&gt;is the type of the pipeline and the &lt;span style="color: red"&gt;value &lt;/span&gt;is comma separated types of the aspects. When the concrete pipeline is instantiated by the client it already knows it type which serves to consult the config file and identify what aspects to load using reflection. This is how BasePipeline constructor looks like:&lt;/p&gt;

    &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;BasePipeline()
{
    pipelineName = &lt;span style="color: blue"&gt;this&lt;/span&gt;.ToString();
    
    LoadPipelineAspects();

}&lt;/pre&gt;
    &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

    &lt;p&gt;See &lt;strong&gt;Step #1&lt;/strong&gt; for LoadPipelineAspects() function implementation where reflection magic happens to dynamically load the aspects.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;b&gt;Step #4 &amp;#8211; Test the solution.&lt;/b&gt; To test the solution follow these steps: 

    &lt;ul&gt;
      &lt;li&gt;Create Class library project and reference to the library where Pipeline base classes reside. Implement your own Pipeline while inheriting from BasePipeline. &lt;/li&gt;

      &lt;li&gt;Implement few aspects that implement IAspect interface. &lt;/li&gt;

      &lt;li&gt;Create simple Windows Console application, add reference to the libraries and add simple code similar to this to Main function: 
        &lt;pre class="code"&gt;MyPipeline.&lt;span style="color: #2b91af"&gt;SimplePipeline &lt;/span&gt;sp = &lt;br /&gt;&lt;span style="color: blue"&gt;                        new &lt;/span&gt;MyPipeline.&lt;span style="color: #2b91af"&gt;SimplePipeline&lt;/span&gt;();

sp.HandleRequest(&lt;span style="color: blue"&gt;null&lt;/span&gt;);&lt;/pre&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;p&gt;In the config file add modifications as described in &lt;strong&gt;Step #3.&lt;/strong&gt;&lt;/p&gt;
      &lt;/li&gt;

      &lt;li&gt;
        &lt;p&gt;Run the application.&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Done. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ChainOfResponsibilityDesignPatternFocusO_DFF4/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="123" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ChainOfResponsibilityDesignPatternFocusO_DFF4/image_thumb.png" width="307" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Any time one needs to change the logic, add/remove aspects - it is just a matter of tweaking config file - that is it. &lt;/p&gt;

&lt;p&gt;I've just copied and pasted existing aspects inside the configuration file and run the application again, here is what I get:&lt;/p&gt;

&lt;p&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;key &lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MyPipeline.SimplePipeline&lt;/span&gt;&amp;quot; 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color: red"&gt;value &lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MyPipeline.SimpleAspect1, 
    &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;#160; MyPipeline.SimpleAspect2, 

    &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;#160; MyPipeline.SimpleAspect1, 

    &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;#160; MyPipeline.SimpleAspect2, 

    &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;#160; MyPipeline.SimpleAspect1, 

    &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;#160; MyPipeline.SimpleAspect2&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt; 
    &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ChainOfResponsibilityDesignPatternFocusO_DFF4/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="126" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/ChainOfResponsibilityDesignPatternFocusO_DFF4/image_thumb_1.png" width="272" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I think it is cool.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Focus on Security&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;From security perspective there are few things to keep in mind. When invoking assemblies with reflection there is immediate risk of luring attacks that result in spoofed assemblies. For more information how to get protected see my related post below - &lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/12/net-assembly-spoof-attack.aspx"&gt;.Net Assembly Spoof Attack&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Focus on Performance&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Reflection is considered as slow operation. Everything is relative. In case where reflection is used in performance critical application you should consider performance optimization for reflection. One such optimization is constructor caching as described in &lt;a href="http://weblogs.asp.net/bradygaster/archive/2003/11/26/39952.aspx" target="_blank"&gt;More Provider Goodieness&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Focus on Operations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;From operations perspective it seems ideal case. I witnessed few times the situation where the change was not an option since it required whole rebuild of the application - something that operations team was not happy with and put veto on it.&lt;/p&gt;

&lt;p&gt;The trick is constantly asking yourself &amp;quot;What I am optimizing? Security, Performance, or Operations?&amp;quot;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My related posts&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/12/net-assembly-spoof-attack.aspx"&gt;.Net Assembly Spoof Attack&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/12/26/basic-httpmodule-sample-plus-bonus-case-study-how-httomodule-saved-mission-critical-project-s-life.aspx"&gt;Basic HttpModule Sample (Plus Bonus Case Study - How HttpModule Saved Mission Critical Project's Life)&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/04/how-to-hack-wcf-new-technology-old-hacking-tricks.aspx"&gt;How To Hack WCF - New Technology, Old Hacking Tricks&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/05/18/aop-pipelines-interceptors-and-httpmodlues.aspx"&gt;AOP, Pipelines, Interceptors, and HttpModlues&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/10/06/iis-7-great-finds-how-to-setup-iis7-on-vista-bulk-web-site-creation-asp-net-pipeline-integration-with-iis7.aspx"&gt;IIS 7 Great Finds - How To Setup IIS7 On Vista, Bulk Web Site Creation, ASP.NET Pipeline Integration With IIS7&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="http://cid-dd25b83e4ca261f7.skydrive.live.com/self.aspx/Visual%20Studio%20Projects/Alikl.BasicSamples.zip" target="_blank"&gt;Download the sample from my SkyDrive&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/Alikl.BasicSamples.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/p&gt;

&lt;p&gt;Have fun.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7108994" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Security/default.aspx">Security</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Planning+Phase/default.aspx">Planning Phase</category></item><item><title>How To Keep ASP.NET ViewState On The Server – Revised</title><link>http://blogs.msdn.com/alikl/archive/2008/01/08/how-to-keep-asp-net-viewstate-on-the-server-revised.aspx</link><pubDate>Tue, 08 Jan 2008 23:13:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7032152</guid><dc:creator>alikl</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/alikl/comments/7032152.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=7032152</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=7032152</wfw:comment><description>&lt;p&gt;This is a follow up post to &lt;a href="http://blogs.msdn.com/alikl/archive/2008/01/02/basic-sample-how-to-keep-asp-net-viewstate-on-the-server.aspx"&gt;Basic Sample - How To Keep ASP.NET ViewState On The Server&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;ASP.NET 2.0 offers much easier built-in mechanism to save ViewState on the server in Session using &lt;b&gt;SessionPageStatePersister&lt;/b&gt;. Thanks to Russ who pointed me to this feature available in ASP.NET 2.0 via comments in the &lt;a href="http://blogs.msdn.com/alikl/archive/2008/01/02/basic-sample-how-to-keep-asp-net-viewstate-on-the-server.aspx"&gt;previous post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The details can be found here &lt;a href="http://msdn2.microsoft.com/en-us/library/aa479403.aspx" target="_blank"&gt;ASP.NET 2.0 Page State Persister&lt;/a&gt; [thanks go to Eddie from our own &lt;a href="http://blogs.msdn.com/ace_team/" target="_blank"&gt;ACE team&lt;/a&gt; for the pointer].&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Short analysis.&lt;/b&gt; Using &lt;i&gt;SessionPageStatePersister&lt;/i&gt; to store VIewState is very convenient as there is no code needed, almost. The down side is that this approach allows storing ViewState only in Session while the approach described in previous post allows routing ViewState to any storage of your choice &amp;#8211; Session, Cache, DB, Web Services &amp;#8211; up to your imagination. This can be important when considering scalability aspects of the solution that kazlak pointed out in the comments for the previous post.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;To commentators. &lt;i&gt;Big-thank-you&lt;/i&gt;&lt;/b&gt; for leaving your insightful comments. Sharing your insights helps me to improve and I am sure it also enriches this blog readers experience &amp;#8211; THANKS! Please comment more and leave your web sites/blogs so I can link back to you and give you full credit to your insights.&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7032152" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Development+Phase/default.aspx">Development Phase</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category></item><item><title>Basic Sample - How To Keep ASP.NET ViewState On The Server</title><link>http://blogs.msdn.com/alikl/archive/2008/01/02/basic-sample-how-to-keep-asp-net-viewstate-on-the-server.aspx</link><pubDate>Wed, 02 Jan 2008 13:38:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6952077</guid><dc:creator>alikl</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/alikl/comments/6952077.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alikl/commentrss.aspx?PostID=6952077</wfw:commentRss><wfw:comment>http://blogs.msdn.com/alikl/rsscomments.aspx?PostID=6952077</wfw:comment><description>&lt;p&gt;During recent few engagements with my customers I've noticed&amp;#160; VIewState is extensively [unintentionally] used. ViewState is on by default. The result is heavy weight Html that round trips on the network. This causes slow response time and high network utilization that affects another applications using the same network.&lt;/p&gt;  &lt;p&gt;How to remove ViewState from the network completely while taking an advantage if its functionality at same time?&lt;/p&gt;  &lt;p&gt;This post walks through basic steps of creating ASP.NET Base Page that implements functionality allowing saving ViewState on the server. The approach reduces dramatically network utilization. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Summary of steps&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Step 1 - Create Visual Studio Solution.&lt;/strong&gt;&amp;#160; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Step 2 - Implement Base Page&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Step 3 - Inherit Each ASPX page from Custom Base Page&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Step 4 - Test The Solution&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following section describes each step in details.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;li&gt;&lt;strong&gt;Step 1 - Create Visual Studio Solution.&lt;/strong&gt;&amp;#160; Open Visual Studio 2008 and create empty solution, found under &amp;quot;Visual Studio Solutions&amp;quot;. Name it BasePageSample. In Solution explorer right click the solution and add new project. Choose &amp;quot;ASP.NET Web Application&amp;quot; under Web node in &amp;quot;Add new Project&amp;quot; dialog. Name it SampleWebToUseExternalBasePage. Right click the solution in Solution Explorer and add new project. Choose &amp;quot;Class Library&amp;quot; under Windows node. Name it MyBasePage. In MyBasePage project add reference to System.Web assembly. Right click MyBasePage project and add new class, name it LeaveViewStateOnTheServer.cs.     &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;/li&gt;  &lt;li&gt;&lt;strong&gt;Step 2 - Implement Base Page.&lt;/strong&gt;&amp;#160; While in LeaveViewStateOnTheServer class add &lt;span style="color: blue"&gt;using &lt;/span&gt;declarations and inherit from Page type:     &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Collections.Generic;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Linq;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Text;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.IO;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Web.UI;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Web;&lt;/pre&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;namespace &lt;/span&gt;MyBasePage
{
    &lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;LeaveViewStateOnTheServer &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;Page
    &lt;/span&gt;{
    }
}&lt;/pre&gt;
Override two relevant methods that handle Loading and Saving of ViewState: 

  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;protected override object &lt;/span&gt;LoadPageStateFromPersistenceMedium()
{
    &lt;span style="color: blue"&gt;object &lt;/span&gt;viewStateBag;
    &lt;span style="color: blue"&gt;string &lt;/span&gt;m_viewState = (&lt;span style="color: blue"&gt;string&lt;/span&gt;)Session[&lt;span style="color: #a31515"&gt;&amp;quot;ViewState&amp;quot;&lt;/span&gt;];
    &lt;span style="color: #2b91af"&gt;LosFormatter &lt;/span&gt;m_formatter = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;LosFormatter&lt;/span&gt;();
    &lt;span style="color: blue"&gt;try
    &lt;/span&gt;{
        viewStateBag = m_formatter.Deserialize(m_viewState);
    }
    &lt;span style="color: blue"&gt;catch
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;throw new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpException&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;The View State is invalid.&amp;quot;&lt;/span&gt;);
    }
    &lt;span style="color: blue"&gt;return &lt;/span&gt;viewStateBag;
}
&lt;span style="color: blue"&gt;protected override void &lt;/span&gt;SavePageStateToPersistenceMedium(&lt;span style="color: blue"&gt;object &lt;/span&gt;viewState)
{
    &lt;span style="color: #2b91af"&gt;MemoryStream &lt;/span&gt;ms = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MemoryStream&lt;/span&gt;();
    &lt;span style="color: #2b91af"&gt;LosFormatter &lt;/span&gt;m_formatter = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;LosFormatter&lt;/span&gt;();
    m_formatter.Serialize(ms, viewState);
    ms.Position = 0;
    &lt;span style="color: #2b91af"&gt;StreamReader &lt;/span&gt;sr = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StreamReader&lt;/span&gt;(ms);
    &lt;span style="color: blue"&gt;string &lt;/span&gt;viewStateString = sr.ReadToEnd();
    Session[&lt;span style="color: #a31515"&gt;&amp;quot;ViewState&amp;quot;&lt;/span&gt;] = viewStateString;
    ms.Close();
    &lt;span style="color: blue"&gt;return&lt;/span&gt;;
}&lt;/pre&gt;
This is a basic code that can be adopted and adapted to specific needs. The code mostly based on &lt;a href="http://msdn.microsoft.com/msdnmag/issues/03/02/CuttingEdge/#S6 " target="_blank"&gt;Dino Esposito's code&lt;/a&gt;. 

  &lt;br /&gt;

  &lt;br /&gt;&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Step 3 - Inherit Each ASPX page from Custom Base Page.&lt;/strong&gt; Right click SampleWebToUseExternalBasePage project and reference to MyBasePage project. Right click SampleWebToUseExternalBasePage project and add new ASPX page, name it default.aspx. Open default.aspx.cs code behind and inherit the page from custom Base Page: 

  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;MyBasePage;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;SampleWebToUseExternalBasePage
{
    &lt;span style="color: blue"&gt;public partial class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;_Default &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;LeaveViewStateOnTheServer&lt;/span&gt;&lt;/pre&gt;

  &lt;br /&gt;&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Step 4 - Test The Solution.&lt;/strong&gt; Add any control to the page from the toolbox. GridView uses ViewState the most. Here is how rendered Html For GridView looks &lt;strong&gt;with&lt;/strong&gt; default ViewState behavior: 

  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/AlterD.NETPageProcessingLeaveViewStateOn_13900/image_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="264" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/AlterD.NETPageProcessingLeaveViewStateOn_13900/image_thumb.png" width="274" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

  &lt;p&gt;And here is how it looks without:&lt;/p&gt;

  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/AlterD.NETPageProcessingLeaveViewStateOn_13900/image_4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="279" alt="image" src="http://blogs.msdn.com/blogfiles/alikl/WindowsLiveWriter/AlterD.NETPageProcessingLeaveViewStateOn_13900/image_thumb_1.png" width="277" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

  &lt;p&gt;&amp;#160;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;My Related Posts&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/03/28/performance-testing-for-the-masses.aspx"&gt;Performance Testing For The Masses&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/08/16/improve-asp-net-performance-by-disabling-viewstate-and-setting-session-as-readonly.aspx"&gt;Improve ASP.NET Performance By Disabling ViewState And Setting Session As ReadOnly&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a href="http://blogs.msdn.com/alikl/archive/2007/11/02/identify-asp-net-web-services-and-wcf-performance-issues-by-examining-iis-logs.aspx"&gt;Identify ASP.NET, Web Services, And WCF Performance Issues By Examining IIS Logs&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;strong&gt;Related Resources&lt;/strong&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;a title="http://msdn.microsoft.com/msdnmag/issues/03/02/CuttingEdge/#S6" href="http://msdn.microsoft.com/msdnmag/issues/03/02/CuttingEdge/#S6" target="_blank"&gt;Keeping View State on the Server&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/950xf363.aspx" href="http://msdn2.microsoft.com/en-us/library/950xf363.aspx" target="_blank"&gt;pages Element (ASP.NET Settings Schema)&lt;/a&gt; &lt;/li&gt;

    &lt;li&gt;&lt;a title="http://msdn2.microsoft.com/en-us/library/ms972976.aspx" href="http://msdn2.microsoft.com/en-us/library/ms972976.aspx" target="_blank"&gt;Understanding ASP.NET View State&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;Download Sample Visual Studio 2008 solution from my SkyDrive:&lt;/p&gt;

  &lt;p&gt;&lt;/p&gt;
  &lt;iframe style="border-right: #dde5e9 1px solid; padding-right: 0px; border-top: #dde5e9 1px solid; padding-left: 0px; padding-bottom: 0px; margin: 3px; border-left: #dde5e9 1px solid; width: 240px; padding-top: 0px; border-bottom: #dde5e9 1px solid; height: 66px; background-color: #ffffff" marginwidth="0" marginheight="0" src="http://cid-dd25b83e4ca261f7.skydrive.live.com/embedrowdetail.aspx/Visual%20Studio%20Projects/BasePageSample.zip" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;&lt;/li&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6952077" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alikl/archive/tags/Implementation/default.aspx">Implementation</category><category domain="http://blogs.msdn.com/alikl/archive/tags/Performance/default.aspx">Performance</category></item></channel></rss>