<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Prasanna's Blog</title>
        <link>http://geekswithblogs.net/BizG/Default.aspx</link>
        <description>BizTalk, WCF, C# and Software Factories</description>
        <language>en-US</language>
        <copyright>Prasanna Krishnan</copyright>
        <managingEditor>lionkrish@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Prasanna's Blog</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/BizG/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>WCF features/improvements in .NET 3.5 SP1 and VS 2008 SP1</title>
            <category>BizTalk, WCF, Design Patterns, C#, Software Factories</category>
            <link>http://geekswithblogs.net/BizG/archive/2008/07/09/wcf-featuresimprovements-in-.net-3.5-sp1-and-vs-2008-sp1.aspx</link>
            <description>&lt;p&gt;Here are the new improvements in WCF in .Net 3.5 and VS 2008 SP1&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;a href="http://www.pluralsight.com/community/blogs/aaron/archive/2008/05/12/50909.aspx"&gt;http://www.pluralsight.com/community/blogs/aaron/archive/2008/05/12/50909.aspx&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Ta,&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=123679"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=123679" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/123679.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/07/09/wcf-featuresimprovements-in-.net-3.5-sp1-and-vs-2008-sp1.aspx</guid>
            <pubDate>Wed, 09 Jul 2008 16:56:43 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/123679.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/07/09/wcf-featuresimprovements-in-.net-3.5-sp1-and-vs-2008-sp1.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/123679.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/123679.aspx</trackback:ping>
        </item>
        <item>
            <title>Strategy Pattern</title>
            <category>C#</category>
            <category>Design Patterns</category>
            <category>general</category>
            <link>http://geekswithblogs.net/BizG/archive/2008/03/19/strategy-pattern.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;The strategy pattern is typically used when your programmer's algorithm should be interchangeable with different variations of the algorithm. For example, if you have code that sorts array, under certain circumstances, you might want to create QuickSort and under other circumstances, you might want to create Merge Sort.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;The strategy pattern is usually implemented by declaring an abstract base class with an algorithm method, which is then implemented by inheriting concrete classes. At some point in the code, it is decided what concrete strategy is relevant; it would then be instantiated and used wherever relevant.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Following example shows how a ArrayList with diffrent sort algorithms. &lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
&lt;p&gt;&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections;&lt;br /&gt;
using NUnit.Framework;&lt;/p&gt;
&lt;p&gt;namespace DesignPatterns&lt;br /&gt;
{&lt;br /&gt;
    // Strategy class: SortStrategy&lt;br /&gt;
    // Define the general interface common to all supported algorithms&lt;br /&gt;
    public abstract class SortStrategy&lt;br /&gt;
    {&lt;br /&gt;
        public abstract void Sort(ArrayList list);&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    // Concrete class QuickSort&lt;br /&gt;
    public class QuickSort : SortStrategy&lt;br /&gt;
    {&lt;br /&gt;
        public override void Sort(ArrayList list)&lt;br /&gt;
        {&lt;br /&gt;
            // Sort the list using a quicksort algorithm&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    // Concrete class MergeSort&lt;br /&gt;
    public class MergeSort : SortStrategy&lt;br /&gt;
    {&lt;br /&gt;
        public override void Sort(ArrayList list)&lt;br /&gt;
        {&lt;br /&gt;
            // Sort the list using a mergesort algorithm&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    // Context class&lt;br /&gt;
    public class SortedList&lt;br /&gt;
    {&lt;br /&gt;
        private ArrayList list = new ArrayList();&lt;br /&gt;
        private SortStrategy sortstrategy;&lt;/p&gt;
&lt;p&gt; public SortedList(SortStrategy sortstrategy)&lt;br /&gt;
        {&lt;br /&gt;
            this.sortstrategy = sortstrategy;)&lt;br /&gt;
   &lt;br /&gt;
 }&lt;br /&gt;
        &lt;br /&gt;
        public void Add(string name)&lt;br /&gt;
        {&lt;br /&gt;
            list.Add(name);&lt;br /&gt;
        }&lt;/p&gt;
&lt;p&gt;        public void Sort()&lt;br /&gt;
        {&lt;br /&gt;
            sortstrategy.Sort(list);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    [TestFixture]&lt;br /&gt;
    public class StrategyClassTestFixture&lt;br /&gt;
    {&lt;br /&gt;
        [Test]&lt;br /&gt;
        public void TestSortedList()&lt;br /&gt;
        {&lt;br /&gt;
            SortedList sortedList = new SortedList(new QuickSort());&lt;/p&gt;
&lt;p&gt;            sortedList.Add("mitchel");&lt;br /&gt;
            sortedList.Add("gregg");&lt;br /&gt;
            sortedList.Add("steve");&lt;br /&gt;
            sortedList.Add("rob");&lt;/p&gt;
&lt;p&gt;        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120648"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120648" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/120648.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/03/19/strategy-pattern.aspx</guid>
            <pubDate>Thu, 20 Mar 2008 01:27:28 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/120648.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/03/19/strategy-pattern.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/120648.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/120648.aspx</trackback:ping>
        </item>
        <item>
            <title>Contravariance and generics</title>
            <category>BizTalk, WCF, Design Patterns, C#, Software Factories</category>
            <category>C#</category>
            <category>Design Patterns</category>
            <category>general</category>
            <link>http://geekswithblogs.net/BizG/archive/2008/03/19/contravariance-and-generics.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;since i have already posted basic ContraVariance in delegate, i am not going to go thru the same again, those of you who had missed my earlier post can refer &lt;a href="http://geekswithblogs.net/BizG/archive/2008/02/25/covariance-and-contravariance-in-delegate.aspx"&gt;here&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;here is an example of using generics with contravariance&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;namespace ContravarianceWithGenerics&lt;br /&gt;
{&lt;br /&gt;
    public interface IEquity&lt;br /&gt;
    {&lt;br /&gt;
        string ToString();&lt;br /&gt;
        string Save();&lt;br /&gt;
    }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;    //base class&lt;br /&gt;
    abstract class Equity : IEquity&lt;br /&gt;
    {&lt;br /&gt;
        int _price;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        public Equity(int Price)&lt;br /&gt;
        {&lt;br /&gt;
            _price = Price;&lt;br /&gt;
        }&lt;br /&gt;
        public override string ToString()&lt;br /&gt;
        {&lt;br /&gt;
            return GetType().Name + " : " + _price;&lt;br /&gt;
        }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        #region IEquity Members&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
&lt;p&gt;&lt;br /&gt;
        public virtual string Save()&lt;br /&gt;
        {&lt;br /&gt;
            return "Called from Base Class";&lt;br /&gt;
        }&lt;/p&gt;
&lt;p&gt;        #endregion&lt;br /&gt;
    }&lt;br /&gt;
    //derived&lt;br /&gt;
    class Stock : Equity&lt;br /&gt;
    {&lt;br /&gt;
        public Stock(int Price)&lt;br /&gt;
            : base(Price)&lt;br /&gt;
        {&lt;/p&gt;
&lt;p&gt;        }&lt;/p&gt;
&lt;p&gt;        public override string Save()&lt;br /&gt;
        {&lt;br /&gt;
            return "Called from Stock Class";&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    //derived&lt;br /&gt;
    class Bond : Equity&lt;br /&gt;
    {&lt;br /&gt;
        public Bond(int Price)&lt;br /&gt;
            : base(Price)&lt;br /&gt;
        {&lt;/p&gt;
&lt;p&gt;        }&lt;/p&gt;
&lt;p&gt;        public override string Save()&lt;br /&gt;
        {&lt;br /&gt;
            return "Called from Bond Class";&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    class EquityBusinessImplementation&amp;lt;T&amp;gt; where T: Equity, IEquity&lt;br /&gt;
    {&lt;br /&gt;
        public delegate void SellNotify(T b);&lt;/p&gt;
&lt;p&gt;        public void EquitySaleReport(Equity e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine("Report of sale is " + e);&lt;br /&gt;
            Console.WriteLine(e.Save() );&lt;br /&gt;
        }&lt;br /&gt;
        public SellNotify sellNotifyDlg;&lt;/p&gt;
&lt;p&gt;        public void Sell(T s)&lt;br /&gt;
        {&lt;br /&gt;
            if (null != sellNotifyDlg)&lt;br /&gt;
            {&lt;br /&gt;
                sellNotifyDlg(s);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/p&gt;
&lt;p&gt;    class Program&lt;br /&gt;
    {&lt;br /&gt;
        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            EquityBusinessImplementation&amp;lt;Stock&amp;gt; s = &lt;br /&gt;
                new EquityBusinessImplementation&amp;lt;Stock&amp;gt;(); &lt;br /&gt;
            s.sellNotifyDlg += s.EquitySaleReport;&lt;br /&gt;
            s.Sell(new Stock(100));&lt;/p&gt;
&lt;p&gt;            EquityBusinessImplementation&amp;lt;Bond&amp;gt; b = &lt;br /&gt;
                new EquityBusinessImplementation&amp;lt;Bond&amp;gt;();&lt;br /&gt;
            b.sellNotifyDlg += b.EquitySaleReport;&lt;br /&gt;
            b.Sell(new Bond(1000));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;Happy programming !!!&lt;/p&gt;
&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120645"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120645" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/120645.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/03/19/contravariance-and-generics.aspx</guid>
            <pubDate>Wed, 19 Mar 2008 23:45:56 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/120645.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/03/19/contravariance-and-generics.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/120645.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/120645.aspx</trackback:ping>
        </item>
        <item>
            <title>Generics &amp; Inheritance</title>
            <category>BizTalk, WCF, Design Patterns, C#, Software Factories</category>
            <category>C#</category>
            <category>general</category>
            <link>http://geekswithblogs.net/BizG/archive/2008/03/13/generics--inheritance.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;A generic class that uses parameterized types, like MyBase&amp;lt;T&amp;gt;, is called an open-constructed generic. A generic class that uses no parameterized types, like MyBase&amp;lt;int&amp;gt;, is called a closed-constructed generic.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;You may derive from a closed-constructed generic; that is, you may inherit a class named MyDerived from another class named MyBase, as in:&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
&lt;p&gt;&lt;br /&gt;
&lt;font color="#0000ff"&gt;public class MyDerived&amp;lt;T&amp;gt; : MyBase1&amp;lt;int&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;You may derive from an open-constructed generic, provided the type is parameterized. &lt;/p&gt;
&lt;p&gt;For example: &lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff"&gt;public class MyDerived&amp;lt;T&amp;gt; : MyBase&amp;lt;T&amp;gt;&lt;/font&gt; is valid, but&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;font color="#ff0000"&gt;public class MyDerived&amp;lt;T&amp;gt; : MyBase&amp;lt;Y&amp;gt;&lt;/font&gt; is not valid since Y is also a parameterized type. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Non-generic classes may derive from closed-constructed generic classes, but not from open-constructed generic classes. That is, &lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff"&gt;public class MyDerived : MyBase&amp;lt;int&amp;gt;&lt;/font&gt; is valid, but&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;font color="#ff0000"&gt;public class MyDerived : MyBase&amp;lt;T&amp;gt;&lt;/font&gt; is not valid.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;-------&lt;/p&gt;
&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120511"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120511" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/120511.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/03/13/generics--inheritance.aspx</guid>
            <pubDate>Thu, 13 Mar 2008 17:49:46 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/120511.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/03/13/generics--inheritance.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/120511.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/120511.aspx</trackback:ping>
        </item>
        <item>
            <title>Constraints in generic and Their Benefits</title>
            <category>BizTalk, WCF, Design Patterns, C#, Software Factories</category>
            <category>C#</category>
            <category>general</category>
            <link>http://geekswithblogs.net/BizG/archive/2008/03/13/constraints-in-generic-and-their-benefits.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;A generic class allows you to write your class without committing to any type, yet allows the user of your class, later on, to indicate the specific type to be used. While this gives greater flexibility by placing some constraints on the types that may be used for the parameterized type, you gain some control in writing your class. Let's look at an example:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Example 1. The need for constraints: code that will not compile&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
&lt;p&gt;&lt;br /&gt;
public static T Max&amp;lt;T&amp;gt;(T op1, T op2) &lt;br /&gt;
{&lt;br /&gt;
        if (op1.CompareTo(op2) &amp;lt; 0)&lt;br /&gt;
                return op1;&lt;br /&gt;
        return op2;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;&lt;font style="BACKGROUND-COLOR: #c0c0c0"&gt;&lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff"&gt;&lt;em&gt;The code in Example 1 will produce a compilation error:&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff"&gt;&lt;em&gt;Error 1 'T' does not contain a definition for 'CompareTo'&lt;br /&gt;
&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Assume I need the type to support the CompareTo() method. I can specify this by using the constraint that the type specified for the parameterized type must implement the IComparable interface. Example 2 has the code:&lt;/p&gt;
&lt;p&gt;Example 2. Specifying a constraint&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
public static T Max&amp;lt;T&amp;gt;(T op1, T op2) where T : IComparable&lt;br /&gt;
{&lt;br /&gt;
        if (op1.CompareTo(op2) &amp;lt; 0)&lt;br /&gt;
                return op1;&lt;br /&gt;
        return op2;&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;In Example 2, I have specified the constraint that the type used for parameterized type must inherit from (implement) IComparable. The following are some of the other constraints may be used:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;font color="#0000ff"&gt;where T : struct                   type must be a value type (a struct)&lt;br /&gt;
where T : class                   type must be reference type (a class)&lt;br /&gt;
where T : new()                  type must have a no-parameter constructor&lt;br /&gt;
where T : class_name      type may be either class_name or one of its&lt;br /&gt;
                                              sub-classes (or is below class_name &lt;br /&gt;
                                              in the inheritance hierarchy)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;where T : interface_name  type must implement the specified interface&lt;br /&gt;
You may specify a combination of constraints, as in: where T : IComparable, new(). This says that the type for the parameterized type must implement the IComparable interface and must have a no-parameter constructor.&lt;/p&gt;
&lt;p&gt;------&lt;br /&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120509"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=120509" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/120509.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/03/13/constraints-in-generic-and-their-benefits.aspx</guid>
            <pubDate>Thu, 13 Mar 2008 17:25:07 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/120509.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/03/13/constraints-in-generic-and-their-benefits.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/120509.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/120509.aspx</trackback:ping>
        </item>
        <item>
            <title>Delegate inference</title>
            <category>C#</category>
            <category>general</category>
            <link>http://geekswithblogs.net/BizG/archive/2008/02/26/delegate-inference.aspx</link>
            <description>&lt;p&gt;&lt;font face="Arial"&gt;Delegate inference allows you to make a direct assignment of a method name to a &lt;br /&gt;
delegate variable, without wrapping it first with a delegate object.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;The oldwayclass shows implementation in C# 1.1&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;class OldWayClass&lt;br /&gt;
{&lt;br /&gt;
   delegate void notifyDelegate();&lt;br /&gt;
   public void InvokeMethod()&lt;br /&gt;
   {&lt;br /&gt;
      notifyDelegate del = new notifyDelegate(SomeMethod);&lt;br /&gt;
      del();&lt;br /&gt;
   }&lt;br /&gt;
   void SomeMethod()&lt;br /&gt;
   {...}&lt;br /&gt;
}&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;
&lt;p&gt;&lt;br /&gt;
and the NewWayClass is the sample implementation in C# 2.0&lt;/p&gt;
&lt;p&gt;class NewWayClass&lt;br /&gt;
{&lt;br /&gt;
   delegate void notifyDelegate();&lt;br /&gt;
   public void InvokeMethod()&lt;br /&gt;
   {&lt;br /&gt;
      &lt;font color="#008080"&gt;notifyDelegate del = SomeMethod;&lt;br /&gt;
&lt;/font&gt;      del();&lt;br /&gt;
   }&lt;br /&gt;
   void SomeMethod()&lt;br /&gt;
   {...}&lt;br /&gt;
}&lt;/p&gt;
&lt;p&gt;When you assign a method name to a delegate, the compiler first infers the delegate's type. Then the compiler verifies that there is a method by that name and that its signature matches that of the inferred delegate type. Finally, the compiler creates a new object of the inferred delegate type, wrapping the method and assigning it to the delegate. The compiler can only infer the delegate type if that type is a specific delegate type—that is, anything other than the abstract type Delegate. Delegate inference is a very useful feature indeed, resulting in concise, elegant code.&lt;/p&gt;
&lt;/font&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119971"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119971" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/119971.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/02/26/delegate-inference.aspx</guid>
            <pubDate>Tue, 26 Feb 2008 14:01:23 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/119971.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/02/26/delegate-inference.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/119971.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/119971.aspx</trackback:ping>
        </item>
        <item>
            <title>Covariance and contravariance in delegate</title>
            <category>BizTalk, WCF, Design Patterns, C#, Software Factories</category>
            <category>C#</category>
            <category>general</category>
            <link>http://geekswithblogs.net/BizG/archive/2008/02/25/covariance-and-contravariance-in-delegate.aspx</link>
            <description>&lt;p&gt;&lt;span class="term"&gt;Covariance&lt;/span&gt; and &lt;span class="term"&gt;contravariance&lt;/span&gt; provide a degree of flexibility when you match method signatures with delegate types. Covariance permits a method to have a more derived return type than what is defined in the delegate. Contravariance permits a method with parameter types that are less derived than in the delegate type.&lt;/p&gt;
&lt;p&gt;&lt;span class="term"&gt;contravariance&lt;/span&gt; example:&lt;/p&gt;
&lt;p&gt;This example demonstrates how delegates can be used with methods that have parameters of a type that are base types of the delegate signature parameter type. With contravariance, you can now use one handler in places where, previously, you would have had to use separate handlers. For example&lt;font size="2"&gt; both sellNotifyDlg and sellBondNotify delegates are using the same handler - EquitySaleReport since both stock and bond derive from Equity base class&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;namespace ContraVariance&lt;br /&gt;
{&lt;br /&gt;
    //base class&lt;br /&gt;
    class Equity&lt;br /&gt;
    {&lt;br /&gt;
        int _price;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        public Equity(int Price)&lt;br /&gt;
        {&lt;br /&gt;
            _price = Price;&lt;br /&gt;
        }&lt;br /&gt;
        public override string ToString()&lt;br /&gt;
        {&lt;br /&gt;
            return GetType().Name + " : " + _price;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
    //derived&lt;br /&gt;
    class Stock : Equity&lt;br /&gt;
    {&lt;br /&gt;
        public Stock(int Price)&lt;br /&gt;
            : base(Price)&lt;br /&gt;
        {&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        }&lt;br /&gt;
    }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;    //derived&lt;br /&gt;
    class Bond : Equity&lt;br /&gt;
    {&lt;br /&gt;
        public Bond(int Price)&lt;br /&gt;
            : base(Price)&lt;br /&gt;
        {&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        }&lt;br /&gt;
    }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;    class Program&lt;br /&gt;
    {&lt;br /&gt;
        delegate void StockSellNotify(Stock s);&lt;br /&gt;
        delegate void BondSellNotify(Bond b);&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        static void EquitySaleReport(Equity e)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine("Report of sale is " + e);&lt;br /&gt;
        }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        static StockSellNotify sellNotifyDlg;&lt;br /&gt;
        static BondSellNotify sellBondNotify;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        static void Sell(Stock s)&lt;br /&gt;
        {&lt;br /&gt;
            if (null != sellNotifyDlg)&lt;br /&gt;
            {&lt;br /&gt;
                sellNotifyDlg(s);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        //overload &lt;br /&gt;
        static void Sell(Bond  b)&lt;br /&gt;
        {&lt;br /&gt;
            if (null != sellBondNotify)&lt;br /&gt;
            {&lt;br /&gt;
                sellBondNotify(b);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
       &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        static void Main(string[] args)&lt;br /&gt;
        {&lt;br /&gt;
            sellNotifyDlg += EquitySaleReport;&lt;br /&gt;
            Sell(new Stock(100));&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;            sellBondNotify += EquitySaleReport;&lt;br /&gt;
            Sell(new Bond(101));&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;            //both sellNotifyDlg and sellBondNotify are using the same handler - EquitySaleReport&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;            &lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;In my next post i will put a sample for Covariance and try to refine the contravariance sample with generics ...&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Happy programming !!!&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119959"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119959" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/119959.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/02/25/covariance-and-contravariance-in-delegate.aspx</guid>
            <pubDate>Tue, 26 Feb 2008 01:45:38 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/119959.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/02/25/covariance-and-contravariance-in-delegate.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/119959.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/119959.aspx</trackback:ping>
        </item>
        <item>
            <title>Generic Proxy for WCF services</title>
            <category>BizTalk, WCF, Design Patterns, C#, Software Factories</category>
            <category>Design Patterns</category>
            <category>Software Factories</category>
            <category>general</category>
            <link>http://geekswithblogs.net/BizG/archive/2008/02/23/generic-proxy-for-wcf-services.aspx</link>
            <description>&lt;p&gt;&lt;font size="3"&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;When we generate (WCF) service proxy class for a service by using &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;svcutil.exe&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;, it creates a proxy that derives from &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;System.ServiceModel.ClientBase&amp;lt;TChannel&amp;gt;&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;. The proxy implements &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;IDisposable&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt; and the client code can be wraped inside &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;using&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt; statement and guaranteed clean-up in the face of exceptions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="3"&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;However, the &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;System.ServiceModel.ClientBase&amp;lt;TChannel&amp;gt;&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt; class can throw exceptions from its &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;Dispose&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt; method, because it internally invokes &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;Close()&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt; method which might lead t0 a faulted state. In that case you have to call &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;Abort&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt; for clean-up. Most times you are not interested in knowing whether the Dispose fails or not and you just want to have guaranteed clean up of any resources held by the proxy. &lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman" size="3"&gt;Check out &lt;/font&gt;&lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=855018&amp;amp;SiteID=1"&gt;&lt;font face="Times New Roman" size="3"&gt;this discussion on the WCF forum&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt; for why Microsoft implemented the dispose in this way.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="3"&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;To prevent you from writing a lot of code to accomplish this clean-up, I have written a generic &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;GenericServiceProxyAgent &lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;class that does it for you. &lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="3"&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;The idea is that you derive a class from my &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;GenericServiceProxyAgent&amp;lt;TProxy, TChannel&amp;gt;&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt; class. Insert your proxy class (that should derive from &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;ClientBase&amp;lt;TChannel&amp;gt;&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;) name for &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;TProxy&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;, and the service interface name for &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;TChannel&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt;. The helper class wraps the proxy and doesn't directly expose its methods. From your derived class you can use the protected &lt;/font&gt;&lt;/span&gt;&lt;span lang="EN" style="FONT-FAMILY: 'Courier New'; mso-ansi-language: EN"&gt;Proxy&lt;/span&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font face="Times New Roman"&gt; property to get access to the service proxy. You should add methods to your derived class that delegate to the proxy. &lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;span lang="EN" style="mso-ansi-language: EN"&gt;&lt;font size="3"&gt;&lt;font face="Times New Roman"&gt;Create a convenience method to the derived helper that create request messages and unpack response messages. So our helper methods have a different signature than the methods on the proxy class itself.&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span lang="EN-GB"&gt;&lt;o:p&gt;&lt;font face="Times New Roman" size="3"&gt;here is the code snippet.&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span lang="EN-GB"&gt;&lt;o:p&gt;&lt;font face="Times New Roman" size="3"&gt;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/p&gt;
&lt;span lang="EN-GB"&gt;&lt;o:p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt; &lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;font face="Arial"&gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.ServiceModel;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;namespace xxx.Net.Services&lt;br /&gt;
{&lt;br /&gt;
    /// &amp;lt;summary&amp;gt;&lt;br /&gt;
    /// Generic proxy class for a WCF services.&lt;br /&gt;
    /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
    /// &amp;lt;typeparam name="TProxy"&amp;gt;The type of WCF service proxy to wrap.&amp;lt;/typeparam&amp;gt;&lt;br /&gt;
    /// &amp;lt;typeparam name="TChannel"&amp;gt;The type of WCF service interface to wrap.&amp;lt;/typeparam&amp;gt;&lt;br /&gt;
    public class GenericServiceProxyAgent&amp;lt;TProxy, TChannel&amp;gt; : IDisposable&lt;br /&gt;
        where TProxy : ClientBase&amp;lt;TChannel&amp;gt;, new()&lt;br /&gt;
        where TChannel : class&lt;br /&gt;
    {&lt;br /&gt;
        /// &amp;lt;summary&amp;gt;&lt;br /&gt;
        /// variable to hold proxy instance&lt;br /&gt;
        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
        private TProxy _proxy;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;
        /// Gets the WCF service proxy wrapped by this instance.&lt;br /&gt;
        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
        protected TProxy Proxy&lt;br /&gt;
        {&lt;br /&gt;
            get&lt;br /&gt;
            {&lt;br /&gt;
                if (_proxy != null)&lt;br /&gt;
                {&lt;br /&gt;
                    return _proxy;&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    throw new ObjectDisposedException("GenericServiceProxyAgent");&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;
        /// default constructor.&lt;br /&gt;
        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
        protected GenericServiceProxyAgent()&lt;br /&gt;
        {&lt;br /&gt;
            _proxy = new TProxy();&lt;br /&gt;
        }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;        /// &amp;lt;summary&amp;gt;&lt;br /&gt;
        /// Disposes the current instance.&lt;br /&gt;
        /// &amp;lt;/summary&amp;gt;&lt;br /&gt;
        public void Dispose()&lt;br /&gt;
        {&lt;br /&gt;
            try&lt;br /&gt;
            {&lt;br /&gt;
                if (_proxy != null)&lt;br /&gt;
                {&lt;br /&gt;
                    if (_proxy.State != CommunicationState.Faulted)&lt;br /&gt;
                    {&lt;br /&gt;
                        _proxy.Close();&lt;br /&gt;
                    }&lt;br /&gt;
                    else&lt;br /&gt;
                    {&lt;br /&gt;
                        _proxy.Abort();&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
     catch (FaultException unknownFault)&lt;br /&gt;
     {&lt;br /&gt;
       System.Diagnostics.Debug.WriteLine("An unknown exception was received. " + unknownFault.Message);&lt;br /&gt;
       _proxy.Abort();&lt;br /&gt;
     }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;            catch (CommunicationException)&lt;br /&gt;
            {&lt;br /&gt;
  System.Diagnostics.Debug.WriteLine("Service proxy encountred a communication exception and aborted");&lt;br /&gt;
                _proxy.Abort();&lt;br /&gt;
            }&lt;br /&gt;
            catch (TimeoutException)&lt;br /&gt;
            {&lt;br /&gt;
  System.Diagnostics.Debug.WriteLine("Service proxy encountred a timeout exception and aborted");&lt;br /&gt;
                _proxy.Abort();&lt;br /&gt;
            }&lt;br /&gt;
            catch (Exception)&lt;br /&gt;
            {&lt;br /&gt;
  System.Diagnostics.Debug.WriteLine("Service proxy encountred a unknown exception and aborted");&lt;br /&gt;
                _proxy.Abort();&lt;br /&gt;
                throw;&lt;br /&gt;
            }&lt;br /&gt;
            finally&lt;br /&gt;
            {&lt;br /&gt;
                _proxy = null;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;/font&gt; &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p class="MsoNormal" style="MARGIN: 0in 0in 0pt"&gt;&lt;span lang="EN-GB"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font color="#0000ff"&gt;Note: Always check the "CommunicationState" before invoking any method on them, this is certainly an additional line of code but certainly a best practise&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Happy programming !!!&lt;/p&gt;
&lt;/o:p&gt;&lt;/span&gt; &lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119916"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119916" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/119916.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/02/23/generic-proxy-for-wcf-services.aspx</guid>
            <pubDate>Sat, 23 Feb 2008 18:14:47 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/119916.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/02/23/generic-proxy-for-wcf-services.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/119916.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/119916.aspx</trackback:ping>
        </item>
        <item>
            <title>Socket errors in WCF netTcpBinding</title>
            <link>http://geekswithblogs.net/BizG/archive/2008/02/22/socket-errors-in-wcf-nettcpbinding.aspx</link>
            <description>&lt;p&gt;i just finished writing Windows service host for my WCF services, there were no crash or exceptions thrown either by client or server, &lt;/p&gt;
&lt;p&gt;I was just browing event log to check things were fine, then noticed at end of each call to WCF service, there was a log message with the following exception&lt;/p&gt;
&lt;p&gt;&lt;font color="#ff0000"&gt;System.ServiceModel.CommunicationException occurred&lt;br /&gt;
  Message="The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:02:00'."&lt;br /&gt;
  Source="System.ServiceModel"&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;ok here is the solution: when using netTcpBinding the service client has to call the &lt;strong&gt;&lt;font color="#003300" size="3"&gt;close() method &lt;/font&gt;&lt;/strong&gt;of the service in order to relase the instance back to the pool&lt;/p&gt;
&lt;p&gt;Agile way to fix this is by change the binding type to WSHttp or BasicHttp. it will work &lt;img alt="" src="/Providers/BlogEntryEditor/FCKeditor/editor/images/smiley/msn/wink_smile.gif" /&gt;&lt;/p&gt;
&lt;p&gt;Happy Programing !!!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119893"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119893" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/119893.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/02/22/socket-errors-in-wcf-nettcpbinding.aspx</guid>
            <pubDate>Fri, 22 Feb 2008 20:10:20 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/119893.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/02/22/socket-errors-in-wcf-nettcpbinding.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/119893.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/119893.aspx</trackback:ping>
        </item>
        <item>
            <title>Static Class in Dotnet</title>
            <link>http://geekswithblogs.net/BizG/archive/2008/02/05/static-class-in-dotnet.aspx</link>
            <description>&lt;p&gt;I guess most of us know what a static class is, you can't instiantiate, cannot have any instancing members etc.&lt;/p&gt;
&lt;p&gt;This might sound funny but the truth is Static class are &lt;font color="#003300" size="3"&gt;"Abstract and Sealed",&lt;/font&gt; never understood why ?&lt;/p&gt;
&lt;p&gt;If you dont agree with me, use reflector or ILDASM and view your static Class .&lt;/p&gt;
&lt;p&gt;Happy Programming !!!&lt;/p&gt;
&lt;p&gt;----&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119295"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=119295" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BizG/aggbug/119295.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Prasanna Krishnan</dc:creator>
            <guid>http://geekswithblogs.net/BizG/archive/2008/02/05/static-class-in-dotnet.aspx</guid>
            <pubDate>Tue, 05 Feb 2008 14:53:53 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BizG/comments/119295.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BizG/archive/2008/02/05/static-class-in-dotnet.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/BizG/comments/commentRss/119295.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/BizG/services/trackbacks/119295.aspx</trackback:ping>
        </item>
    </channel>
</rss>