<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Serializing and Deserializing Thoughts...</title>
	<atom:link href="http://dineshmandal.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dineshmandal.wordpress.com</link>
	<description>Learning and just sharing...</description>
	<lastBuildDate>Wed, 04 Jan 2012 08:00:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dineshmandal.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Serializing and Deserializing Thoughts...</title>
		<link>http://dineshmandal.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dineshmandal.wordpress.com/osd.xml" title="Serializing and Deserializing Thoughts..." />
	<atom:link rel='hub' href='http://dineshmandal.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Using MemoryCache in .Net 4.0</title>
		<link>http://dineshmandal.wordpress.com/2011/11/27/using-memorycache-in-net-4-0/</link>
		<comments>http://dineshmandal.wordpress.com/2011/11/27/using-memorycache-in-net-4-0/#comments</comments>
		<pubDate>Sun, 27 Nov 2011 09:59:32 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[MemoryCache]]></category>
		<category><![CDATA[ObjectCache]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/?p=445</guid>
		<description><![CDATA[Since ASP.Net first came, it came up with a very powerful feature of in-memory object cache (System.Web.Caching.Cache) to store commonly used expensive data on server side. Almost every ASP.Net application/site uses this feature now. But it suffered from few shortcomings like- It is available in ASP.Net only leaving WinForms or WPF clients puzzled. It is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=445&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Since ASP.Net first came, it came up with a very powerful feature of in-memory object cache (System.Web.Caching.Cache) to store commonly used expensive data on server side. Almost every ASP.Net application/site uses this feature now. But it suffered from few shortcomings like-</p>
<ul>
<li>It is available in ASP.Net only leaving WinForms or WPF clients puzzled. </li>
<li>It is not extensible to accommodate other demands to store cache objects in disk or Sql Server. However, MS after realizing these shortcomings, <a href="http://msdn.microsoft.com/en-us/library/ff664753(v=pandp.50).aspx" target="_blank">Caching Application Block</a> library was included in its <a href="http://msdn.microsoft.com/en-us/library/ff632023.aspx?rssCatalog" target="_blank">Enterprise Library</a>. </li>
<li>.Net developers have to look for their own mechanisms to create logical in-memory partitions called regions to group or organize cache objects in memory. </li>
</ul>
<p align="justify">However, .Net 4.0 came up with a new set of caching APIs in <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.aspx" target="_blank">System.Runtime.Caching</a> namespace that addresses all the above shortcomings. This new namespace can be found in System.Runtime.Caching.dll assembly. But this assembly reference is available only target framework of <a href="http://msdn.microsoft.com/en-us/library/w0x726c2.aspx" target="_blank">.Net Framework 4</a>, not <a href="http://msdn.microsoft.com/en-us/library/cc656912.aspx" target="_blank">.Net Framework 4 Client Profile</a>.</p>
<p>The System.Runtime.Caching namespace contains two core set of classes:</p>
<ul>
<li>
<div align="justify">Concrete implementation of <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache.aspx" target="_blank">System.Runtime.Caching.MemoryCache</a> class to support in-memory object cache. MemoryCache is closely modeled after old System.Web.Caching.Cache of ASP.Net. However, one does not have to rely upon System.Web assembly to use MemoryCache (We will see it through an example shortly).</div>
</li>
<li>Abstract types to build custom cache implementation other than in-built MemoryCache. </li>
</ul>
<p align="justify">Now let’s move to try out an example to leverage MemoryCache features. First of all we will create a class library type project. Add a class MyCache and assembly reference of System.Runtime.caching.dll.</p>
<p><strong>MyCache Code sample</strong>:</p>
<blockquote><p>using System;      <br />using System.Collections.Generic;       <br />using System.Linq;       <br />using System.Text;       <br />using System.Runtime.Caching;</p>
<p>namespace DotNetCachingWrapper      <br />{       <br />public enum MyCachePriority       <br />{       <br />Default,       <br />NotRemovable       <br />}</p>
<p>public class MyCache      <br />{       <br />// Gets a reference to the default MemoryCache instance.       <br />private static ObjectCache cache = MemoryCache.Default;       <br />private CacheItemPolicy policy = null;       <br />private CacheEntryRemovedCallback callback = null;</p>
<p>public void AddToMyCache(String CacheKeyName, Object CacheItem, MyCachePriority MyCacheItemPriority, List&lt;String&gt; FilePath)      <br />{       <br />//       <br />callback = new CacheEntryRemovedCallback(this.MyCachedItemRemovedCallback);       <br />policy = new CacheItemPolicy();       <br />policy.Priority = (MyCacheItemPriority == MyCachePriority.Default) ? CacheItemPriority.Default : CacheItemPriority.NotRemovable;       <br />policy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(10.00);       <br />policy.RemovedCallback = callback;       <br />policy.ChangeMonitors.Add(new HostFileChangeMonitor(FilePath));</p>
<p>// Add inside cache      <br />cache.Set(CacheKeyName, CacheItem, policy);       <br />}</p>
<p>public Object GetMyCachedItem(String CacheKeyName)      <br />{       <br />//       <br />return cache[CacheKeyName] as Object;       <br />}</p>
<p>public void RemoveMyCachedItem(String CacheKeyName)      <br />{       <br />//       <br />if (cache.Contains(CacheKeyName))       <br />{       <br />cache.Remove(CacheKeyName);       <br />}       <br />}</p>
<p>private void MyCachedItemRemovedCallback(CacheEntryRemovedArguments arguments)      <br />{       <br />// Log these values from arguments list       <br />String strLog = String.Concat(&quot;Reason: &quot;, arguments.RemovedReason.ToString(), &quot;       <br />| Key-Name: &quot;, arguments.CacheItem.Key, &quot; | Value-Object: &quot;,       <br />arguments.CacheItem.Value.ToString());       <br />}</p>
<p>}      <br />}</p>
</blockquote>
<p>Build this class library to generate assembly name of MyCachingWrapper.dll. Now we are ready to use this library in all ASP.Net web, WinForms and WPF applications.</p>
<p>Now let’s see examples of how this library can be commonly used in both ASP.Net Web Form and WinForm after adding reference of MyCachingWrapper.dll.</p>
<p><strong>ASP.Net Page_Load</strong>:</p>
<blockquote><p>protected void Page_Load(object sender, EventArgs e)      <br />{       <br />//       <br />MyCache objCache = new MyCache();       <br />String strUserName = objCache.GetMyCachedItem(&quot;USER_NAME&quot;) as String;       <br />if (String.IsNullOrEmpty(strUserName))       <br />{       <br />List&lt;String&gt; lstFiles = new List&lt;string&gt;();       <br />lstFiles.Add(HttpContext.Current.Request.MapPath(&quot;~/XmlFiles/ListOfUsers.xml&quot;));</p>
<p>XElement x = XElement.Load(HttpContext.Current.Request.MapPath(&quot;~/XmlFiles/ListOfUsers.xml&quot;));      <br />var qry = from u in x.Elements(&quot;Users&quot;) where u.Element(&quot;UserCode&quot;).Value == &quot;101&quot; select u;       <br />strUserName = qry.First().Element(&quot;UserName&quot;).Value;</p>
<p>// Add inside cache      <br />objCache.AddToMyCache(&quot;USER_NAME&quot;, strUserName, MyCachePriority.Default, lstFiles);       <br />}       <br />this.lblUserName.Text = strUserName;       <br />}</p>
</blockquote>
<p><strong>WinForm Form_Load</strong>:</p>
<blockquote><p>private void frmDefault_Load(object sender, EventArgs e)      <br />{       <br />//       <br />MyCache objCache = new MyCache();       <br />String strFilePath =System.IO.Path.Combine(Environment.CurrentDirectory, &quot;../../XmlFiles/ListOfUsers.xml&quot;);       <br />String strUserName = objCache.GetMyCachedItem(&quot;USER_NAME&quot;) as String;       <br />if (String.IsNullOrEmpty(strUserName))       <br />{       <br />List&lt;String&gt; lstFiles = new List&lt;string&gt;();       <br />lstFiles.Add(strFilePath);</p>
<p>XElement x = XElement.Load(strFilePath);      <br />var qry = from u in x.Elements(&quot;Users&quot;) where u.Element(&quot;UserCode&quot;).Value == &quot;101&quot; select u;       <br />strUserName = qry.First().Element(&quot;UserName&quot;).Value;</p>
<p>// Add inside cache      <br />objCache.AddToMyCache(&quot;USER_NAME&quot;, strUserName, MyCachePriority.Default, lstFiles);       <br />}       <br />this.lblUserName.Text = strUserName;       <br />}</p>
</blockquote>
<p><strong>Sample ListOfUsers.xml File</strong>:</p>
<blockquote><p>&lt;?xml version=&quot;1.0&quot;?&gt;      <br />&lt;ListOfUsers xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;       <br />&lt;Users&gt;       <br />&lt;UserCode&gt;101&lt;/UserCode&gt;       <br />&lt;UserName&gt;Dan Brown&lt;/UserName&gt;       <br />&lt;/Users&gt;       <br />&lt;Users&gt;       <br />&lt;UserCode&gt;102&lt;/UserCode&gt;       <br />&lt;UserName&gt;da Vinci&lt;/UserName&gt;       <br />&lt;/Users&gt;       <br />&lt;Users&gt;       <br />&lt;UserCode&gt;103&lt;/UserCode&gt;       <br />&lt;UserName&gt;Monalisa&lt;/UserName&gt;       <br />&lt;/Users&gt;       <br />&lt;Users&gt;       <br />&lt;UserCode&gt;104&lt;/UserCode&gt;       <br />&lt;UserName&gt;Shakespeare&lt;/UserName&gt;       <br />&lt;/Users&gt;       <br />&lt;Users&gt;       <br />&lt;UserCode&gt;105&lt;/UserCode&gt;       <br />&lt;UserName&gt;William Wordsworth&lt;/UserName&gt;       <br />&lt;/Users&gt;       <br />&lt;/ListOfUsers&gt;</p>
</blockquote>
<p align="justify">Now we can debug above code and see other interesting things. You will see the usage of MemoryCache methods and its techniques to cache objects are similar to what we have been doing in ASP.Net cache so far. Also, we see how the same <code>MyCache </code>library is usable in both web and windows applications.</p>
<p><strong>MemoryCache points worth mentioning</strong>:</p>
<ul>
<li>MemoryCache.Default returns the single and same instance of in-memory ObjectCache through a static read-only property.<br />
<blockquote>
<p>public static MemoryCache Default { get; }</p>
</blockquote>
</li>
<li>
<div align="justify"><a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.cacheentryremovedcallback(v=vs.110).aspx" target="_blank">CacheEntryRemovedCallback</a> signature is different than what we have seen in prior versions of ASP.Net. Refer to <a href="http://dineshmandal.wordpress.com/2009/09/20/cacheitemremovedcallback-example-asp-dot-net/">example</a>. In the current callback method, one can see the following details when cache item is expired after 10 seconds.</div>
</li>
</ul>
<p><a href="http://dineshmandal.files.wordpress.com/2011/11/callbackargumentsdetails.jpg" target="_blank"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="CallbackArgumentsDetails" border="0" alt="CallbackArgumentsDetails" src="http://dineshmandal.files.wordpress.com/2011/11/callbackargumentsdetails_thumb.jpg?w=598&#038;h=86" width="598" height="86" /></a></p>
<ul>
<li>
<div align="justify">CacheItemPriority enum in .Net 4.0 is cleaner than what we have seen in prior versions of <a href="http://msdn.microsoft.com/en-us/library/system.web.caching.cacheitempriority.aspx">ASP.Net</a>. Now, it is only Default and NotRemovable.</div>
</li>
<li>
<div align="justify">In prior version of ASP.Net, <a href="http://msdn.microsoft.com/en-us/library/system.web.caching.cachedependency.aspx" target="_blank">CacheDependency</a> was used to monitor changes in any underlying objects like files, Sql database tables, rows, columns, etc. Now .Net 4.0 provides <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.changemonitor.aspx" target="_blank">ChangeMonitor</a> class which is ASP.Net neutral and has wider scope of monitoring dependent objects to expire cache items. However, <a href="http://msdn.microsoft.com/en-us/library/system.web.caching.cachedependency.aspx" target="_blank">CacheDependency</a> is still there in ASP.Net 4.0. We should use other implementation of <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.changemonitor.aspx" target="_blank">ChangeMonitor</a> like <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.hostfilechangemonitor.aspx" target="_blank">HostFileChangeMontor</a> in the above example.</div>
</li>
<li>
<div align="justify">The default implementation of MemoryCache does not give us flexibility to add regions along with keys. In order to use regions, you should extend MemoryCache.</div>
</li>
</ul>
<p>Hope you all will appreciate .Net 4.0 caching feature.</p>
<p><a style="display:none;" href="http://dineshmandal.wordpress.com/2011/11/27/using-memorycache-in-net-4-0/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/asp-net/'>ASP.Net</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/cvb-net/'>C#/VB.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/memorycache/'>MemoryCache</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/objectcache/'>ObjectCache</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/net-4-0/'>.Net 4.0</a>, <a href='http://dineshmandal.wordpress.com/tag/asp-net/'>ASP.Net</a>, <a href='http://dineshmandal.wordpress.com/tag/c/'>C#</a>, <a href='http://dineshmandal.wordpress.com/tag/caching/'>Caching</a>, <a href='http://dineshmandal.wordpress.com/tag/memorycache/'>MemoryCache</a>, <a href='http://dineshmandal.wordpress.com/tag/objectcache/'>ObjectCache</a>, <a href='http://dineshmandal.wordpress.com/tag/visual-studio-2010/'>Visual Studio 2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/445/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/445/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/445/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=445&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2011/11/27/using-memorycache-in-net-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/11/callbackargumentsdetails_thumb.jpg" medium="image">
			<media:title type="html">CallbackArgumentsDetails</media:title>
		</media:content>
	</item>
		<item>
		<title>Testing and Monitoring WCF Service using soapUI and Fiddler</title>
		<link>http://dineshmandal.wordpress.com/2011/09/03/testing-and-monitoring-wcf-service-using-soapui-and-fiddler/</link>
		<comments>http://dineshmandal.wordpress.com/2011/09/03/testing-and-monitoring-wcf-service-using-soapui-and-fiddler/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 19:56:24 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[Dot Net Tools]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Fiddler]]></category>
		<category><![CDATA[soapUI]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/?p=403</guid>
		<description><![CDATA[This article is not about understanding the details of .Net WCF service, soapUI and Fiddler as all these three are quite popular things among .Net developers. And tools like soapUI and Fiddler may already be in the arsenal of many web developers and QA engineers. Those who are new to these two tools should refer [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=403&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">This article is not about understanding the details of .Net WCF service, soapUI and Fiddler as all these three are quite popular things among .Net developers. And tools like soapUI and Fiddler may already be in the arsenal of many web developers and QA engineers. Those who are new to these two tools should refer to following articles.</p>
<ul>
<li>soapUI- <a href="http://www.soatutorial.net/test-web-services-using-soapui/">SOA Tutorial</a> </li>
<li>Fiddler- <a href="http://dineshmandal.wordpress.com/2009/07/08/fiddler-and-asp-net/">Fiddler Tool and ASP.Net Applications</a> and <a href="http://www.mehdi-khalili.com/fiddler-in-action/part-1">Fiddler in Action – Part 1</a> </li>
</ul>
<p align="justify">However, we will take a look into how Fiddler can be used to Monitor SOAP Request and SOAP Response transmitting behind the soapUI.</p>
<p align="justify">Let’s start with a simple WCF service in place. No need to have a WCF .Net Client as of now to test and monitor HTTP traffic of WCF service calls.</p>
<p>1. Open soapUI and set the following settings. Make sure the service’s wsdl path is correct.</p>
<p><a href="http://dineshmandal.files.wordpress.com/2011/09/clip_image0021.jpg" target="_blank"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="Loading wsdl definition" border="0" alt="Loading wsdl definition" src="http://dineshmandal.files.wordpress.com/2011/09/clip_image002_thumb1.jpg?w=582&#038;h=469" width="582" height="469" /></a></p>
<p>2. After loading the definition of WSDL, service definitions will appear like shown below.</p>
<p><a href="http://dineshmandal.files.wordpress.com/2011/09/service_definitions.jpg" target="_blank"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="Service requests definitions" border="0" alt="Service requests definitions" src="http://dineshmandal.files.wordpress.com/2011/09/service_definitions_thumb.jpg?w=244&#038;h=319" width="244" height="319" /></a></p>
<p>3. Double click on Request # node and navigate to the request window on the right.</p>
<p><a href="http://dineshmandal.files.wordpress.com/2011/09/clip_image0061.jpg" target="_blank"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="Submitting the request" border="0" alt="Submitting the request" src="http://dineshmandal.files.wordpress.com/2011/09/clip_image006_thumb1.jpg?w=537&#038;h=312" width="537" height="312" /></a></p>
<p>4. Fill the method parameters denoted by “?”.</p>
<p>5. Open Fiddler and make sure it is ready to capture HTTP(S) traffic.</p>
<p>6. Submit request to the specified endpoint and SOAP Response can be seen on the right pane.</p>
<p><a href="http://dineshmandal.files.wordpress.com/2011/09/clip_image0081.jpg" target="_blank"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="Service Request-Response in soapUI" border="0" alt="Service Request-Response in soapUI" src="http://dineshmandal.files.wordpress.com/2011/09/clip_image008_thumb1.jpg?w=487&#038;h=246" width="487" height="246" /></a></p>
<p align="justify">7. If you see the Fiddler window, there is no traffic captured. This is really frustrating if you have been testing your services using soapUI when you do not see the underlying details of the SOAP Request and SOAP Response in the wire.</p>
<p>8. All you need to do following proxy settings in the soapUI File –&gt; Preferences –&gt; Proxy Settings window.</p>
<p><a href="http://dineshmandal.files.wordpress.com/2011/09/clip_image0101.jpg" target="_blank"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="soapUI Proxy Settings" border="0" alt="soapUI Proxy Settings" src="http://dineshmandal.files.wordpress.com/2011/09/clip_image010_thumb1.jpg?w=467&#038;h=277" width="467" height="277" /></a></p>
<p>9. Re-submit web service request on soapUI.</p>
<p>10. Now you see WCF Request-Response traffic in the Fiddler window <img style="border-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://dineshmandal.files.wordpress.com/2011/09/wlemoticon-smile.png?w=600" />. You are now all in your territory to view the details of service request-response headers, body, and many more!</p>
<p><a href="http://dineshmandal.files.wordpress.com/2011/09/clip_image0121.jpg" target="_blank"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="SOAP Request-Response view in Fiddler" border="0" alt="SOAP Request-Response view in Fiddler" src="http://dineshmandal.files.wordpress.com/2011/09/clip_image012_thumb1.jpg?w=585&#038;h=371" width="585" height="371" /></a></p>
<p>But why did we add Port No. 8888 in the proxy settings of soapUI? It is because Fiddler by default listens on port no. 8888.</p>
<p><a href="http://dineshmandal.files.wordpress.com/2011/09/clip_image0141.jpg" target="_blank"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="Fiddler default listening port no." border="0" alt="Fiddler default listening port no." src="http://dineshmandal.files.wordpress.com/2011/09/clip_image014_thumb1.jpg?w=491&#038;h=303" width="491" height="303" /></a></p>
<p>If you have configured your Fiddler proxy tool to listen on some other port no., then you should use that one.</p>
<p align="justify">I hope you enjoyed this testing tip. No need to reiterate how blissful it is to test web services using soapUI and Fiddler if you are a web service developer/provider to remote clients.<br />
<br /><a style="display:none;" href="http://dineshmandal.wordpress.com/2011/09/03/testing-and-monitoring-wcf-service-using-soapui-and-fiddler/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/asp-net/'>ASP.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tools/'>Dot Net Tools</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/wcf/'>WCF</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/debugging/'>Debugging</a>, <a href='http://dineshmandal.wordpress.com/tag/fiddler/'>Fiddler</a>, <a href='http://dineshmandal.wordpress.com/tag/soapui/'>soapUI</a>, <a href='http://dineshmandal.wordpress.com/tag/wcf/'>WCF</a>, <a href='http://dineshmandal.wordpress.com/tag/web-service/'>Web Service</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/403/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/403/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/403/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=403&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2011/09/03/testing-and-monitoring-wcf-service-using-soapui-and-fiddler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/09/clip_image002_thumb1.jpg" medium="image">
			<media:title type="html">Loading wsdl definition</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/09/service_definitions_thumb.jpg" medium="image">
			<media:title type="html">Service requests definitions</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/09/clip_image006_thumb1.jpg" medium="image">
			<media:title type="html">Submitting the request</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/09/clip_image008_thumb1.jpg" medium="image">
			<media:title type="html">Service Request-Response in soapUI</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/09/clip_image010_thumb1.jpg" medium="image">
			<media:title type="html">soapUI Proxy Settings</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/09/wlemoticon-smile.png" medium="image">
			<media:title type="html">Smile</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/09/clip_image012_thumb1.jpg" medium="image">
			<media:title type="html">SOAP Request-Response view in Fiddler</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2011/09/clip_image014_thumb1.jpg" medium="image">
			<media:title type="html">Fiddler default listening port no.</media:title>
		</media:content>
	</item>
		<item>
		<title>Strategy Design Pattern in .Net</title>
		<link>http://dineshmandal.wordpress.com/2010/09/26/strategy-design-pattern-in-dot-net/</link>
		<comments>http://dineshmandal.wordpress.com/2010/09/26/strategy-design-pattern-in-dot-net/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 13:53:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[Behavioral Design Pattern]]></category>
		<category><![CDATA[Strategy Design Pattern]]></category>

		<guid isPermaLink="false">https://dineshmandal.wordpress.com/2010/09/26/strategy-design-pattern-in-net/</guid>
		<description><![CDATA[Strategy design pattern falls under the category of Behavioral Design Pattern. In this pattern, we capture abstraction in an Interface or Abstract class called Strategy Base, and we bury implementation details of algorithms in concrete classes called Concrete Strategy. Client code can then call such different implementation methods based upon some strategy or condition during [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=310&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify"><a href="http://en.wikipedia.org/wiki/Strategy_pattern" target="_blank">Strategy design pattern</a> falls under the category of <a href="http://en.wikipedia.org/wiki/Behavioral_pattern" target="_blank">Behavioral Design Pattern</a>. In this pattern, we capture abstraction in an Interface or Abstract class called Strategy Base, and we bury implementation details of algorithms in concrete classes called Concrete Strategy. Client code can then call such different implementation methods based upon some strategy or condition during run time. Client is not tied statically or bound to call fixed methods, rather it can change its strategy dynamically. This is because client never calls any methods directly by instantiating concrete classes. Client sets its strategy via some other class called Context.</p>
<p>Let’s see one such example of this pattern.</p>
<p align="justify"><img style="display:inline;border-width:0;" title="StrategyDesignPattern" border="0" alt="StrategyDesignPattern" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image0024.jpg?w=488&#038;h=399" width="488" height="399" />    <br />Fig: Strategy Design Pattern showing all three main components- Strategy Base, Concrete Strategy and Context Classes.</p>
<p>Coming to code, we have:</p>
<pre>namespace BehavioralDesignPattern.StrategyDesignPattern
{
public abstract class StrategyBase
{
public abstract long Calculate(int x,int y);
}

public class ConcreteAddStrategy : StrategyBase
{
public override long Calculate(int x, int y)
{
return x + y;
}
}

public class ConcreteSubtractStrategy : StrategyBase
{
public override long Calculate(int x, int y)
{
return x - y;
}
}

public class Context
{
public StrategyBase Strategy { get; set; }
public long CallCalculateMethod(int x, int y)
{
return (Strategy.Calculate(x, y));
}
}
}</pre>
<p align="justify">We see each of the concrete strategy class implementing algorithm to calculate upon numbers in its own way- one doing addition, while other doing subtraction. But their over all capability to do arithmetic operations upon numbers is abstracted inside Calculate(int, int) method in StrategyBase class.</p>
<p align="justify">See the Context class above. It has a property Strategy to get-set of type StrategyBase type. Alternatively, Context class can get-set instance of StrategyBase by a constructor or some method as well like SetStrategy(StrategyBase objSB).</p>
<p align="justify">But why do we require this Context class? Because clients agree to call any ConcreteStrategy method not directly. Clients will only hint out for such concrete strategy. What does this mean? This means a lot- <strong>Strategy pattern lets you change the guts of an object</strong>.</p>
<p>See the client code below:</p>
<pre>private void CallStrategyAddMethod()
{
//
Context objCtxt = new Context();
objCtxt.Strategy = new ConcreteAddStrategy();
// Now the object's strategy is to call Add method.
objCtxt.CallCalculateMethod(10, 15);
}</pre>
<p align="justify">As seen from the above code, object “objCtxt” is able to call method in a concrete strategy class.</p>
<p align="justify">Whenever modeling a system after <a href="http://en.wikipedia.org/wiki/Strategy_pattern" target="_blank">Strategy Design Pattern</a>, one has to carefully think of a way to allow client to convey its strategy to context class.</p>
<p>That’s it.<br />
  <br /><a style="display:none;" href="http://dineshmandal.wordpress.com/2010/09/26/strategy-design-pattern-in-dot-net/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/architecture/'>Architecture</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/cvb-net/'>C#/VB.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/design-patterns/'>Design Patterns</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/net-4-0/'>.Net 4.0</a>, <a href='http://dineshmandal.wordpress.com/tag/net3-5/'>.Net3.5</a>, <a href='http://dineshmandal.wordpress.com/tag/behavioral-design-pattern/'>Behavioral Design Pattern</a>, <a href='http://dineshmandal.wordpress.com/tag/design-patterns/'>Design Patterns</a>, <a href='http://dineshmandal.wordpress.com/tag/strategy-design-pattern/'>Strategy Design Pattern</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/310/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=310&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2010/09/26/strategy-design-pattern-in-dot-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image0024.jpg" medium="image">
			<media:title type="html">StrategyDesignPattern</media:title>
		</media:content>
	</item>
		<item>
		<title>Template Method Design Pattern in .Net</title>
		<link>http://dineshmandal.wordpress.com/2010/09/26/template-method-design-pattern-in-dot-net/</link>
		<comments>http://dineshmandal.wordpress.com/2010/09/26/template-method-design-pattern-in-dot-net/#comments</comments>
		<pubDate>Sun, 26 Sep 2010 10:30:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[Behavioral Design Pattern]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Template Method Design Pattern]]></category>

		<guid isPermaLink="false">https://dineshmandal.wordpress.com/2010/09/26/template-method-design-pattern-in-net/</guid>
		<description><![CDATA[Template method design pattern falls under the category of Behavioral Design Pattern. In this pattern, a template method defines a skeleton of an algorithm in terms of abstract operations. The template method can contain one or more steps. But these steps will have to be in abstract form only. That said, we cannot change the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=303&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify"><a href="http://en.wikipedia.org/wiki/Template_method_pattern" target="_blank">Template method design pattern</a> falls under the category of <a href="http://en.wikipedia.org/wiki/Behavioral_pattern" target="_blank">Behavioral Design Pattern</a>. In this pattern, a template method defines a skeleton of an algorithm in terms of abstract operations. The template method can contain one or more steps. But these steps will have to be in abstract form only. That said, we cannot change the order of steps, and most importantly we cannot override the template method itself. Only the steps given in the skeleton of algorithm of template method need to be overridden in concrete classes.</p>
<p>Let’s see how classes can be designed in this template pattern.</p>
<p><img style="display:inline;border-width:0;" title="TemplateMethodPattern" border="0" alt="emplateMethodPattern" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image0025.jpg?w=471&#038;h=329" width="471" height="329" /></p>
<p>Fig: High Level Class Diagram of Template Method Design Pattern</p>
<p>And see the code implementation below:</p>
<pre>namespace BehavioralDesignPattern.TemplateMethod
{
public abstract class AbstractAlgorithmSkeleton
{
public void TemplateMethod()
{
// Template Method declaring algorithm
// in terms of abstract operations.
Step1();
Step2();
Step3();
}
public abstract void Step1();
public abstract void Step2();
public abstract void Step3();
}

# region &quot;Concrete Implementations of abstract operations defined in Template Method&quot;
public class ConcreteClassA : AbstractAlgorithmSkeleton
{
public override void Step1()
{
Console.WriteLine(&quot;ConcreteClassA, Step 1&quot;);
}

public override void Step2()
{
Console.WriteLine(&quot;ConcreteClassA, Step 2&quot;);
}

public override void Step3()
{
Console.WriteLine(&quot;ConcreteClassA, Step 3&quot;);
}

public void OtherMethodA()
{
//
}
}

public class ConcreteClassB : AbstractAlgorithmSkeleton
{
public override void Step1()
{
Console.WriteLine(&quot;ConcreteClassB, Step 1&quot;);
}

public override void Step2()
{
Console.WriteLine(&quot;ConcreteClassB, Step 2&quot;);
}

public override void Step3()
{
Console.WriteLine(&quot;ConcreteClassB, Step 3&quot;);
}

public void OtherMethodB()
{
//
}
}

# endregion &quot;Concrete Classes Implementation&quot;
}</pre>
<p align="justify">We see the concrete classes are overriding the abstract operations defined by the template method in its algorithm. This way template method pattern provides an abstract view of algorithm.</p>
<p align="justify">So in practical scenario, this pattern fits only when different types of object instances are required to invoke methods or operations that differ sharply in implementation but the algorithm remaining same. Also, sometimes when are refactoring multiple classes, we can find template method pattern coming into picture.</p>
<p><strong>Consuming the template method:</strong></p>
<pre>private void CallTemplateMethod()
{
AbstractAlgorithmSkeleton objTemplate = null;
objTemplate = new ConcreteClassA();
// Now this call to TemplateMethod() will direct calls
// to methods in ConcreteClassA.
objTemplate.TemplateMethod();
}</pre>
<p align="justify">Important point to note here is: the way we are calling TemplateMethod() of ConcreteClassA from base class AbstractAlgorithmSkeleton reminds us of “The <a href="http://en.wikipedia.org/wiki/Hollywood_Principle" target="_blank">Hollywood Principle</a>”- “Do not call us, we will call for you”. That is, child class method is being called from base class. This way of method call is also known as <a href="http://en.wikipedia.org/wiki/Inversion_of_control" target="_blank">Inversion of Control</a>.</p>
<p>That’s it.<a style="display:none;" href="http://dineshmandal.wordpress.com/2010/09/26/template-method-design-pattern-in-dot-net/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/architecture/'>Architecture</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/cvb-net/'>C#/VB.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/design-patterns/'>Design Patterns</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/net-4-0/'>.Net 4.0</a>, <a href='http://dineshmandal.wordpress.com/tag/net3-5/'>.Net3.5</a>, <a href='http://dineshmandal.wordpress.com/tag/architecture/'>Architecture</a>, <a href='http://dineshmandal.wordpress.com/tag/behavioral-design-pattern/'>Behavioral Design Pattern</a>, <a href='http://dineshmandal.wordpress.com/tag/c/'>C#</a>, <a href='http://dineshmandal.wordpress.com/tag/design-patterns/'>Design Patterns</a>, <a href='http://dineshmandal.wordpress.com/tag/template-method-design-pattern/'>Template Method Design Pattern</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/303/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/303/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/303/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=303&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2010/09/26/template-method-design-pattern-in-dot-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image0025.jpg" medium="image">
			<media:title type="html">TemplateMethodPattern</media:title>
		</media:content>
	</item>
		<item>
		<title>Decorator Design Pattern in .Net</title>
		<link>http://dineshmandal.wordpress.com/2010/09/19/decorator-design-pattern-in-dot-net/</link>
		<comments>http://dineshmandal.wordpress.com/2010/09/19/decorator-design-pattern-in-dot-net/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 16:01:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Decorator Design Pattern]]></category>
		<category><![CDATA[Structural Design Pattern]]></category>

		<guid isPermaLink="false">https://dineshmandal.wordpress.com/2010/09/19/decorator-design-pattern-in-net/</guid>
		<description><![CDATA[Decorator design pattern falls under the category of Structural Design Pattern. Structural design pattern emphasizes upon the overall structure of classes and objects in the system either by doing class inheritance or by composing objects into larger structures using object composition. Decorator pattern comes handy when we want to add additional responsibilities to the object [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=287&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify"><a href="http://www.oodesign.com/decorator-pattern.html" target="_blank">Decorator design pattern</a> falls under the category of <a href="http://www.go4expert.com/forums/showthread.php?t=5127#decorator" target="_blank">Structural Design Pattern</a>. Structural design pattern emphasizes upon the overall structure of classes and objects in the system either by doing class inheritance or by composing objects into larger structures using <a href="http://en.wikipedia.org/wiki/User_defined_type" target="_blank">object composition</a>. Decorator pattern comes handy when we want to add additional responsibilities to the object during run time.</p>
<ul>
<li>
<div align="justify">Additional responsibilities can be added statically by class inheritance also. But this will create another problem when we want to add such responsibilities to objects of many classes. We may have to create many child classes to support additional new functions.</div>
</li>
<li>
<div align="justify">So instead of creating many child classes of already existing concrete classes, we create a new Decorator, and a new Concrete Decorator class that will add new methods and properties to the existing class object during run time. This way we are not modifying the existing concrete or legacy classes. Responsibilities to objects can be added during runtime because base class of the object and Decorator class share the same base type. And Concrete Decorator class extends the new Decorator.</div>
</li>
</ul>
<p align="justify">This design pattern does not come initially during system design. It generally comes during maintenance phase or later in the development phase.</p>
<p align="justify">Now let’s see the example of decorator design pattern. We even use mobile phone to send text and multimedia messages. Once the message is sent, the Outbox becomes empty. But sometimes we want to save the sent content message. To do this, we need to select the option of “Send and Save”, and any message sent this way will be saved inside “Sent” folders. Here, even if the user may not always want to save the sent messages, it is for sure that he may definitely want to send messages. Keeping this use case in mind, let’s look into such a class design.</p>
<p><img style="display:inline;border-width:0;" title="BaseMessage" border="0" alt="BaseMessage" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image0021.jpg?w=275&#038;h=272" width="275" height="272" />    <br />Fig: Base class for SMS and MMS Concrete Classes</p>
<p><img style="display:inline;border-width:0;" title="Decorator" border="0" alt="Decorator" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image0041.jpg?w=469&#038;h=412" width="469" height="412" />    <br />Fig: Overall class structure after the introduction of Decorator</p>
<p align="justify">From the above diagram, we see two main concrete classes that are involved in sending messages- MobileMMS sends image as message content while MobileSMS send text. Both of the classes are doing well with SendMessage() method. SendMessage() is an abstract method in BaseMessage root class. Decorator, often called DecoratorBase, can be seen inheriting from the same base type of these two MobileMMS and MobileSMS classes, i.e.; inheriting from BaseMessage class. <strong>For a Decorator class this is important.</strong></p>
<p>Then, we see MessageProcessor class (often called ConcreteDecorator) which is a concrete implementation of Decorator.</p>
<p align="justify">Note: BaseMessage, MobileMMS and MobileSMS are the original classes. Only due to SendAndSave option, a new responsibility SaveMessage() is now required to be added into the objects of MobileMMS and MobileSMS. This is how we see DecoratorBase and ConcreteDecorator need to be added later on.</p>
<p>Now let’s see the actual implementation of the classes.</p>
<pre>namespace DecoratorPattern
{
abstract class BaseMessage
{
private string _sender;
private string _recipient;
public string MessageSender
{
get
{
return this._sender;
}
set
{
this._sender = value;
}
}
public string MessageRecipient {
get
{
return this._recipient;
}
set
{
this._recipient = value;
}
}
public abstract void SendMessage();
}
}</pre>
<pre>namespace DecoratorPattern
{
class MobileSMS: BaseMessage
{
private string _message;
public MobileSMS(string strSender, string strRecipient, string strMessage)
{
this.MessageSender = strSender;
this.MessageRecipient = strRecipient;
this.Message = strMessage;
}
public string Message
{
get
{
return this._message;
}
set
{
this._message = value;
}
}
public override void SendMessage()
{
//Send Text message
}
}
}</pre>
<pre>namespace DecoratorPattern
{
class MobileMMS:BaseMessage
{
private byte[] image;
public MobileMMS(string strSender, string strRecipient, byte[] image)
{
this.MessageSender = strSender;
this.MessageRecipient = strRecipient;
this.Image = image;
}
public byte[] Image
{
get
{
return this.image;
}
set
{
this.image = value;
}
}
public override void SendMessage()
{
//Send MMS message
}
}
}</pre>
<pre>namespace DecoratorPattern
{
<strong>class Decorator: BaseMessage
</strong>{
protected BaseMessage message;
public Decorator(BaseMessage message)
{
this.message = message;
}
public override void SendMessage()
{
message.SendMessage();
}
}
}</pre>
<pre>namespace DecoratorPattern
{
<strong>class MessageProcessor:Decorator
</strong>{
public MessageProcessor(BaseMessage message): base(message)
{
}
public void SaveMessage()
{
//Saves outgoing message
}
public override void SendMessage()
{
//
<strong>base.SendMessage();
SaveMessage();
</strong>}
}
}</pre>
<p align="justify">Now see the SendSMS and SendMMS methods: how the constructor methods of MessageProcessor are accepting object instances. This is called <a href="http://en.wikipedia.org/wiki/User_defined_type" target="_blank">object composition</a>, and <strong>important for Concrete Decorator.</strong> This way MessageProcessor will be able to direct the call to the actual method of the class. See the SendMessage() method code above in MessageProcessor.</p>
<p><strong><span style="text-decoration:underline;">Client Code</span></strong></p>
<pre>namespace DecoratorPattern
{
class Program
{
public enum SendMessageOption
{
SendOnly = 0,
SendAndSave = 1
}
private void SendSMS(SendMessageOption option)
{
//Send SMS
MobileSMS sms = new MobileSMS(&quot;123&quot;, &quot;456&quot;, &quot;This is example of decorator pattern.&quot;);
if (option == SendMessageOption.SendOnly)
{
sms.SendMessage();
}
else if (option == SendMessageOption.SendAndSave)
{
MessageProcessor msgProcessor = new MessageProcessor(<strong>sms</strong>);
msgProcessor.SendMessage();
}
}
private void SendMMS(SendMessageOption option)
{
//Send MMS
MobileMMS mms = new MobileMMS(&quot;123&quot;, &quot;456&quot;, new byte[] { 1, 2, 3, 4 });
if (option == SendMessageOption.SendOnly)
{
mms.SendMessage();
}
else if (option == SendMessageOption.SendAndSave)
{
MessageProcessor msgProcessor = new MessageProcessor(<strong>mms</strong>);
msgProcessor.SendMessage();
}
}

static void Main(string[] args)
{
//
Program obj = new Program();
obj.SendSMS(SendMessageOption.SendOnly);
obj.SendSMS(SendMessageOption.SendAndSave);
obj.SendMMS(SendMessageOption.SendOnly);
obj.SendMMS(SendMessageOption.SendAndSave);
//Wait for user enter key
Console.Read();
}
}
}</pre>
<p align="justify">Hope the <a href="http://www.oodesign.com/decorator-pattern.html" target="_blank">Decorator design pattern</a> is now simple enough to understand.<a style="display:none;" href="http://dineshmandal.wordpress.com/2010/09/19/decorator-design-pattern-in-dot-net/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/architecture/'>Architecture</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/cvb-net/'>C#/VB.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/design-patterns/'>Design Patterns</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/net-4-0/'>.Net 4.0</a>, <a href='http://dineshmandal.wordpress.com/tag/net3-5/'>.Net3.5</a>, <a href='http://dineshmandal.wordpress.com/tag/architecture/'>Architecture</a>, <a href='http://dineshmandal.wordpress.com/tag/c/'>C#</a>, <a href='http://dineshmandal.wordpress.com/tag/decorator-design-pattern/'>Decorator Design Pattern</a>, <a href='http://dineshmandal.wordpress.com/tag/design-patterns/'>Design Patterns</a>, <a href='http://dineshmandal.wordpress.com/tag/structural-design-pattern/'>Structural Design Pattern</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/287/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/287/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/287/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=287&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2010/09/19/decorator-design-pattern-in-dot-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image0021.jpg" medium="image">
			<media:title type="html">BaseMessage</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image0041.jpg" medium="image">
			<media:title type="html">Decorator</media:title>
		</media:content>
	</item>
		<item>
		<title>Embedding and Using Resources from .Net Assembly</title>
		<link>http://dineshmandal.wordpress.com/2010/07/10/embedding-and-using-resources-from-dot-net-assembly/</link>
		<comments>http://dineshmandal.wordpress.com/2010/07/10/embedding-and-using-resources-from-dot-net-assembly/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 16:29:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[.Net Assembly]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">https://dineshmandal.wordpress.com/2010/07/10/embedding-and-using-resources-from-net-assembly/</guid>
		<description><![CDATA[.Net Assemblies can contain various types of resources like images, icons, files, etc. Such resources are mostly static, i.e.; do not keep changing during run time or application wise. Also, such resources are not executable items. So while deploying such assemblies, we need to make sure those resources are intact with the packaged assemblies. Else, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=256&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">.Net Assemblies can contain various types of resources like images, icons, files, etc. Such resources are mostly static, i.e.; do not keep changing during run time or application wise. Also, such resources are not executable items. So while deploying such assemblies, we need to make sure those resources are intact with the packaged assemblies. Else, assemblies may blow up while executing the resource dependent methods. So as part of deployment strategy, we should embed such resources into the assembly itself.</p>
<p>Today we will see one such example of embedding Xml file into assembly.</p>
<ul>
<li>Add one Class Library type project into the solution. </li>
<li>Add one Xml file as well. Fill Xml file with few data that the class library may use to query. </li>
<li>Right click on the Xml file, and select <strong>Properties</strong> &#8211;&gt; <strong>Build</strong> <strong>Action</strong>. Out of several <strong>Build</strong> <strong>Action</strong> options, select <strong>Embedded</strong> <strong>Resource</strong>. </li>
</ul>
<p><img style="display:inline;border-width:0;" title="ResourceProperties" border="0" alt="ResourceProperties" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image0026.jpg?w=406&#038;h=355" width="406" height="355" /></p>
<ul>
<li>There you may see other properties as well like <strong>Copy to Output Directory</strong>. It has options like this: </li>
</ul>
<p><img style="display:inline;border-width:0;" title="ResourceSettings" border="0" alt="ResourceSettings" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image0042.jpg?w=412&#038;h=410" width="412" height="410" /></p>
<ul>
<li>If you select <strong>Do Not Copy</strong>, output of building the class library inside <strong>\bin\</strong> folder will not have separate *.dll than embedded Xml file. </li>
<li>If you select <strong>Copy Always</strong>, output of building the class library inside <strong>\bin\</strong> folder will always have *.dll and an embedded Xml file. </li>
</ul>
<p align="justify">However, I prefer the first option. By this we make sure our distributable assembly is only one *.dll. This way the embedded resource Xml file cannot be modified, and our assembly can safely execute methods that depend upon this Xml file. I like to suggest one more tips here- rename this Xml file extension to *.config. Renaming Xml file extension to *.config makes file not browse able by Browser in web applications.</p>
<p align="justify">Here I have shown steps of embedding resource file into .Net assembly. This assembly can be either Class Library or Web application. We cannot embed resource file into web site type project as Web site does not produce assembly like Web application.</p>
<p>Now, let’s see how we can access embedded Xml file from assembly during runtime.</p>
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Xml;
using System.IO;

namespace MathLibrary
{
public class MathLibrary
{
//
private const string strFileName = &quot;XMLFile.config&quot;;

public System.Xml.XmlDocument GetXMLDocument()
{
//
var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.<a href="http://msdn.microsoft.com/en-us/library/5kx66y1a.aspx">GetManifestResourceStream</a>this.GetType(), strFileName);
var doc = new XmlDocument();

try
{
if (stream == null)
{
throw new FileNotFoundException(&quot;Couldnot find embedded mappings resource file.&quot;, strFileName);
}
doc.Load(stream);
}
catch (Exception ex)
{ throw ex; }
return doc;
}

public System.IO.Stream GetXMLStream()
{
//
var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.<a href="http://msdn.microsoft.com/en-us/library/5kx66y1a.aspx" target="_blank">GetManifestResourceStream</a>(this.GetType(), strFileName);

try
{
if (stream == null)
{
throw new FileNotFoundException(&quot;Couldnot find embedded mappings resource file.&quot;, strFileName);
}
}
catch (Exception ex)
{ throw ex; }
return stream;
}
}
}</pre>
<p align="justify">There are two methods shown above- one returning <strong>XmlDocument</strong> object and other returning <strong>IO.Stream</strong>. Either of the return type can be used to construct <strong>XmlDocument</strong> object now at caller end of these methods.</p>
<p align="justify">Now let’s verify the assembly if it has any embedded resource or not. We can do this using either <a href="http://www.red-gate.com/products/reflector/" target="_blank">Reflector</a> or <a href="http://msdn.microsoft.com/en-us/library/aa309387(VS.71).aspx" target="_blank">Ildasm</a> tool.</p>
<p><strong><span style="text-decoration:underline;">Reflector View:</span></strong><strong></strong></p>
<p><img style="display:inline;border-width:0;" title="ReflectorView" border="0" alt="ReflectorView" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image005.jpg?w=377&#038;h=330" width="377" height="330" /></p>
<p><strong><span style="text-decoration:underline;">Ildasm View:</span></strong><strong></strong></p>
<p><img style="display:inline;border-width:0;" title="IldasmView" border="0" alt="IldasmView" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image006.jpg?w=388&#038;h=195" width="388" height="195" /></p>
<p>See resource name is qualified with assembly namespace name prefixed to it- <strong>MathLibrary.XMLFile.config</strong>.</p>
<p>Happy Coding!<a style="display:none;" href="http://dineshmandal.wordpress.com/2010/07/10/embedding-and-using-resources-from-dot-net-assembly/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/cvb-net/'>C#/VB.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/net-4-0/'>.Net 4.0</a>, <a href='http://dineshmandal.wordpress.com/tag/net-assembly/'>.Net Assembly</a>, <a href='http://dineshmandal.wordpress.com/tag/net3-5/'>.Net3.5</a>, <a href='http://dineshmandal.wordpress.com/tag/c/'>C#</a>, <a href='http://dineshmandal.wordpress.com/tag/visual-studio-2010/'>Visual Studio 2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/256/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=256&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2010/07/10/embedding-and-using-resources-from-dot-net-assembly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image0026.jpg" medium="image">
			<media:title type="html">ResourceProperties</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image0042.jpg" medium="image">
			<media:title type="html">ResourceSettings</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image005.jpg" medium="image">
			<media:title type="html">ReflectorView</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image006.jpg" medium="image">
			<media:title type="html">IldasmView</media:title>
		</media:content>
	</item>
		<item>
		<title>Visual Studio 2010: Exporting and Importing Break-Points</title>
		<link>http://dineshmandal.wordpress.com/2010/07/02/visual-studio-2010-exporting-and-importing-break-points/</link>
		<comments>http://dineshmandal.wordpress.com/2010/07/02/visual-studio-2010-exporting-and-importing-break-points/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 17:44:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">https://dineshmandal.wordpress.com/2010/07/02/visual-studio-2010-exporting-and-importing-break-points/</guid>
		<description><![CDATA[Coding less and debugging more has always been part of programming. Debugging of code is always accompanied by locating appropriate break-points and inspecting program execution. But locating break points again and again whenever a solution is opened for debugging consumes time. When we feel the program execution is happening as expected, then we either delete [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=236&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Coding less and debugging more has always been part of programming. Debugging of code is always accompanied by locating appropriate break-points and inspecting program execution. But locating break points again and again whenever a solution is opened for debugging consumes time. When we feel the program execution is happening as expected, then we either delete break-points or disable them. Overall, programmers spend few minutes for break-points activities.</p>
<p align="justify">Visual Studio 2010 comes with new feature of exporting and importing break-points in an xml file. So when we are done with break-points, we can export and save at a physical location. Then, delete the break-points (Ctrl + Shift + F9). Whenever we require break-points again in code, we can import the settings file that we saved last time. This xml file contains all the required settings of break-points in the code like line number, file name, etc.</p>
<p>Snapshots shown below are self-explanatory for .Net programmers.</p>
<p>Open break-point window (Ctrl + Alt + B).</p>
<p><img style="display:inline;border-width:0;" title="ExportBreakPoints" border="0" alt="ExportBreakPoints" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image0027.jpg?w=538&#038;h=398" width="538" height="398" />    <br />Fig 1: Exporting break-points</p>
<p><img style="display:inline;border-width:0;" title="ImportBreakPoints" border="0" alt="ImportBreakPoints" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image003.jpg?w=548&#038;h=466" width="548" height="466" /></p>
<p>Fig 2: Importing break-points</p>
<p>After importing break-point xml file, the break-points are again set at lines and files where break-points were set originally.</p>
<p><img style="display:inline;border-width:0;" title="BreakPoint-XmlStructure" border="0" alt="BreakPoint-XmlStructure" src="http://dineshmandal.files.wordpress.com/2010/09/clip_image0043.jpg?w=444&#038;h=289" width="444" height="289" />    <br />Fig 3: Break-point xml structure</p>
<p>Cheers!<a style="display:none;" href="http://dineshmandal.wordpress.com/2010/07/02/visual-studio-2010-exporting-and-importing-break-points/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/cvb-net/'>C#/VB.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/net-4-0/'>.Net 4.0</a>, <a href='http://dineshmandal.wordpress.com/tag/debugging/'>Debugging</a>, <a href='http://dineshmandal.wordpress.com/tag/visual-studio-2010/'>Visual Studio 2010</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=236&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2010/07/02/visual-studio-2010-exporting-and-importing-break-points/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image0027.jpg" medium="image">
			<media:title type="html">ExportBreakPoints</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image003.jpg" medium="image">
			<media:title type="html">ImportBreakPoints</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/09/clip_image0043.jpg" medium="image">
			<media:title type="html">BreakPoint-XmlStructure</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.Net 4.0 New Features</title>
		<link>http://dineshmandal.wordpress.com/2010/05/08/asp-net-4-0-new-features/</link>
		<comments>http://dineshmandal.wordpress.com/2010/05/08/asp-net-4-0-new-features/#comments</comments>
		<pubDate>Sat, 08 May 2010 19:11:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HttpHandler]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">https://dineshmandal.wordpress.com/2010/05/08/asp-net-4-0-new-features-2/</guid>
		<description><![CDATA[ViewStateMode – ViewState for Individual Controls ASP.Net 4.0 allows view state in a page to be more controllable from page to its child controls level. That is, view state of a control can be enabled or disabled irrespective of its parent control’s view state. Even if view state of a page is disabled, controls of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=222&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify"><strong>ViewStateMode – ViewState for Individual Controls</strong>    <br />ASP.Net 4.0 allows view state in a page to be more controllable from page to its child controls level. That is, view state of a control can be enabled or disabled irrespective of its parent control’s view state. Even if view state of a page is disabled, controls of the page can have their own view state individually enabled or disabled or even inherited from the page’s view state mode property.    <br />This property if utilized properly can certainly boost performance of a page.</p>
<p>For example, we can individually enable or disable user control’s view state in a page.</p>
<p><img style="display:inline;border-width:0;" title="ViewStateMode" border="0" alt="ViewStateMode" src="http://dineshmandal.files.wordpress.com/2010/10/clip_image002.jpg?w=506&#038;h=301" width="506" height="301" /></p>
<p>By default, ViewStateMode is enabled for a page object, while controls have inherit mode.</p>
<p align="justify"><strong>Page.MetaKeywords and Page.MetaDescription &#8211; SEO Optimization Feature</strong>    <br />ASP.Net 4.0 has come up with these two properties that will help developers add meta tags for keywords and description in the aspx pages in easier fashion. Web Search Engines really need these two meta tags for search indexing of any pages. These two properties can be used in a page in various ways. Inside &lt;head&gt; tag or in the code behind or even at &lt;%@Page%&gt; directive level.</p>
<p align="justify">However, setting meta keywords or description in code behind will be more useful when we have to add keywords and descriptions dynamically from source like database.</p>
<p align="justify">MetaKeyWords is used to store few useful keywords that will briefly highlight important information of a page by tags. From SEO perspective, meta keywords should contain keywords separated by spaces.</p>
<p align="justify">MetaDescription is used to add page description in short that will help Search Engines to quickly describe about the page links in search pages.</p>
<p align="justify">Prior to ASP.Net 4.0, we have to add meta tags using HtmlMeta control (public class HtmlMeta : HtmlControl) adding into page header as:</p>
<pre>protected void Page_Load(object sender, EventArgs e)
{
//
HtmlMeta metakey = new HtmlMeta();
metakey.Name = &quot;keywords&quot;;
metakey.Content = &quot;ASP.Net 2.0 3.5&quot;;
HtmlMeta metadesc = new HtmlMeta();
metadesc.Name = &quot;description&quot;;
metadesc.Content = &quot;ASP.Net 2.0 3.5 Page Description...&quot;;
//Add to page header
Page.Header.Controls.Add(metakey);
Page.Header.Controls.Add(metadesc);
}</pre>
<p>
  <br />In ASP.Net 4.0, we can add in many ways.</p>
<p></p>
<pre>protected void Page_Load(object sender, EventArgs e)
{
//Adding Page meta tags information
this.Page.MetaKeywords = &quot;ASP.Net 4.0 SEO Meta Tag&quot;;
this.Page.MetaDescription = &quot;Serializing and Deserializing Thoughts..&quot;;
}</pre>
<p>Or,<br />
  
<pre>&lt;head runat=&quot;server&quot;&gt;
  &lt;title&gt;Feature: ViewStateMode&lt;/title&gt;
  &lt;meta name=&quot;keywords&quot; content =&quot;ASP.Net 4.0 ViewStateMode&quot;/&gt;
  &lt;meta name=&quot;description&quot; content=&quot;ViewStateMode feature in ASP.Net 4.0&quot; /&gt;
  &lt;/head&gt;</pre>
</p>
<p>Or inside Page directive,</p>
<p><img style="display:inline;border-width:0;" title="MetaDescription" border="0" alt="MetaDescription" src="http://dineshmandal.files.wordpress.com/2010/10/clip_image003.jpg?w=539&#038;h=250" width="539" height="250" /></p>
<p><strong></strong></p>
<p align="justify"><strong>Response.RedirectPermanent – Search Engine Friendly Webpage Redirection</strong></p>
<p>In classic ASP or ASP.Net earlier than 4.0, we used to redirect to new pages or links by setting Response.StatusCode to 301 before calling Response.AddHeader method. Now ASP.Net 4.0 has provided Response.RedirectPermanent method to redirect to new pages or links with StatusCode of 301 implicitly set. Search Engines use this 301 code to understand permanent redirection from old pages links.</p>
<p>For example,<br />
  <br />Classic ASP method:</p>
<pre>&lt;%@ Language=VBScript %&gt;
&lt;%
Response.Status=&quot;301 Moved Permanently&quot;
Response.AddHeader &quot;Location&quot;,&quot;http://www.new-page-url.com/&quot;
%&gt;</pre>
<p>
  <br />ASP.Net method prior to 4.0:</p>
<p></p>
<pre>&lt;script runat=&quot;server&quot;&gt;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = &quot;301 Moved Permanently&quot;;
Response.AddHeader(&quot;Location&quot;,&quot;http://www.new-page-url.com&quot;);
}
&lt;/script&gt;</pre>
<p>
  <br />ASP.Net 4.0 method:</p>
<p></p>
<pre>Response.RedirectPermanent(&quot;http://www.new-page-url.com &quot;);</pre>
<p align="justify">
  <br /><strong>Web.Config Refactoring – Custom HttpHandlers and HttpModules</strong></p>
<p>Web.config now looks cleaner as most of the settings are controlled from machine.config file as ASP.Net 4.0 is all set to benefit from IIS 7 and IIS 7.5 features. When IIS is set to use .Net 4.0 and Integrated Pipeline mode, &lt;compilation&gt; element holds .Net version attribute. And the traditional &lt;httpHandlers&gt; and &lt;httpModules&gt; section is now shifted out of &lt;system.web&gt; and added inside new section &lt;system.webserver&gt;. All the custom handlers are added inside &lt;handlers&gt;, and all the modules inside &lt;modules&gt; section.</p>
<p></p>
<pre>&lt;system.webServer&gt;
&lt;!-- Add the module for Integrated mode applications --&gt;
&lt;modules runAllManagedModulesForAllRequests=&quot;true&quot;&gt;
&lt;add name=&quot;MyModule&quot; type=&quot;WebAppModule.MyCustomModule, WebAppModule&quot; /&gt;
&lt;/modules&gt;
&lt;!-- Add the handler for Integrated mode applications --&gt;
&lt;handlers&gt;
&lt;add name=&quot;MyHandler&quot; path=&quot;svrtime.tm&quot; verb=&quot;GET&quot; &lt;type=&quot;WebAppModule.MyCustomHandler, WebAppModule&quot;preCondition=&quot;integratedMode&quot; /&gt;
&lt;/handlers&gt;
&lt;/system.webServer&gt;</pre>
<p>
  <br />Also,</p>
<p></p>
<pre>&lt;system.web&gt;
&lt;compilation debug=&quot;true&quot; targetFramework=&quot;4.0&quot; /&gt;</pre>
<p align="justify">
  <br />Interesting point is, when we add custom handlers and modules this way, we do not have to manually configure handlers and modules in IIS again. IIS will automatically refresh itself.<a style="display:none;" href="http://dineshmandal.wordpress.com/2010/05/08/asp-net-4-0-new-features/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/asp-net/'>ASP.Net</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/cvb-net/'>C#/VB.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/iis/'>IIS</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/net-4-0/'>.Net 4.0</a>, <a href='http://dineshmandal.wordpress.com/tag/asp-net/'>ASP.Net</a>, <a href='http://dineshmandal.wordpress.com/tag/c/'>C#</a>, <a href='http://dineshmandal.wordpress.com/tag/httphandler/'>HttpHandler</a>, <a href='http://dineshmandal.wordpress.com/tag/iis/'>IIS</a>, <a href='http://dineshmandal.wordpress.com/tag/seo/'>SEO</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/222/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/222/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/222/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=222&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2010/05/08/asp-net-4-0-new-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/10/clip_image002.jpg" medium="image">
			<media:title type="html">ViewStateMode</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2010/10/clip_image003.jpg" medium="image">
			<media:title type="html">MetaDescription</media:title>
		</media:content>
	</item>
		<item>
		<title>Exception Handling in WCF</title>
		<link>http://dineshmandal.wordpress.com/2010/04/04/exception-handling-in-wcf/</link>
		<comments>http://dineshmandal.wordpress.com/2010/04/04/exception-handling-in-wcf/#comments</comments>
		<pubDate>Sun, 04 Apr 2010 12:12:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Exception Handling]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/?p=208</guid>
		<description><![CDATA[We have been doing exception handling in managed application using try-catch block with Exception or its derived Custom Exception objects. But this mechanism is very much .Net Technology specific. When we develop SOA applications, our application is not limited to mere one technology or single loyal client. So the communication process of this service or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=208&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">We have been doing exception handling in managed application using try-catch block with Exception or its derived Custom Exception objects. But this mechanism is very much .Net Technology specific. When we develop SOA applications, our application is not limited to mere one technology or single loyal client. So the communication process of this service or service method level errors to client via wire becomes a little bit tricky. WCF has two types of error handling mechanism: one is by as usual Exception objects, and other is by SOAP fault message. SOAP fault is used to marshall .Net exceptions to client in much readable and convenient way to support interoperability. With use of SOAP fault, the verbose exception message is reduced to Code and Message. For this System.ServiceModel namespace comes FaultException class and FaultContract attribute.</p>
<p align="justify">Let’s come to see from example on how to do exception handling in WCF application. Before this, write our service first.</p>
<blockquote><p>namespace WcfSvc     <br />{     <br />[ServiceContract]     <br />public interface IBasicMathService     <br />{     <br />[OperationContract]     <br />int Subtraction(int x, int y);</p>
<p>[OperationContract]     <br />int Multiplication(int x, int y);</p>
<p>[OperationContract]   <br />[FaultContract(typeof(BasicMathFault))]   <br />int Addition(int x, int y);   <br />}</p>
<p>[DataContract]   <br />public class BasicMathFault   <br />{   <br />//   <br />[DataMember]   <br />public string Source;</p>
<p>[DataMember]   <br />public string ExceptionMessage;</p>
<p>[DataMember]   <br />public string InnerException;</p>
<p>[DataMember]   <br />public string StackTrace;    <br />}    <br />}</p>
</blockquote>
<p>And its implementation is as:</p>
<blockquote><p>public class BasicMath : IBasicMathService   <br />{   <br />public int Addition(int x, int y)   <br />{   <br />//   <br />int result = 0;   <br />try   <br />{   <br />result = (x + y);   <br />}   <br />catch   <br />{   <br />BasicMathFault ex = new BasicMathFault();   <br />ex.Source = &quot;BasicMath.Addition method&quot;;   <br />ex.ExceptionMessage = &quot;Could not perform addition operation.&quot;;   <br />ex.InnerException = &quot;Inner exception from math service&quot;;   <br />ex.StackTrace = &quot;&quot;;   <br />//Throwing strongly-typed FaultException   <br />throw new FaultException(ex, new FaultReason(&quot;This is an error condition in BasicMath.Addition method&quot;)); }   </p>
<p>return result;   <br />}</p>
<p>public int Multiplication(int x, int y)   <br />{   <br />//Due to some calculation error condition, let&#8217;s assume we are throwing this error.   <br />//Throwing simply FaultException   <br />throw new FaultException(new FaultReason(&quot;Error occurred while processing    <br />for the result&quot;), new FaultCode(&quot;mutliplication.method.error&quot;));    <br />}</p>
<p>public int Subtraction(int x, int y)   <br />{   <br />//Exception we generally throw in managed application in the form of Exception object   <br />throw new NotImplementedException(&quot;Method still not implemented&quot;);    <br />}    <br />}</p>
</blockquote>
<p>This is our typical service related code. If we see IBasicMathService interface and its implementation in BasicMath class, we have:    </p>
<p>Addition(x,y) method decorated with FaultContract attribute in IBasicMathService class,     </p>
<p>Subtraction(x,y) method using simple Exception throwing mechanism,     </p>
<p>Multiplication(x,y) method using simple FaultException object, and     </p>
<p>Addition(x,y) method using strongly-typed fault of type BasicMathFault in FaultException object</p>
<p align="justify">So what does all this mean to client, and how exception is transmitted to client? Let’s answer with these three examples in our client code.</p>
<p><strong>A) Throwing Simple Exception</strong></p>
<blockquote><p>private void SubtractIntegers()   <br />{   <br />try   <br />{   <br />obj = new BasicmathServiceRef.BasicMathServiceClient();   <br />int result = obj.Subtraction(10, 15);   <br />}   <br />catch (Exception ex)   <br />{   <br />Response.Write(ex.Message + &quot;   <br />&quot;);   <br />}   <br />}</p>
</blockquote>
<p align="justify">When this method is called, client receives verbose error message from WCF as:    </p>
<p>“The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.”</p>
<p align="justify">If we closely see this error information, we come across two things: turn on\off IncludeExceptionDetailInFaults value either through ServiceBehaviorAttribute of the class containing this method, or modify IncludeExceptionDetailInFaults value in configuration file or section of this service.</p>
<p>Either of these two things is pretty easy.</p>
<p>a) Decorate BasicMath class as:</p>
<blockquote><p>[ServiceBehavior(IncludeExceptionDetailInFaults = false)]   <br />public class BasicMath : IBasicMathService   <br />{</p>
</blockquote>
<p>b) Or, modify in config file</p>
<p align="justify">By default this key value is false. If we make it true, the verbose error message that we received will be reduced to human readable message that we passed in constructor of NotImplementedException.    </p>
<p>“Method still not implemented”</p>
<p align="justify">While debugging WCF exception, one may encounter error in the service like “xyz exception unhandled by user code”. This is some what <a href="http://connect.microsoft.com/VisualStudio/feedback/details/302017/wcf-misleading-exception-in-debugger-faultexception-was-unhandled-by-user-code" target="_blank">misleading</a>, but no need to worry.</p>
<p><strong>B) Throw exception of FaultException type</strong></p>
<blockquote><p>private void MultiplyIntegers()   <br />{   <br />try   <br />{   <br />obj = new BasicmathServiceRef.BasicMathServiceClient();   <br />int result = obj.Multiplication(10, 15);   <br />}   <br />catch (FaultException ex)   <br />{   <br />Response.Write(ex.Message + &quot;&quot;);   <br />}   <br />}</p>
</blockquote>
<p align="justify">On calling this method, WCF will serialize the exception as a Fault message and return to the client as:    </p>
<p>“Error occurred while processing for the result”</p>
<p>However, client is unlikely to receive verbose error message if we throw exception of type FaultException even key IncludeExceptionDetailInFaults is true or false. If we see the exception thrown code,</p>
<blockquote><p>throw new FaultException(new FaultReason(&quot;Error occurred while processing for the result&quot;), new FaultCode(&quot;mutliplication.method.error&quot;));</p>
</blockquote>
<p align="justify">we have used FaultCode. Client can use this specific fault code contained in FaultException code to take decision, but this approach becomes more of procedural by many if-else condition to branch out code some thing like:</p>
<blockquote><p>if (ex.Code.Name == &quot;mutliplication.method.error&quot;)   <br />{   <br />Response.Write(ex.Message + &quot;&quot;);   <br />}</p>
</blockquote>
<p><strong>C) Throwing with strongly typed fault</strong><br />
<blockquote>private void AddIntegers()    <br />{    <br />try    <br />{    <br />obj = new BasicmathServiceRef.BasicMathServiceClient();    <br />int result = obj.Addition(10, 15);    <br />}    <br />catch (FaultException ex)    <br />{    <br />Response.Write(ex.Message + &quot; &quot;);    <br />}    <br />}</p>
</blockquote>
<p align="justify">With this approach, client will be able to explicitly handle fault of only that type whose service method is to be used by client. Here, we are using BasicMathFault type. At the service level, the specific method has to be decorated with FaultContract attribute so that exception can be serialized as:<br />
<blockquote>[OperationContract]    <br />[FaultContract(typeof(BasicMathFault))]    <br />int Addition(int x, int y);</p>
</blockquote>
<p align="justify">The detail of fault type is up to our convenient level to let WCF serialize only needful information to client.</p>
<p align="justify">When we call this Addition(x,y) method, one may receive this error message if an exception occurs.    </p>
<p>“This is an error condition in BasicMath.Addition method”</p>
<p>Thus, we see how we can do exception handling in WCF.<a style="display:none;" href="http://dineshmandal.wordpress.com/2010/04/04/exception-handling-in-wcf/" rel="tag">CodeProject</a></p>
<br />Filed under: <a href='http://dineshmandal.wordpress.com/category/net-technologies/'>.Net Technologies</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/cvb-net/'>C#/VB.Net</a>, <a href='http://dineshmandal.wordpress.com/category/codeproject/'>CodeProject</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/dot-net-tips/'>Dot Net Tips</a>, <a href='http://dineshmandal.wordpress.com/category/net-technologies/wcf/'>WCF</a> Tagged: <a href='http://dineshmandal.wordpress.com/tag/net3-5/'>.Net3.5</a>, <a href='http://dineshmandal.wordpress.com/tag/asp-net/'>ASP.Net</a>, <a href='http://dineshmandal.wordpress.com/tag/c/'>C#</a>, <a href='http://dineshmandal.wordpress.com/tag/debugging/'>Debugging</a>, <a href='http://dineshmandal.wordpress.com/tag/exception-handling/'>Exception Handling</a>, <a href='http://dineshmandal.wordpress.com/tag/wcf/'>WCF</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=208&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2010/04/04/exception-handling-in-wcf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>
	</item>
		<item>
		<title>Designing Business Logic Layer: Some Guidelines</title>
		<link>http://dineshmandal.wordpress.com/2010/01/01/designing-business-logic-layer/</link>
		<comments>http://dineshmandal.wordpress.com/2010/01/01/designing-business-logic-layer/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 14:32:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Factory Pattern]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/?p=198</guid>
		<description><![CDATA[Business Logic Layer is a very crucial layer for any data base applications. A timely thought when applied to this layer from the beginning of application layers design can save lots of time and complexity. Software architects divide the software into modules, then different layers, and core functioning layers for important application features. But when [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=198&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">Business Logic Layer is a very crucial layer for any data base applications. A timely thought when applied to this layer from the beginning of application layers design can save lots of time and complexity. Software architects divide the software into modules, then different layers, and core functioning layers for important application features. But when actual development work starts, complexity of different layers and modules start crawling into code gradually.    <br />Reason being:     <br />• We try to mix business rules of different modules wishfully     <br />• Writing methods with abundant codes     <br />• Not clearly separating responsibilities of presentation and data access layers     <br />• Creating code duplicity, i.e.; writing same set of code or methods at various places</p>
<p>Results are:    <br />• Difficult to debug     <br />• Difficult to understand the flow     <br />• Difficult to maintain and modify business rules correctly when such rules exist across layers and modules     <br />• Difficult to write Unit Tests</p>
<p align="justify">We can avoid these things if we take care of these things when writing codes.    <br />• Write methods that do single meaningful task with one call. Do not mix other code logic with the methods. For example, if we write SavePayment() method, then this method should only focus on save task, and not update or delete or check connection status or read Xml files, etc. This is what we call Single Responsibility Principle.     <br />• Encourage use of factory methods for object creation instead of writing lots of If-else constructs based upon some input type values.     <br />• When you need data or result sets (DTO) of other modules, then preferably call business logic layer methods of that module instead of writing that module code logic into yours. This is quite important aspect for any business logic layer.     <br />• Classes in this layer should be loosely coupled. For this different injection patterns like dependency injection or inversion of control, etc can help. Sometimes even a simple Enum type can come to a great rescue.     <br />• Write business methods that accept valid entity class object or DTO object in business rather than single valued parameters like integer or string or array or even optional params. This ensures business logic layer code function even unmodified when there are database table and entity or DTO class changes in behind.     <br />• Avoid lots of business rules in stored procedures or even in presentation UI.     <br />• Business logic layer methods should not be aware of presentation UI controls’ properties or values. These methods should accept values in integer or string instead.</p>
<p align="justify">Let me explain all these points by one example. I worked in an accounting module of a project where customers can make payments of their bills in various ways. They can make either full payment or in-partial or even in installments. For each payment mode, there were different rules and validations. So this module had clear separation of implementation with rules of each mode functioning without depending upon others. This way our lots of coding and debugging time got saved.    <br />Let’s see the code snippets.</p>
<p><span style="text-decoration:underline;">Enum showing different Payment Mode       <br /></span><br />
<blockquote>
<p>public enum PaymentMode </p>
<p>   	{      <br />Normal,       <br />Part,       <br />Installment       <br />}</p>
</blockquote>
<p><span style="text-decoration:underline;">Custome Bill DTO       <br /></span><br />
<blockquote>
<p>public class CustomerBillDTO </p>
<p>     {      <br />private Int64 intBillNo;      <br />private Int16 intBillMonth;      <br />private Int16 intBillYear;      <br />private double dblBillAmount;      <br />private string strCustomerID;      <br />private Int64 intPayAmount;      <br />//And many other fields&#8230;      <br />}</p>
</blockquote>
<p><span style="text-decoration:underline;">Payment Processor factory class</span><br />
<blockquote>
<p>interface IPaymentProcessorFactory       <br />{       <br />//       <br />IPaymentProcessor GetPaymentProcessor(PaymentMode mode);      <br />}</p>
<p>public class PaymentProcessorFactory : IPaymentProcessorFactory      <br />{       <br />//       <br />private IPaymentProcessor objPaymentProcessor = null;</p>
<p>public IPaymentProcessor GetPaymentProcessor(PaymentMode mode)      <br />{       <br />//       <br />switch (mode)       <br />{       <br />case PaymentMode.Normal:       <br />objPaymentProcessor = new NormalPaymentProcessor();       <br />break;</p>
<p>case PaymentMode.Part:      <br />objPaymentProcessor = new PartPaymentProcessor();       <br />break;       <br />case PaymentMode.Installment:       <br />objPaymentProcessor = new InstallmentPaymentProcessor();       <br />break;       <br />}       <br />return objPaymentProcessor;       <br />}       <br />}</p>
</blockquote>
<p><span style="text-decoration:underline;">Different Payment Processor class      <br /></span><br />
<blockquote>
<p>public interface IPaymentProcessor </p>
<p>     {      <br />//       <br />bool SavePayment(CustomerBillDTO Bill);       <br />}</p>
<p>public class NormalPaymentProcessor:IPaymentProcessor      <br />{       <br />//       <br />public bool SavePayment(CustomerBillDTO Bill)       <br />{       <br />return true;       <br />}       <br />}</p>
<p>public class PartPaymentProcessor : IPaymentProcessor      <br />{       <br />//       <br />public bool SavePayment(CustomerBillDTO Bill)       <br />{       <br />return true;       <br />}       <br />}</p>
<p>public class InstallmentPaymentProcessor : IPaymentProcessor      <br />{       <br />//       <br />public bool SavePayment(CustomerBillDTO Bill)       <br />{       <br />return true;       <br />}       <br />}</p>
</blockquote>
<p><span style="text-decoration:underline;">Main class that processes each payment       <br /></span><br />
<blockquote>
<p>class PaymentProcess </p>
<p>    {      <br />private IPaymentProcessorFactory objProcessor = null;       <br />public PaymentProcess(IPaymentProcessorFactory Processor)       <br />{       <br />//       <br />this.objProcessor = Processor;       <br />}</p>
<p>public bool ProcessPayment(CustomerBillDTO Bill, PaymentMode mode)      <br />{       <br />//       <br />IPaymentProcessor objPaymentProcessor = this.objProcessor.GetPaymentProcessor(mode);       <br />return objPaymentProcessor.SavePayment(Bill);       <br />}       <br />}</p>
</blockquote>
<p>At the calling end, we simply make a generous call as:<br />
<blockquote>private void BtnSave_Click(object sender, EventArgs e)       <br />{       <br />//       <br />PaymentProcessorFactory objFactory = new PaymentProcessorFactory();       <br />PaymentProcess objProcess = new PaymentProcess(objFactory);       <br />bool result = objProcess.ProcessPayment(objCustomerBillDTO(), PaymentMode.Normal);       <br />}</p>
</blockquote>
<p align="justify">As we see this is how we have clearly separated each logical functioning of a SavePayment() method.    <br />Even in future, if Part or Installment payment mode is stopped, we do not have to modify the code logic to add any If-else construct to branch out or skip any code flows. In case a new payment mode is added, then writing a new XModePaymenetProcessor class, adding one more Enum value and finally one more object instantiation code in factory class will do enough.</p>
<p>Adding or removing any Bill or Customer related fields in CustomerBillDTO do not even pose threat to this business logic layer.</p>
<p align="justify">Finally, one should always keep in mind that <strong>you write class and class methods for others</strong>. So you should be very clear here: <strong>what the class should offer and how</strong>.</p>
<p>Thanks. <a style="display:none;" href="http://dineshmandal.wordpress.com/2010/01/01/designing-business-logic-layer/" rel="tag">CodeProject</a></p>
<br />Posted in .Net Technologies, Architecture, ASP.Net, C#/VB.Net, CodeProject, Dot Net Tips Tagged: Architecture, Design Patterns, Factory Pattern <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/198/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=198&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2010/01/01/designing-business-logic-layer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>
	</item>
		<item>
		<title>Some Hidden Facts: Stored Procedure and Its Optimization</title>
		<link>http://dineshmandal.wordpress.com/2009/12/26/stored-procedure-optimization/</link>
		<comments>http://dineshmandal.wordpress.com/2009/12/26/stored-procedure-optimization/#comments</comments>
		<pubDate>Sat, 26 Dec 2009 13:38:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Sql Server]]></category>
		<category><![CDATA[Query Optimization Techniques]]></category>
		<category><![CDATA[Stored Procedure]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/?p=190</guid>
		<description><![CDATA[We create stored procedures in database applications for several reasons and benefits like enhanced performance, security, code maintenance, etc. But with time we may see that these stored procedures are not performing well as expected. There can be many reasons like dependent objects (tables, indexes, execution plans, and data size) changed or stored procedures executing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=190&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We create stored procedures in database applications for several reasons and benefits like enhanced performance, security, code maintenance, etc. But with time we may see that these stored procedures are not performing well as expected. There can be many reasons like dependent objects (tables, indexes, execution plans, and data size) changed or stored procedures executing improperly. So we have to be a little bit careful from the beginning of creating stored procedures to execution.</p>
<p>I like to summarize few points about all these things.</p>
<p><strong>A. Stored Procedure Recompilation</strong><br />
When creating a stored procedure, we can specify WITH RECOMPILE option in it. But such stored procedure will never benefit from the cached execution plan as each time it is executed; it forces the cached execution plan to invalidate or flush and create new plan based upon the parameters passed, if any, to it. I do not see any such big benefits of this option. But one may find this useful when such stored procedure will return results or execute only selective part of the stored procedure body based upon supplied input parameters. For example, statements within If-block or Select-Case block based upon input parameters.</p>
<p>But I still feel one should go after the new feature of SQL Server 2008 that helps recompile statement level queries rather than whole stored procedure. But this option will be quite useful as such recompilation is dependent upon input data. Let’s say if you are executing the stored procedure by supplying input parameter like ‘FirstName’ or ‘LastName’ or ‘DateOfBirth’ at a time, then statement-level query recompilation option is better. To use this method, one has to specify that SQL-statement within stored procedure with RECOMPILE query hint.</p>
<p>For example,<br />
CREATE PROC dbo.uspExample<br />
@x_input AS INT,<br />
@y_input AS INT<br />
AS<br />
If @x_input = 1<br />
BEGIN<br />
SELECT x, y, z<br />
FROM dbo.tblXYZ<br />
WHERE xColumn &gt;= @x_input<br />
<strong>OPTION(RECOMPILE);               &#8211;</strong>See here the query hint<br />
End<br />
If @y_input = 2<br />
BEGIN<br />
SELECT x, y, z<br />
FROM dbo.tblXYZ<br />
WHERE yColumn &gt;= @y_input<br />
END<br />
GO</p>
<p>Another tool that we can use is <strong>sp_recompile</strong> system stored procedure. This procedure forces recompile of user defined stored procedure next time it is run.</p>
<p>Let’s look at its syntax first.<br />
<strong>Sp_recompile </strong><strong>‘@somedependent_object’</strong><strong>;<br />
</strong></p>
<p>Here, ‘@somedependent_object’ can be either table or view or another stored procedure or even trigger. If this ‘@somedependent_object’ is table name, then sql server will compile all the stored procedures that references this table. If this object name is some stored procedure, then this stored procedure will recompile next time it is run.<br />
This option is good when the table properties are changed, and this table is in use of many other stored procedures. Instead of recompiling each and every such depending stored procedure, a simple sp_recompile will do enough, and with no server restart!</p>
<p>But there are many other scenarios when stored procedure recompilation can happen automatically. If server is running out of memory, the execution cache will get flushed. If the stored procedure has some session specific SET modifiers (like LOCK TIMEOUT, DATEFIRST, ANSI_WARNINGS, etc), then also stored procedure can recompile.</p>
<p>Situations like when we mix DDL and DML statements together inside stored procedure may also cause stored procedure recompilation. For example, most of us create temporary tables inside stored procedure. Then, do DML operations based upon values in these temporary tables. Even this type of stored procedure is forced to recompile to create new plan according to such new temporary tables. For this type of stored procedure, one should opt for statement-level recompilation by using RECOMPILE hint in that DML statement following DDL statements.</p>
<p>But what is alternative to temporary tables here? We can use table variables instead! Or, if we cannot do without temporary tables, then we should write such DDL statements in the beginning of stored procedure body itself so that multiple recompilations are not happening for a single call to this stored procedure.</p>
<p>So stored procedure recompilation can be harmful and useful both depending upon situations. One has to think twice whether recompilation is required or not.</p>
<p><strong>B. Stored Procedure Name<br />
</strong>We should always create a stored procedure with a full naming convention. Schema name should always prefix the stored procedure name. Schema name will help sql server name resolution easily when it is called. This helps sql server in which schema to query the stored procedure.</p>
<p><strong>C. Table Indexes</strong><br />
Tables should have proper indexes and compiled time to time as indexes may be weird off after some time due to huge data insertion or deletion.</p>
<p>This is all about some useful facts about stored procedure.</p>
<p><a style="display:None;" rel="tag" href="http://dineshmandal.wordpress.com/2009/12/26/stored-procedure-optimization/">CodeProject</a></p>
<br />Posted in CodeProject, Sql Server Tagged: Query Optimization Techniques, Stored Procedure <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/190/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=190&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2009/12/26/stored-procedure-optimization/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>
	</item>
		<item>
		<title>Calling Method in Parent Page from User Control</title>
		<link>http://dineshmandal.wordpress.com/2009/10/10/calling-method-in-parent-page-from-user-control/</link>
		<comments>http://dineshmandal.wordpress.com/2009/10/10/calling-method-in-parent-page-from-user-control/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 19:14:48 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[UserControl]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/?p=178</guid>
		<description><![CDATA[In ASP.Net, we develop custom user control as a reusable server control independent of any containing parent aspx page. User control has its own public properties, methods, delegates, etc that can be used by parent aspx page. When a user control is embedded or loaded into a page, the page can access public properties, methods, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=178&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p align="justify">In ASP.Net, we develop custom user control as a reusable server control independent of any containing parent aspx page. User control has its own public properties, methods, delegates, etc that can be used by parent aspx page. When a user control is embedded or loaded into a page, the page can access public properties, methods, delegates, etc that are in user control. After loading the user control, there a situation may arise like calling methods in page itself. But when a user control is developed, it has no knowledge of containing page. So it becomes a trick to call the page method.</p>
<p>In .Net, Delegate class has one method <a href="http://msdn.microsoft.com/en-us/library/system.delegate.dynamicinvoke%28VS.71%29.aspx">DynamicInvoke</a>. DynamicInvoke method is used to invoke (late-bound) method referenced by delegate. We can use this method to call a method in parent page from user control. Let’s try with this example.</p>
<p>First create a user control called CustomUserCtrl. Its code will look some thing like this:</p>
<p>public partial class CustomUserCtrl : System.Web.UI.UserControl   <br />{    <br />private System.Delegate _delWithParam;    <br />public Delegate PageMethodWithParamRef    <br />{    <br />set { _delWithParam = value; }    <br />}</p>
<p>private System.Delegate _delNoParam;   <br />public Delegate PageMethodWithNoParamRef    <br />{    <br />set { _delNoParam = value; }    <br />}</p>
<p>protected void Page_Load(object sender, EventArgs e)   <br />{    <br />}</p>
<p>protected void BtnMethodWithParam_Click(object sender, System.EventArgs e)   <br />{    <br />//Parameter to a method is being made ready    <br />object[] obj = new object[1];    <br />obj[0] = &quot;Parameter Value&quot; as object;    <br />_delWithParam.DynamicInvoke(obj);    <br />}</p>
<p>protected void BtnMethowWithoutParam_Click(object sender, System.EventArgs e)   <br />{    <br />//Invoke a method with no parameter    <br />_delNoParam.DynamicInvoke();    <br />}    <br />}</p>
<p>Then add this user control into an aspx page. The code behind of this page is as:</p>
<p>public partial class _Default : System.Web.UI.Page   <br />{    <br />delegate void DelMethodWithParam(string strParam);    <br />delegate void DelMethodWithoutParam();    <br />protected void Page_Load(object sender, EventArgs e)    <br />{    <br />DelMethodWithParam delParam = new DelMethodWithParam(MethodWithParam);    <br />//Set method reference to a user control delegate    <br />this.UserCtrl.PageMethodWithParamRef = delParam;    <br />DelMethodWithoutParam delNoParam = new DelMethodWithoutParam(MethodWithNoParam);    <br />//Set method reference to a user control delegate    <br />this.UserCtrl.PageMethodWithNoParamRef = delNoParam;    <br />}</p>
<p>private void MethodWithParam(string strParam)   <br />{    <br />Response.Write(&quot;&lt;br/&gt;It has parameter: &quot; + strParam);    <br />}</p>
<p>private void MethodWithNoParam()   <br />{    <br />Response.Write(&quot;&lt;br/&gt;It has no parameter.&quot;);    <br />}    <br />}</p>
<p align="justify">BtnMethodWithParam and BtnMethowWithoutParam are two different buttons on the user control that are invoking the methods in the parent page. On Page_Load of the page, we are setting the references of page class methods to delegate type properties in the user control. Click different buttons of user control, you will see MethodWithParam(string strParam) and MethodWithNoParam() methods called.</p>
<p>This is all we have to do to call page class methods from user control in ASP.Net.<a style="display:none;" href="http://dineshmandal.wordpress.com/2009/10/10/calling-method-in-parent-page-from-user-control/" rel="tag">CodeProject</a></p>
<br />Posted in .Net Technologies, ASP.Net, C#/VB.Net, CodeProject, Dot Net Tips Tagged: .Net3.5, ASP.Net, C#, UserControl <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/178/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=178&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2009/10/10/calling-method-in-parent-page-from-user-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>
	</item>
		<item>
		<title>Load ASP.Net User Control Dynamically Using jQuery</title>
		<link>http://dineshmandal.wordpress.com/2009/10/10/load-asp-net-user-control-dynamically-using-jquery/</link>
		<comments>http://dineshmandal.wordpress.com/2009/10/10/load-asp-net-user-control-dynamically-using-jquery/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 12:26:22 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[JavaScript/jQuery/JSON/Ajax]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[HttpHandler]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[UserControl]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/?p=170</guid>
		<description><![CDATA[Today we will explore the way of loading ASP.Net user control at run time using jQuery. jQuery has one method load(fn) that will help here. This load(fn) method has following definition. load (url, data, callback): A GET request will be performed by default &#8211; but if any extra parameters are passed, then a POST will [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=170&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today we will explore the way of loading ASP.Net user control at run time using jQuery. jQuery has one method <a href="http://www.visualjquery.com/">load(fn)</a> that will help here. This load(fn) method has following definition.</p>
<p>load (url, data, callback): A GET request will be performed by default &#8211; but if any extra parameters are passed, then a POST will occur.<br />
url (string): URL of the required page<br />
data (map – key/value pair): key value pair data that will be sent to the server<br />
callback (callback method): call back method, not necessarily success</p>
<p>Now comes custom HttpHandler that will load the required user control from the URL given by this load(fn) method. We all know that it is either in-built or custom HttpHandler that is the end point for any request made in ASP.Net.</p>
<p>Let’s see by example. In the ASP.Net application, add one aspx page and user control. Then, add one more class derived from IHttpHandler. The aspx html markup will look something like this.</p>
<p>&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221; &gt;<br />
&lt;head runat=&#8221;server&#8221;&gt;<br />
&lt;title&gt;Load ASP.Net User Control&lt;/title&gt;<br />
&lt;script src=&#8221;jquery-1.2.6.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script&gt;<br />
$(document).ready(function() {<br />
$(&#8220;#BtnLoadUserCtrl&#8221;).click(function() {<br />
$(&#8220;#UserCtrl&#8221;).load(&#8220;SampleUserCtrl.ascx&#8221;);<br />
});<br />
});<br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;form runat=&#8221;server&#8221;&gt;<br />
&lt;div&gt;<br />
&lt;br /&gt;<br />
&lt;input value=&#8221;Load User Control&#8221; /&gt; &lt;br /&gt;<br />
&lt;div id=&#8221;UserCtrl&#8221;&gt;&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/form&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;</p>
<p>The code is quite readable. On the click event of BtnLoadUserCtrl button, SampleUserCtrl.ascx user control is being tried to load in the &lt;div&gt; element having id UserCtrl.</p>
<p>Then, write our custom Httphandler called jQueryHandler as below.</p>
<p>public class jQueryHandler:IHttpHandler<br />
{<br />
public void ProcessRequest(HttpContext context)<br />
{<br />
// We add control in Page tree collection<br />
using(var dummyPage = new Page())<br />
{<br />
dummyPage.Controls.Add(GetControl(context));<br />
context.Server.Execute(dummyPage, context.Response.Output, true);<br />
}<br />
}</p>
<p>private Control GetControl(HttpContext context)<br />
{<br />
// URL path given by load(fn) method on click of button<br />
string strPath = context.Request.Url.LocalPath;<br />
UserControl userctrl = null;<br />
using(var dummyPage = new Page())<br />
{<br />
userctrl = dummyPage.LoadControl(strPath) as UserControl;<br />
}<br />
// Loaded user control is returned<br />
return userctrl;<br />
}</p>
<p>public bool IsReusable<br />
{<br />
get { return true; }<br />
}<br />
}</p>
<p>Do not miss to add this HttpHandler in the web.config.</p>
<p>&lt;httpHandlers&gt;<br />
&lt;add verb=&#8221;*&#8221; path=&#8221;*.ascx&#8221; type=&#8221;JQUserControl.jQueryHandler, JQUserControl&#8221;/&gt;<br />
&lt;/httpHandlers&gt;</p>
<p>This web.config configuration tells that jQueryHandler will process request for file type having .ascx extension and methods all (GET, POST, etc). The type attribute value is something like:<br />
type=”Namespace.TypeName, Assembly name where Handler can be found”</p>
<p>Now we are ready to test our sample. Run the page, and see on the click of button, the sampleusertCtrl.ascx is loaded.</p>
<p>I hope we can now extend this concept to fit any such programming requirement in future.<br />
Happy Coding!<a href="http://dineshmandal.wordpress.com/2009/10/10/load-asp-net-user-control-dynamically-using-jquery/" rel="tag" style="display:None;">CodeProject</a></p>
<br />Posted in .Net Technologies, ASP.Net, C#/VB.Net, CodeProject, Dot Net Tips, JavaScript/jQuery/JSON/Ajax Tagged: .Net3.5, ASP.Net, HttpHandler, jQuery, UserControl <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/170/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=170&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2009/10/10/load-asp-net-user-control-dynamically-using-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>
	</item>
		<item>
		<title>CacheItemRemovedCallback Example in ASP.Net</title>
		<link>http://dineshmandal.wordpress.com/2009/09/20/cacheitemremovedcallback-example-asp-dot-net/</link>
		<comments>http://dineshmandal.wordpress.com/2009/09/20/cacheitemremovedcallback-example-asp-dot-net/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 19:18:00 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Caching]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/2009/09/20/cacheitemremovedcallback-example-in-asp-net/</guid>
		<description><![CDATA[Notify When an Item is Removed from Cache in ASP.Net While adding or inserting an item into cache object, we add dependency object as well to ensure the cache is automatically invalidated if any change is detected in that dependent object like file, for example. Then, we again read or update that item from the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=168&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Notify When an Item is Removed from Cache in ASP.Net</strong></p>
<p align="justify">While adding or inserting an item into cache object, we add dependency object as well to ensure the cache is automatically invalidated if any change is detected in that dependent object like file, for example. Then, we again read or update that item from the original source to make sure the item is still fresh with data. This is one of the main reasons that really appeal the use of ASP.Net caching feature where one can decide about dependencies and expiry time policy. There are other properties also that can be used in combination to set the scope of cached object within time frame and location. See also <a href="http://msdn.microsoft.com/en-us/library/system.web.httpcacheability.aspx">HttpCacheability</a> .</p>
<p align="justify">But today we will explore the <a href="http://msdn.microsoft.com/en-us/library/system.web.caching.cacheitemremovedcallback.aspx" target="_blank">CacheItemRemovedCallback</a> delegate provided by ASP.Net. It is used to notify the application about cache removal or deletion with some reason. <a href="http://msdn.microsoft.com/en-us/library/system.web.caching.cacheitemremovedreason.aspx" target="_blank">CacheItemRemovedReason</a> enumeration is used as a parameter in call back method to tell the appropriate reason of removal.</p>
<p>Let’s take an example to know more about the CacheItemRemovedCallback delegate.</p>
<blockquote><p>protected void Page_Load(object sender, EventArgs e)      <br />{       <br />//Fetch item list from cache       <br />ArrayList cacheditems = CachedItemList();       <br />}</p>
<p>private static CacheItemRemovedCallback OnCachedItemRemoved = null;      <br />private ArrayList CachedItemList()       <br />{       <br />//       <br />OnCachedItemRemoved = new CacheItemRemovedCallback(this.CachedItemRemovedCallback);       <br />ArrayList cacheditems = HttpContext.Current.Cache.Get(&quot;CACHE_KEY&quot;) as ArrayList;       </p>
<p>// Found in cache      <br />if (cacheditems != null)       <br />{       <br />return cacheditems;       <br />}       <br />else       <br />{       <br />// Not found in cache       <br />cacheditems = ItemList();       <br />HttpContext.Current.Cache.Insert(&quot;CACHE_KEY&quot;, cacheditems, new System.Web.Caching.CacheDependency(Server.MapPath(&quot;~//CacheDependentFile.txt&quot;)), Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration, CacheItemPriority.Default, OnCachedItemRemoved);       </p>
<p>return cacheditems;      <br />}       <br />}</p>
<p>private void CachedItemRemovedCallback(string key, Object val, CacheItemRemovedReason reason)      <br />{       <br />//       <br />if (reason == CacheItemRemovedReason.DependencyChanged)       <br />{       <br />// Log the cache key name, reason and time details       <br />// when the cached object was removed from the cache</p>
<p>}       <br />}</p>
<p>private ArrayList ItemList()      <br />{       <br />//       <br />ArrayList lst = new ArrayList();       <br />lst.Add(&quot;First Item&quot;);       <br />lst.Add(&quot;Second Item&quot;);       <br />lst.Add(&quot;Third Item&quot;);       <br />lst.Add(&quot;Fourth Item&quot;);       <br />lst.Add(&quot;Fifth Item&quot;);       <br />return lst;       <br />}</p>
</blockquote>
<p>Let’s see carefully this call back method:</p>
<blockquote><p>private void CachedItemRemovedCallback(string key, Object val, CacheItemRemovedReason reason)      <br />{       <br />//</p>
<p>}</p>
</blockquote>
<p align="justify">The first parameter specifies the cache key name that we used to store an item (an ArrayList collection values). Second parameter is the object that we stored in the cache. The third parameter is an enumeration which has enum values like Removed, Expired, Underused, and DependencyChanged.</p>
<p align="justify">In the above example, if any change is made in CacheDependentFile.txt file, the call back method is automatically fired, and the reason captured will be DependencyChanged. Try and see.</p>
<p align="justify"><a href="http://blogs.msdn.com/tess/archive/2006/08/11/695268.aspx"><strong>Important Point</strong></a>: When using a CacheItemRemovedCallback make sure that you make the callback method (&quot;OnCachedItemRemoved &quot; in the sample above) a static method.</p>
<p align="justify">This feature can be used in many cases like logging the reason why any cached item was removed from the cache, and many others depending upon the scenario.</p>
<p><a style="display:none;" href="http://dineshmandal.wordpress.com/2009/09/20/cacheitemremovedcallback-example-asp-dot-net/" rel="tag">CodeProject</a></p>
<br />Posted in .Net Technologies, ASP.Net, C#/VB.Net, CodeProject, Dot Net Tips Tagged: .Net3.5, ASP.Net, C#, Caching <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/168/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/168/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/168/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=168&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2009/09/20/cacheitemremovedcallback-example-asp-dot-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>
	</item>
		<item>
		<title>Using DebuggerDisplayAttribute</title>
		<link>http://dineshmandal.wordpress.com/2009/08/23/using-debuggerdisplayattribute/</link>
		<comments>http://dineshmandal.wordpress.com/2009/08/23/using-debuggerdisplayattribute/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 07:38:15 +0000</pubDate>
		<dc:creator>Dinesh K Mandal</dc:creator>
				<category><![CDATA[.Net Technologies]]></category>
		<category><![CDATA[C#/VB.Net]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[Dot Net Tips]]></category>
		<category><![CDATA[.Net3.5]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Debugging]]></category>

		<guid isPermaLink="false">http://dineshmandal.wordpress.com/2009/08/23/using-debuggerdisplayattribute/</guid>
		<description><![CDATA[In .Net, we can view variables contents in different ways like local window, quick watch, etc. In System.Diagnostics namespace, we can see a DebuggerDisplayAttribute class that is used to view variables’ contents in debugger window. This attribute can be applied to class, field, property, enum, delegate, struct, etc.  Using this attribute, we can easily view [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=159&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In .Net, we can view variables contents in different ways like local window, quick watch, etc. In System.Diagnostics namespace, we can see a DebuggerDisplayAttribute class that is used to view variables’ contents in debugger window. This attribute can be applied to class, field, property, enum, delegate, struct, etc.  Using this attribute, we can easily view variable contents in debug mode, and those contents are easily visible as data tip when we move mouse pointer over that variable. This attribute becomes quite useful when we have to view inner contents of custom type object variable when it has collection of values.</p>
<p>For example, we will apply this attribute to a class and watch the collection values in debug window.</p>
<p>[DebuggerDisplay("Client Name = {CustomerName} Client Type = {CustomerType, nq}")]<br />
class Customer<br />
{<br />
private string _CustomerName;<br />
private string _CustomerType;<br />
public Customer(string strCustomerName, string strCustomerType)<br />
{<br />
_CustomerName = strCustomerName;<br />
_CustomerType = strCustomerType;<br />
}<br />
public string CustomerName<br />
{<br />
get { return _CustomerName; }<br />
}<br />
public string CustomerType<br />
{<br />
get { return _CustomerType; }<br />
}<br />
}<br />
Now after loading a Customer type collection, we see following view in data tip:<br />
<img style="display:inline;" title="DebuggerDisplayAttribute" src="http://dineshmandal.files.wordpress.com/2009/08/debuggerdisplayattribute4.jpg?w=572&#038;h=208" alt="DebuggerDisplayAttribute" width="572" height="208" /></p>
<p>Fig 1: DebuggerDisplayAttribute changing the data view.<br />
Had not we used DebuggerDisplayAttribute on Customer class type, we would have to traverse a long hierarchy of tree view of each index value of collection object to view data contents.</p>
<p>Programmers often override ToString() method in the custom class type method to view data. But still DebuggerDisplayAttribute wins the heart!</p>
<p>When ToString() method is overridden inside Customer class, then ToString() method of Customer object will result as:</p>
<p>public new string ToString()<br />
{<br />
return (&#8220;Customer Name: &#8221; + _CustomerName + &#8220;\n&#8221; + &#8220;Customer Type: &#8221; + _CustomerType);<br />
}<br />
<img style="display:inline;" title="ToString Method" src="http://dineshmandal.files.wordpress.com/2009/08/tostringmethod.jpg?w=516&#038;h=163" alt="ToString Method" width="516" height="163" /><br />
Fig 2: Result of overridden ToString() method.</p>
<p>DebuggerDisplayAttribute constructor has only one parameter as string. The {} braces contain field or property or method name. In the example above, we have used this way.</p>
<p>[DebuggerDisplay("Client Name = {CustomerName} Client Type = {CustomerType, nq}")]</p>
<p>One can also quickly see {CustomerType, nq}. Due to this “nq” specifier, Client Type value is shown without double quotes, whereas Client Name value is still in double quote (see Fig 1). The “nq” specifier is used for string type properties.</p>
<p>Happy debugging for next time!</p>
<p><a style="display:None;" rel="tag" href="http://dineshmandal.wordpress.com/2009/08/23/using-debuggerdisplayattribute/">CodeProject</a></p>
<br />Posted in .Net Technologies, C#/VB.Net, CodeProject, Dot Net Tips Tagged: .Net3.5, C#, Debugging <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dineshmandal.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dineshmandal.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dineshmandal.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dineshmandal.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dineshmandal.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dineshmandal.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dineshmandal.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dineshmandal.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dineshmandal.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dineshmandal.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dineshmandal.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dineshmandal.wordpress.com/159/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dineshmandal.wordpress.com/159/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dineshmandal.wordpress.com/159/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dineshmandal.wordpress.com&amp;blog=7825771&amp;post=159&amp;subd=dineshmandal&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dineshmandal.wordpress.com/2009/08/23/using-debuggerdisplayattribute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>0.000000 0.000000</georss:point>
		<geo:lat>0.000000</geo:lat>
		<geo:long>0.000000</geo:long>
		<media:content url="http://1.gravatar.com/avatar/f6da0f7ab015b5f704d6301ca27b7bcf?s=96&#38;d=wavatar&#38;r=G" medium="image">
			<media:title type="html">Dinesh K Mandal</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2009/08/debuggerdisplayattribute4.jpg" medium="image">
			<media:title type="html">DebuggerDisplayAttribute</media:title>
		</media:content>

		<media:content url="http://dineshmandal.files.wordpress.com/2009/08/tostringmethod.jpg" medium="image">
			<media:title type="html">ToString Method</media:title>
		</media:content>
	</item>
	</channel>
</rss>
