<?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>Sanjay&#039;s Blog</title>
	<atom:link href="http://dotnettrick.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://dotnettrick.wordpress.com</link>
	<description>.Net Tricks and kicks</description>
	<lastBuildDate>Fri, 18 Dec 2009 17:50:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='dotnettrick.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Sanjay&#039;s Blog</title>
		<link>http://dotnettrick.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://dotnettrick.wordpress.com/osd.xml" title="Sanjay&#039;s Blog" />
	<atom:link rel='hub' href='http://dotnettrick.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The power trick of the Cross Join</title>
		<link>http://dotnettrick.wordpress.com/2009/12/19/the-power-trick-of-the-cross-join/</link>
		<comments>http://dotnettrick.wordpress.com/2009/12/19/the-power-trick-of-the-cross-join/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 17:49:29 +0000</pubDate>
		<dc:creator>letter2sanjay1</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Cross joins]]></category>
		<category><![CDATA[Joins]]></category>

		<guid isPermaLink="false">http://dotnettrick.wordpress.com/2009/12/19/the-power-trick-of-the-cross-join/</guid>
		<description><![CDATA[Many SQL books and tutorials recommend that you “avoid cross joins” or “beware of Cartesian products” when writing your SELECT statements, which occur when you don&#8217;t express joins between your tables.  It’s true that you need to ensure that your join conditions are adequately stated so that you don’t accidentally produce this effect, but it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnettrick.wordpress.com&amp;blog=10970746&amp;post=9&amp;subd=dotnettrick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2><a id="viewpost_ascx_TitleUrl" title="Title of this entry." href="http://weblogs.sqlteam.com/jeffs/archive/2005/09/12/7755.aspx"><br />
</a></h2>
<p>Many SQL books and tutorials recommend that you “avoid cross joins” or “beware of Cartesian products” when writing your SELECT statements, which occur when you don&#8217;t express joins between your tables.  It’s true that you need to ensure that your join conditions are adequately stated so that you don’t accidentally produce this effect, but it is not true that you should avoid these types of joins in every situation.</p>
<p>Cross Joins produce results that consist of every combination of rows from two or more tables.  That means if table A has 3 rows and table B has 2 rows, a CROSS JOIN will result in 6 rows.  There is no relationship established between the two tables – you literally just produce every possible combination.</p>
<p>The danger here, of course, is that if you have table A with 10,000 rows and Table B with 30,000 rows, and you accidentally create the product of these two tables, you will end up with a 300,000,000 row result &#8212; probably not a good idea.  (Though it is great for creating test data and the like.)</p>
<p>So, how can this ever be useful?  Actually, if you do lots of report writing in SQL, a CROSS JOIN can be your best friend.</p>
<p>Suppose you need to write a report that returns total sales for each Store and each Product.  You might come up with this:</p>
<p><span style="font-family:Courier New;color:#000080;font-size:x-small;">SELECT Store, Product, SUM(Sales) as TotalSales<br />
FROM Sales<br />
GROUP BY Store, Product</span></p>
<p>Easy enough – except when the requirement states “show $0 if a store had no sales of a particular product”.  The above query won’t do that – it returns no rows at all if a store had no sales for a particular product.</p>
<p>The solution?  Well, hopefully in your database you have a table of Stores and a table of Products.  A cross join of the two results will return 1 row per combination of Store and Product:</p>
<p><span style="font-family:Courier New;color:#000080;font-size:x-small;">SELECT S.Store, P.Product<br />
</span><span style="font-family:Courier New;color:#000080;font-size:x-small;">FROM Stores S<br />
</span><span style="font-family:Courier New;color:#000080;font-size:x-small;">CROSS JOIN Products P</span></p>
<p dir="ltr">That result is the perfect starting point for the results we wish to return &#8212; now we just need to return the sales for each combination.  We already have written that in our first attempt, so now we just need to combine the two:</p>
<p><span style="font-family:Courier New;color:#000080;font-size:x-small;">SELECT S.Store, P.Product, ISNULL(C.TotalSales,0) as TotalSales<br />
FROM Stores S<br />
CROSS JOIN Products P<br />
LEFT OUTER JOIN<br />
(SELECT Store, Product, SUM(Sales) as TotalSales<br />
FROM Sales<br />
GROUP BY Store, Product) C<br />
ON<br />
S.Store = C.Store AND<br />
P.Product = C.Product</span></p>
<p>The SELECT is derived logically from our requirements.  We start by considering all combinations of stores and products, and from there we show any matching sales data.  Our primary, driving rowset is actually <em>not </em>the transaction table, but rather the cross join of two entity tables!  It might seem very counter intuitive if you haven&#8217;t approached the problem from this angle before, but it leads to very simple and elegant ways to solve rather complicated problems using SQL.</p>
<p>The solution uses what I call “the report writers magic formula”:</p>
<p><strong>(A x B ) -&gt; (C)</strong></p>
<p>In my made up notation, the above reads “A cross joined with B, left outer joined to C ”.  A and B represent master tables of entities in your database, and C represents a summarized derived table of a transactional table in your database.</p>
<p>Some important things to note:</p>
<ul>
<li>All criteria for the transactions, such as date ranges and/or transaction types, need to be done in the <em>inner</em> transaction summary query.</li>
<li>The summarized transactional sub-query needs to be properly grouped so that it returns 1 row per combination of A and B.  Typically, this means that if the PK of table A is “A_ID” and the PK is table B is “B_ID”, then the derived table C should be grouped by A_ID, B_ID.</li>
<li>All criteria that determines which entities to show on your report – i.e., certain regions or only “active” products – should be done on the <em>outer</em> query.</li>
</ul>
<p>Take the previous SELECT statement, for example: Note that the inner SELECT is grouped by Product and Store, which ensures that we return 1 row per combination of Product/Store &#8212; which perfectly matches what the cross join creates.  If we wanted to show only data for 2005, we would put the filter on the TransactionDate column within the <em>inner </em>SELECT (since that is the part of the statement in which we collect and summarize our transactions), but if we want only ProductID #23, we do that in the <em>outer </em>SELECT (since that is where we determine the population of Stores and Products to return):</p>
<p><span style="font-family:Courier New;color:#000080;font-size:x-small;">SELECT S.Store, P.Product, ISNULL(C.TotalSales,0) as TotalSales<br />
FROM Stores S<br />
CROSS JOIN Products P<br />
LEFT OUTER JOIN<br />
(SELECT Store, Product, SUM(Sales) as TotalSales<br />
FROM Sales<br />
<strong> WHERE TransactionDate between &#8217;1/1/2005&#8242; and &#8217;12/31/2005&#8242;</strong><br />
GROUP BY Store, Product) C<br />
ON<br />
S.Store = C.Store AND<br />
P.Product = C.Product<br />
<strong>WHERE<br />
P.Product = 23</strong></span></p>
<p>The CROSS JOIN technique can apply to many situations – to return total labor cost by office by month, even if month X has no labor cost, you can do a cross join of Offices with a table of all months.   Another classic example is showing all GL transactions for a specific set of companies and accounts, returning all accounts and companies even when they have no activity.</p>
<p>The important thing is to practice with very small sets of sample data until you get a feel for how it works.  Also, you should explicitly state CROSS JOIN in your SELECT so that it is very clear that you intend for this to happen and it is not the result of missing joins.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnettrick.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnettrick.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnettrick.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnettrick.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnettrick.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnettrick.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnettrick.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnettrick.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnettrick.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnettrick.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnettrick.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnettrick.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnettrick.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnettrick.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnettrick.wordpress.com&amp;blog=10970746&amp;post=9&amp;subd=dotnettrick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnettrick.wordpress.com/2009/12/19/the-power-trick-of-the-cross-join/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba17c0a39f33d8a281650547aeddb52?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">letter2sanjay1</media:title>
		</media:content>
	</item>
		<item>
		<title>Hosting and Consuming WCF Services</title>
		<link>http://dotnettrick.wordpress.com/2009/12/17/hosting-and-consuming-wcf-services/</link>
		<comments>http://dotnettrick.wordpress.com/2009/12/17/hosting-and-consuming-wcf-services/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 18:55:52 +0000</pubDate>
		<dc:creator>letter2sanjay1</dc:creator>
				<category><![CDATA[WCF]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://dotnettrick.wordpress.com/?p=4</guid>
		<description><![CDATA[Contents:Introduction Exploring Your Hosting Options Self-Hosting Your Service Hosting in Windows Services Hosting Using Internet Information Services Consuming WCF Services Conclusion Introduction When your business relies on a service-oriented architecture, you must make sure that your services are robust. The most important driver behind the robustness of your application is where/how you host your service. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnettrick.wordpress.com&amp;blog=10970746&amp;post=4&amp;subd=dotnettrick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div id="nstext"><strong>Contents:</strong><a href="#msdnwcfhc_topic1">Introduction</a><br />
<a href="#msdnwcfhc_topic2">Exploring Your Hosting Options</a><br />
<a href="#msdnwcfhc_topic3">Self-Hosting Your Service</a><br />
<a href="#msdnwcfhc_topic4">Hosting in Windows Services</a><br />
<a href="#msdnwcfhc_topic5">Hosting Using Internet Information Services</a><br />
<a href="#msdnwcfhc_topic6">Consuming WCF Services</a><br />
<a href="#msdnwcfhc_topic7">Conclusion</a></p>
<h2>Introduction</h2>
<p>When your business relies on a service-oriented architecture, you must make sure that your services are robust. The most important driver behind the robustness of your application is where/how you host your service. You must ask yourself several questions when thinking about hosting services: What are the availability requirements of my services? How am I going to manage and deploy my services? Do I need to support older versions of my services?</p>
<p>Learning how to cover these business requirements is essential to developing successful services. As you learned in Chapter 3, you have to host services on your own host. Windows Communication Foundation (WCF) doesn&#8217;t come with its own host, but instead comes with a class called <strong>ServiceHost</strong> that allows you to host WCF services in your own application easily. You don&#8217;t have to think about any of the network transport specifics to be able to make sure that your services are reachable. It&#8217;s a matter of configuring your services&#8217; endpoints either programmatically or declaratively, and calling the <strong>Open</strong> method of <strong>ServiceHost</strong>. All of the generic functionality regarding bindings, channels, dispatchers, and listeners that you learned about in Chapter 3 is integrated into <strong>ServiceHostBase</strong> and <strong>ServiceHost</strong>. This means that the responsibility of the application that you use to host your service, the application where <strong>ServiceHost</strong> is running, is significantly less than you would expect up front.</p>
<p>This chapter is about which types of applications you can use to host <strong>ServiceHost</strong>. In addition, you will learn about the differences when you want to consume these services hosted in different applications.</p>
<p>After completing this chapter, you will have the following knowledge:</p>
<ul>
<li>The different hosting options available to you</li>
<li>The advantages and disadvantages of each hosting option</li>
<li>Guidance on when to choose each hosting option</li>
<li>Architectural guidance on how Microsoft implemented the different hosting options, and the extensibility points that each option has</li>
</ul>
<h2>Exploring Your Hosting Options</h2>
<p>On the Microsoft .NET platform, you have several types of managed Windows applications that you can create with Microsoft Visual Studio.NET:</p>
<ul>
<li>WinForms applications</li>
<li>Console applications</li>
<li>Windows services</li>
<li>Web applications (ASP.NET) hosted on Internet Information Services (IIS)</li>
<li>WCF services inside IIS 7.0 and WAS on Windows Vista or Windows Server code name &#8220;Longhorn&#8221;</li>
</ul>
<p>If you look through the project templates that come with Microsoft Visual Studio 2005, you will find other options available at your disposal. For obvious reasons, we don&#8217;t consider any of the other templates to be viable options to use in the services world. It is worth noting, however, that WCF doesn&#8217;t block you from running your service in any other type of application as long as it provides you with a .NET application domain. (If you don&#8217;t know the concepts behind a .NET application domain, please refer to the &#8220;Understanding .NET Application Domains&#8221; section that follows.) It all comes down to the requirements you have for your host. To summarize the options, think about the following three generic categories of hosts for your WCF services:</p>
<ul>
<li>Self-hosting in any managed .NET application</li>
<li>Hosting in a Windows service</li>
<li>Hosting in different versions of IIS</li>
</ul>
<p>As you can imagine, all of these have associated project templates in Visual Studio, as mentioned earlier in this section, and all of them have their own characteristics. To get a better understanding of which host is the best in each situation, you must understand the requirements and the features hosts typically have. After you understand this, we will walk you through each hosting option individually.</p>
<h3>Understanding .NET Application Domains</h3>
<p>Assuming you understand the role of Windows processes and how to interact with them from managed code, you must investigate the concept of a .NET application domain. To run your managed .NET code in a process, you create assemblies. These assemblies are not hosted directly within a Windows process. Instead, the common language runtime (CLR) isolates this managed code by creating separate logical partitions within a process called an <em>application domain</em>. A single process may contain multiple application domains, each of which is hosting distinct pieces of code encapsulated in assemblies. This subdivision of a traditional Windows process offers several benefits provided by the .NET Framework.</p>
<p>The main benefits are as follows:</p>
<ul>
<li>Application domains provide the operating system–neutral nature of the .NET platform by abstracting away the concept of an executable or library.</li>
<li>Application domains can be controlled and (un)loaded, as you want.</li>
<li>Application domains provide isolation for an application or within a process where multiple application domains live. Application domains within a process are independent of each other and as such remain functional when one fails the other.</li>
</ul>
<h3>Hosting Environment Features</h3>
<p>A .NET application requires a hosting Windows process. Inside that Windows process, you can host multiple .NET application domains. An application domain is the means for the .NET CLR to isolate the managed code from Windows. The CLR automatically creates one default application domain in each worker process where it is initialized in a process. The default application domain is not unloaded until the process in which it runs shuts down. The CLR controls the shutdown of the default application domain. In most hosts, no code is running inside the default application domain. Instead, hosts (or <em>processes</em>) create a new application domain so the application domain can be closed independently of the process. In a lot of applications, it is desirable that the client-side code and server-side code execute in different application domains. Often, these desires stem from reasons such as security and isolation.</p>
<p>The relationship between processes and application domains is similar to the relationship between applications and application domains and the WCF <strong>ServiceHost</strong>. As Figure 5-1 illustrates, every process has at least one application domain, and each application domain can host zero or more WCF <strong>ServiceHost</strong> instances. WCF requires at least an application domain hosted inside a Windows process.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-1%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-1(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-1. Processes, application domains, and WCF ServiceHost relationship</strong></p>
<blockquote>
<div><strong>Note</strong> Although you can instantiate multiple instances of <strong>ServiceHost</strong>, it is easier to maintain one instance of <strong>ServiceHost</strong> per application domain. You can use multiple endpoints to expose multiple service interfaces in one host. More advanced hosts, such as IIS and WAS, do instantiate multiple instances of <strong>ServiceHost</strong> to provide isolation and different security contexts.</div>
</blockquote>
<blockquote>
<div>Therefore, the main responsibility of the host is to provide a Windows worker process and an application domain to the WCF <strong>ServiceHost</strong>. In addition, WCF relies on the security and configuration features provided by an application domain. A Windows process always runs under a default identity that WCF uses out of the box. However, WCF comes with features to impersonate users on several levels (which is covered in Chapter 7 of the book). If you don&#8217;t use these features, then the Windows process that your service runs under provides the security context. As you know from previous chapters, by default WCF relies on the configuration features in the .NET Framework that are accessible through the application domain.</div>
</blockquote>
<blockquote>
<div>Some hosts come with additional features for managing applications running under them. Most notably, IIS comes with automatic process recycling, resource throttling, logging, health indicators, and other features. You can learn more about these topics throughout the chapter. (Different IIS versions have different manageability features that are supported by WCF. Most notably, IIS 5.1 on Windows XP comes with several limitations in the management user interface.)</div>
</blockquote>
<h3>Hosting Environment Requirements</h3>
<p>Microsoft did a good job ensuring that you as a service developer don&#8217;t have to care much about the hosting environment. <strong>ServiceHost</strong> abstracts all the technological difficulties away so you can focus on your service logic instead of the plumbing involved in hosting services. Based on your requirements, you have to choose a host. WCF is written primarily as a programming model, and one of the main design decisions for it is to be host-agnostic. <strong>ServiceHost</strong>doesn&#8217;t care where it is instantiated as long as it is running when you want your services to be reachable. In other words, it requires a process that runs a .NET application domain.</p>
<p>You must consider certain requirements when choosing an application type (such as whether it&#8217;s a console application, a WinForms application, and so on). You must instantiate <strong>ServiceHost</strong> to provide you with the hosting environment where your services live. Typical .NET applications such as console and WinForms applications run on user desktop machines. These environments are not running all the time; hosting your services there is possible, but they&#8217;re not typical enterprise-ready hosts. We consider enterprise-ready hosts to support a larger-scale service-oriented architecture, where services are exposing key business functionality on which multiple systems rely. These enterprise-ready hosts typically fulfill requirements such as high availability. As such, we don&#8217;t consider console or WinForms applications to be enterprise-ready hosts.</p>
<p>Services usually run on servers and are managed and operated by operators. Usually, the operators that manage servers don&#8217;t like starting console applications or WinForms application by hand when servers are rebooted. For your service applications to be ready to run in a data center, the only viable option for enterprise service-oriented scenarios is hosting your services either on IIS or as a Windows service.</p>
<p>Sometimes, you&#8217;ll require interprocess communication on a user&#8217;s desktop machine. In this scenario, the service is active only when the user is using the application. Typical applications where you see interprocess communication requirements are console applications and WinForms applications. The applications are suitable to host these types of services.</p>
<p>To be able to determine which host is the most applicable host for your scenario, you should refer to your nonfunctional requirements. Typically, nonfunctional requirements state technical requirements for your application to ensure they meet the quality and maintainability of your application. For WCF applications, this comes down to the following topics:</p>
<ul>
<li><em>Availability</em>: When do you want to be able to reach your service?</li>
<li><em>Reliability</em>: What happens when your service somehow breaks? How does this affect other consumers?</li>
<li><em>Manageability</em>: Do you need easy access to information about what is happening on the host where WCF services live?</li>
<li><em>Versioning</em>: Do you need to support older versions of the service? Do you know who is consuming your services?</li>
<li><em>Deployment</em>: What is your deployment model? Are you installing through the Microsoft Installer process and Visual Studio deployment packages, or is xcopy sufficient?</li>
<li><em>State</em>: Are your services stateless? Do you need sessions?</li>
</ul>
<p>Based on these nonfunctional requirements, you can decide which host meets your needs. To help you with this choice, for the remaining part of this chapter you will look at the different hosting environments, including their advantages and disadvantages.</p>
<blockquote>
<div><strong>Note</strong> The WCF programming model is agnostic to where it is running, so switching to a different host later is always possible and doesn&#8217;t mean you have to change your service implementation. Typically, you&#8217;ll start with a self-hosted scenario in a console application to test-drive and prototype your services.</div>
</blockquote>
<h2>Self-Hosting Your Service</h2>
<p>The most flexible and easiest way to host WCF services is by self-hosting. To be able to self-host your services, you have to meet two requirements. First, you need the WCF runtime; second, you need a managed .NET application in which you can host <strong>ServiceHost</strong>. It is your own responsibility to write the code that starts and stops the host.</p>
<p>The following are the advantages of self-hosting:</p>
<ul>
<li><em>Is easy to use</em>: With only a few lines of code you have your service running.</li>
<li><em>Is flexible</em>: You can easily control the lifetime of your services through the <strong>Open()</strong> and <strong>Close()</strong> methods of <strong>ServiceHost&lt;T&gt;</strong>.</li>
<li><em>Is easy to debug</em>: Debugging WCF services that are hosted in a self-hosted environment provides a familiar way of debugging, without having to attach to separate applications that activate your service.</li>
<li><em>Is easy to deploy</em>: In general, deploying simple Windows applications is as easy as xcopy. You don&#8217;t need any complex deployment scenarios on server farms, and the like, to deploy a simple Windows application that serves as a WCF <strong>ServiceHost</strong>.</li>
<li><em>Supports all bindings and transports</em>: Self-hosting doesn&#8217;t limit you to out-of-the-box bindings and transports whatsoever. On Windows XP and Windows Server 2003, IIS limits you to HTTP only.</li>
</ul>
<p>The following are the disadvantages of self-hosting:</p>
<ul>
<li><em>Limited availability</em>: The service is reachable only when the application is running.</li>
<li><em>Limited features</em>: Self-hosted applications have limited support for high availability, easy manageability, robustness, recoverability, versioning, and deployment scenarios. At least, out-of-the-box WCF doesn&#8217;t provide these, so in a self-hosted scenario you have to implement these features yourself; IIS, for example, comes with several of these features by default.</li>
</ul>
<p>In other words, you shouldn&#8217;t consider self-hosting for enterprise scenarios. Self-hosting is suitable during the development or demonstration phases of your enterprise project. Another suitable example where you would self-host your services is when you want applications on a user desktop to communicate with each other or in a peer-to-peer scenario, as described in Chapter 12 of the book.</p>
<p>You saw several examples of self-hosting scenarios in Chapter 3. These examples all used simple console applications. To illustrate this better in a real-life scenario, this chapter presents a WinForms application that hosts a service that tracks published quotes for the Market Makers actors in the QuickReturns Ltd. case study.</p>
<p>For this scenario, you have two distinct WinForms applications. One is the Market Makers Manager application that Market Makers can use to publish quotes and trade their securities. The other is a separate WinForms application that tracks published quotes. It does that by exposing a service that implements the <strong>ITradeTrackingService</strong> contract, as described in Listing 5-1. The Market Makers Manager application calls this service when it successfully publishes a quote through the <strong>TradeService</strong>.</p>
<p><strong>Listing 5-1. ServiceContract for the TradeTrackingService</strong></p>
<div id="ctl00_MTCS_main_ctl11_">
<div dir="ltr">
<pre>using System.ServiceModel;
using QuickReturns.StockTrading.ExchangeService.DataContracts;

namespace QuickReturns.StockTrading.TradeTrackingService.Contracts
{
    [ServiceContract()]
    interface ITradeTrackingService
    {
        [OperationContract()]
        void PublishQuote(Quote quote);
    }
}</pre>
</div>
</div>
<h2>Hosting in Windows Services</h2>
<p>Hosting a WCF service in a Windows service is a logical choice. Windows services shouldn&#8217;t be confused with WCF services. They both use the word service, but they have different meanings. A Windows service is a process managed by the operating system. Windows comes with the Service Control Manager, which controls the services installed on the operating system. Windows uses services to support operating system features such as networking, USB, remote access, message queuing, and so on. You can use Visual Studio 2005 to create a Windows service using the Windows Service project template shown in Figure 5-2.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-2%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-2(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-2. Visual Studio 2005 Windows Service project template</strong></p>
<p>The Windows Service project template generates a project that contains two files: the service1.cs file that contains the service implementation and the program.cs file that instantiates and essentially hosts the Windows service. To host your WCF service inside a Windows service, you merely have to implement the <strong>Start()</strong> and <strong>Stop()</strong> methods of the Windows service, as shown in Listing 5-2. Because the paradigm of starting Windows services is similar to starting your services inside WCF <strong>ServiceHost</strong>, you end up tying the lifetime of your WCF service to the lifetime of your Windows service.</p>
<p><strong>Listing 5-2. Windows service hosting the WCF ServiceHost</strong></p>
<div id="ctl00_MTCS_main_ctl13_">
<div dir="ltr">
<pre>using System;
using System.ServiceModel;
using System.ServiceProcess;
using QuickReturns.StockTrading.ExchangeService;

namespace QuickReturns.StockTrading.ExchangeService.Hosts
{
    public partial class ExchangeWindowsService : ServiceBase
    {
        ServiceHost host;

        public ExchangeWindowsService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            Type serviceType = typeof(TradeService);
            host = new ServiceHost(serviceType);
            host.Open();
        }

        protected override void OnStop()
        {
            if(host != null)
               host.Close();
        }
    }
}</pre>
</div>
</div>
<p>So, writing a Windows service that hosts your WCF service is pretty easy and comes with several benefits when compared to the self-hosting scenario from earlier in this chapter. On the other hand, writing a Windows service that hosts your WCF service also comes with some disadvantages that you must understand.</p>
<p>The following are the advantages:</p>
<ul>
<li><em>Automatic starting</em>: The Windows Service Control Manager allows you to set the startup type to automatic, so that as soon as Windows starts, the service will be started, without an interactive logon on the machine.</li>
<li><em>Recovery</em>: The Windows Service Control Manager has built-in support to restart services when failures occur.</li>
<li><em>Security identity</em>: The Windows Service Control Manager allows you to choose a specific security identity under which you want the service to run including built-in system or network service accounts.</li>
<li><em>Manageability</em>: In general, Windows operators know a lot about the Service Control Manager and other management tools that can work with Windows service installation and configuration. This will improve the acceptance of Windows services in production environments; however, to make services maintainable, you would probably have to add some instrumentation and logging features.</li>
<li><em>Support for all bindings and transports</em>: Self-hosting doesn&#8217;t limit you in using any of the out-of-the-box bindings and transports whatsoever. On Windows XP and Windows Server 2003, IIS limits you to HTTP only.</li>
</ul>
<p>The following are some of the disadvantages of Windows services:</p>
<ul>
<li><em>Deployment:</em> Services must be installed with the .NET Framework <strong>Installutil.exe</strong> utility or through a custom action in an installer package.</li>
<li><em>Limited features</em>: Windows services still have a limited set of out-of-the-box features to support high availability, easy manageability, versioning, and deployment scenarios. Essentially you have to cover these requirements yourself through custom code while, for example, IIS comes with several of these features by default. Windows services do add recoverability and some security features, but you still have to do some work yourself.</li>
</ul>
<p>To be able to install a service in the Service Control Manager, you have to add an installer to the project. Visual Studio 2005 allows you to do this easily:</p>
<ol>
<li>Open the Designer view of the Service class in your Windows service project.</li>
<li>Click the background of the designer to select the service itself, instead of any of its contents.</li>
<li>In the Properties window, click the <strong>Add Installer</strong> link in the gray area under the list of properties, as shown in Figure 5-3. By default, this adds a component class containing two installers to your project. The component is named ProjectInstaller, and the installers that it contains are the installer for your service and the installer for the associated process of the service.<img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-3%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-3(en-us,MSDN.10).gif" /><strong>Figure 5-3. The Add Installer function of a Windows service project</strong></li>
<li>Access the Designer view for ProjectInstaller, and click <strong>ServiceInstaller1</strong>.</li>
<li>In the Properties window, set the <strong>ServiceName</strong> property to <strong>QuickReturns Exchange Service</strong>.</li>
<li>Set the <strong>StartType</strong> property to <strong>Automatic</strong>, as shown in Figure 5-4.<img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-4%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-4(en-us,MSDN.10).gif" /><strong>Figure 5-4. The Properties window of QuickReturns Exchange Service</strong></li>
<li>Access the Designer view for ProjectInstaller, and click <strong>serviceProcessInstaller1</strong>.</li>
<li>In the Properties window, set the <strong>Account</strong> property to <strong>Network Service</strong>, as shown in Figure 5-5.<img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-5%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-5(en-us,MSDN.10).gif" /><strong>Figure 5-5. The Properties window of QuickReturns Exchange Service</strong></li>
</ol>
<p>To be able create a setup that can be used to install your Windows service, you must add a Visual Studio setup and deployment project to the solution. The following steps describe how to add a setup and deployment project to your solution:</p>
<ol>
<li>Select <strong>File</strong> | <strong>Add</strong> | <strong>New Project</strong>.</li>
<li>In the <strong>New Project</strong> dialog box, select the <strong>Other Project Types</strong> category, select <strong>Setup and Deployment</strong>, and then select <strong>Setup Project</strong>, as shown in Figure 5-6.<img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-6%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-6(en-us,MSDN.10).gif" /><strong>Figure 5-6. Visual Studio 2005 setup project template</strong></li>
<li>In the Solution Explorer, right-click the setup project, point to <strong>Add</strong>, then choose <strong>Project Output</strong>, as shown in Figure 5-7. The <strong>Add Project Output Group</strong> dialog box appears.<img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-7%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-7(en-us,MSDN.10).gif" /><strong>Figure 5-7. Adding the Windows service project output</strong></li>
<li>Select the Windows service project.</li>
<li>From the list box, select <strong>Primary Output</strong>, and click <strong>OK</strong>.</li>
</ol>
<p>This adds a project item for the primary output of your Windows service to the setup project. Now, add a custom action to install the executable file. To add a custom action to the setup project, follow these steps:</p>
<ol>
<li>In Solution Explorer, right-click the setup project, point to <strong>View</strong>, and then choose <strong>Custom Actions</strong>, as shown in Figure 5-8. The Custom Actions view appears.<img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-8%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-8(en-us,MSDN.10).gif" /><strong>Figure 5-8. Opening the Custom Actions view</strong></li>
<li>Right-click <strong>Custom Actions</strong> and select <strong>Add Custom Action</strong>.</li>
<li>Double-click the application folder in the list box to open it, select <strong>Primary Output</strong> from the Windows service project, and click <strong>OK</strong>. The primary output is added to all four nodes of the custom actions: Install, Commit, Rollback, and Uninstall.</li>
<li>Build the setup project.</li>
</ol>
<p>When you compile the project, the output is a Microsoft Installer file (.msi) that you can use to install the service into the Windows Service Control Manager.</p>
<blockquote>
<div><strong>Note</strong> This chapter describes the basics of building Windows services and Windows service installers. Setting your Windows services to run under the unrestricted Localsystem account or the somewhat appropriate Network Service account is not always the best choice in terms of security best practices. Usually operators have the ability to choose the credentials during setup or adjust the security identity settings after installation through the Service Control Manager Management Console snap-in that can be accessed through Windows Computer Management. Please refer to Chapter 7 of this book, MSDN Help, or a book dedicated to .NET development for more details and best practices regarding developing Windows services.</div>
</blockquote>
<h2>Hosting Using Internet Information Services</h2>
<p>Web service development on IIS has long been the domain of ASP.NET. When ASP.NET 1.0 was released, a Web service framework was part of it. Microsoft leveraged the ASP.NET HTTP pipeline to make Web services a reality on the Windows platform. Unfortunately, this tight coupling between ASP.NET and Web services comes with several limitations in the service-orientation world; the dependency on HTTP is the main culprit. Running the ASP.NET HTTP pipeline on a different host is hard and therefore is an uncommon scenario. Even then, ASP.NET Web services (also known as ASMX services) stay very Web-oriented in terms of deployment scenarios and configuration dependencies. Microsoft initially released several versions of the Web Services Enhancements (WSE) to cover some of the limitations of ASP.NET Web services, and especially to address the limitations in the implementation of the WS-* protocols. However, WSE was very dependent on the ASP.NET Web service implementation.</p>
<p>As you learned in previous chapters, WCF services take a totally different approach to make service orientation a reality. The unified programming model of WCF is based on a strictly layered model to break the Web-oriented paradigm and disconnect the service model and channel layer from the supported transports. This model allows WCF to support several different hosts of which IIS is the most important.</p>
<p>WCF was built to support Windows XP, Windows Server 2003, Windows Vista, and Windows Server code name &#8220;Longhorn.&#8221; Since IIS 5.1, which was released with Windows XP, a lot has changed. Still, Microsoft succeeded in supporting WCF on older versions. This was possible because of the features that the Microsoft .NET Framework and the CLR provide, which is what WCF is built on. In the following sections, you will learn the differences in the process models of the different IIS versions and the consequences for your WCF services.</p>
<h3>Core IIS 5.1 and 6.0 Features</h3>
<p>To be able to explain the differences, we first have to explain the core features of IIS. IIS has long been supporting multiple sites and multiple applications on one machine. To enable this, IIS introduced a common address model that is split into three main areas:</p>
<ul>
<li>Sites (Note: IIS 5.1, released with Windows XP, supports only one site.)</li>
<li>Applications</li>
<li>Virtual directories</li>
</ul>
<p>Sites are bound to a particular scheme, network address, and port combination. IIS not only supports HTTP but also, depending on the version, FTP, NNTP, and SMTP. You can run multiple applications under the same site and under the same scheme, network, and port combination. A typical URI for an application is <strong>http://localhost/MyApplication</strong>. A virtual directory is simply a folder that is mapped to the network space of the site, which could somewhere else on the file system. This way, you can keep the actual content or code of an application separate from the other applications that are part of the same site.</p>
<p>In IIS 6.0, Microsoft made some significant changes in the IIS process model. The IIS process model was split into application pools that can be shared among sites and applications, where each application runs in its own application domain. An <em>application pool</em> is a separate Windows worker process called W3wp.exe and is started only when it needs to start. In other words, IIS comes with an application activation model that allows IIS to start-up an application pool when it receives a request for a particular application that is bound to that application pool. This enables IIS to host several thousands of applications on one server without keeping several thousand processes running. The activation architecture of IIS is an interesting model in the services world, as you will see in the &#8220;Windows Activation Services&#8221; section of this chapter.</p>
<p>Figure 5-9 shows the core IIS 6.0 architecture on the bottom of the HTTP protocol stack and, on top of that, at least four different processes.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-9%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-9(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-9. IIS 6.0 core architecture</strong></p>
<ul>
<li><strong>Lsass.exe:</strong> Responsible for the security features in IIS: the implementation of Windows Authentication and Secure Sockets Layer (SSL).</li>
<li><strong>Inetinfo.exe:</strong> The process that hosts the non-HTTP services and the IIS Admin Service, including the Metabase.</li>
<li><strong>SvcHost.exe:</strong> The process that can host operating system services; in the case of IIS, it hosts the Web (HTTP) service.</li>
<li><strong>W3wp.exe:</strong> A worker process. IIS can have multiple W3wp.exe processes, one for each application pool. To support Web-garden scenarios where one application is split in separate processes, you have multiple instances of the same worker process. This can provide additional scalability and performance benefits.</li>
</ul>
<blockquote>
<div><strong>Note</strong> We are describing the IIS 6.0 architecture here, because that was the most widely used version of IIS before the release of WCF. In addition, WCF supports IIS 6.0, and the model closely resembles the implementation that was chosen with IIS 7.0 and Windows Activation Services, as you will learn in the remainder of this chapter. The main difference between IIS 5.1 and IIS 6.0 is the limitation in the amount of sites and application pools. IIS 5.1 supports only one site bound to one application pool.</div>
</blockquote>
<h3>Hosting WCF Services in IIS</h3>
<p>To host a WCF Service in IIS, you need a new physical file with the .svc extension. The file associates a service with its implementation and is the means for IIS to create <strong>ServiceHost</strong> for you. IIS takes over the interaction between your service and <strong>ServiceHost</strong>; you no longer have to instantiate and start <strong>ServiceHost</strong> yourself. The first line of the .svc file contains a directive enclosed in the ASP.NET <strong>&lt;% Page %&gt;</strong> directive that tells the hosting environment to which service this file points. The service code can then reside inline as shown in Listing 5-3, in a separate assembly registered in the GAC, in an assembly that resides in the application&#8217;s Bin folder, or in a C# file that resides under the application&#8217;s App_Code folder. The most common scenario is to define endpoints in a configuration file. In IIS, you have to define your endpoints in the Web.config file, as explained in the next section.</p>
<p>Listing 5-3 shows a sample .svc file based on the <strong>TradeService</strong> service that you saw earlier. It has the service code defined inline. Listing 5-4 shows an example .svc file where the code resides in the App_Code folder.</p>
<p><strong>Listing 5-3. ExchangeServiceInline.svc File with inline code</strong></p>
<div id="ctl00_MTCS_main_ctl21_">
<div dir="ltr">
<pre>&lt;%@ServiceHost Language="C#"
Service="QuickReturns.StockTrading.ExchangeService.TradeServiceInline"
%&gt;

using System;
using System.Collections;
using System.ServiceModel;
using QuickReturns.StockTrading.ExchangeService.Contracts;
using QuickReturns.StockTrading.ExchangeService.DataContracts;

namespace QuickReturns.StockTrading.ExchangeService
{
    [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
                    IncludeExceptionDetailInFaults=true)]
    public class TradeServiceInline : ITradeService
    {
        public Quote GetQuote(string ticker)
        {
             ...
        }

        public void PublishQuote(Quote quote)
        {
             ...
        }
    }
}</pre>
</div>
</div>
<p><strong>Listing 5-4. ExchangeService.svc file with external code</strong></p>
<div id="ctl00_MTCS_main_ctl22_">
<div dir="ltr">
<pre>&lt;% @ServiceHost language="C#"
Service=" QuickReturns.StockTrading.ExchangeService.TradeService"
<strong>CodeBehind="~/App_Code/TradeService.cs"</strong> %&gt;</pre>
</div>
</div>
<h3>Configuring WCF Services in IIS</h3>
<p>Hosting in IIS means you will have to set up the WCF configuration in the Web.config file of the application where you want to host your service. The service configuration in the Web.config file is similar to that of self-hosted services. Listing 5-5 shows an example of a Web.config file for the <strong>TradeService</strong> service.</p>
<p><strong>Listing 5-5. Web.config used to configure a service hosted in IIS</strong></p>
<div id="ctl00_MTCS_main_ctl23_">
<div dir="ltr">
<pre>&lt;?xml version="1.0"?&gt;
&lt;configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"&gt;
   &lt;system.serviceModel&gt;
      &lt;services&gt;
         &lt;service
name="QuickReturns.StockTrading.ExchangeService.TradeService"
                  behaviorConfiguration="tradeServiceBehavior"&gt;
         &lt;endpoint name="basicHttpBinding"
                   <strong>address=""</strong>
                   binding="basicHttpBinding"
                   contract="QuickReturns.StockTrading.ExchangeService.?
                             Contracts.ITradeService"/&gt;
         &lt;endpoint name="mexHttpBinding"
                   contract="IMetadataExchange"
                   binding="mexHttpBinding"
                   address="mex" /&gt;
      &lt;/service&gt;
      &lt;service
name="QuickReturns.StockTrading.ExchangeService.TradeServiceInline"
               behaviorConfiguration="tradeServiceBehavior"&gt;
            &lt;endpoint name="basicHttpBinding"
                      <strong>address=""</strong>
                      binding="basicHttpBinding"
                      contract="QuickReturns.StockTrading.ExchangeService.?
                                Contracts.ITradeService"/&gt;
            &lt;endpoint name="mexHttpbinding"
                      contract="IMetadataExchange"
                      binding="mexHttpBinding"
                      address="mex" /&gt;
         &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
         &lt;serviceBehaviors&gt;
            &lt;behavior name="tradeServiceBehavior" &gt;
               &lt;serviceMetadata httpGetEnabled="true" /&gt;
            &lt;/behavior&gt;
            &lt;behavior name="returnFaults"
                      returnUnknownExceptionsAsFaults="true"/&gt;
         &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
   &lt;/system.serviceModel&gt;
&lt;/configuration&gt;</pre>
</div>
</div>
<p>Please note that the <strong>address</strong> attribute of the service is empty. The .svc file determines the <em>base</em> address of the service. However, you can provide an additional string that would set the endpoint&#8217;s address relative to the .svc file. For example, you can use the following:</p>
<p><strong>http://localhost:8080/QuickReturns/Exchange.svc/ExchangeService</strong></p>
<p>The service <strong>name</strong> attribute specified in the config file functions as a lookup key for the corresponding ExchangeService.svc. It tells the hosting environment to which service this configuration belongs. The other attributes on the endpoint level are the same as explained previously.</p>
<p>In IIS, Web configuration files can be nested in sites, applications, and virtual directories. WCF takes all the configuration files into account and merges services and their endpoints together. This means that nested Web.config files are additive to each other, where the last file read in the bottom of the hierarchy takes precedence over files higher in the hierarchy.</p>
<h3>Accessing ServiceHost in IIS</h3>
<p>The default behavior of hosting your WCF services in IIS is that IIS controls the instantiation of <strong>ServiceHost</strong>. This limits you from having start-up and shutdown code before a message reaches your service. The advantage of no start-up and shutdown code is, of course, less code that potentially introduces errors. IIS provides you with an easier hosting environment, in terms of lines of code, than a console application. However, sometimes you need a way to circumvent this limitation. To do this and influence IIS in instantiating <strong>ServiceHost</strong>, you can build your own factory that creates your custom host. This way, you can access any of the events or override any of the methods you like.</p>
<p>To support custom <strong>ServiceHost</strong> activation, you should implement your own <strong>Factory</strong> that inherits from <strong>ServiceHostFactory</strong>, which is a factory class that can instantiate your custom host. That class is provided in order to hook up the events for <strong>ServiceHost</strong>; you can use this class and put the type as the <strong>Factory</strong> attribute in the .svc file, as shown in Listing 5-6. By overriding the <strong>CreateServiceHost</strong> method of the <strong>ServiceHostFactory</strong> class, you can perform similar tasks as you do in self-hosting scenarios, as you learned in Chapter 3. Among other things, this enables you to abstract the logic to build up the description from the external configuration or create a more suitable base class for your base library, project, department, or company to use.</p>
<p>Listing 5-7 shows the code of <strong>TradeServiceCustomHost</strong> and <strong>TradeServiceCustomHostFactory</strong> that creates the host.</p>
<p><strong>Listing 5-6. .svc file with a CustomServiceHostFactory</strong></p>
<div id="ctl00_MTCS_main_ctl24_">
<div dir="ltr">
<pre>&lt;% @ServiceHost Language="C#" Debug="true"
   Service="QuickReturns.StockTrading.ExchangeService.TradeService"
   Factory="QuickReturns.StockTrading.ExchangeService.
TradeServiceCustomHostFactory" %&gt;</pre>
</div>
</div>
<p><strong>Listing 5-7. TradeServiceCustomHostFactory and TradeServiceCustomHost</strong></p>
<div id="ctl00_MTCS_main_ctl25_">
<div dir="ltr">
<pre>using System;
using System.ServiceModel;
using System.ServiceModel.Activation;

namespace QuickReturns.StockTrading.ExchangeService
{
   public class TradeServiceCustomHostFactory : <strong>ServiceHostFactory</strong>
   {
      protected override ServiceHost CreateServiceHost(
         Type serviceType, Uri[] baseAddresses)
      {
         TradeServiceCustomHost customServiceHost =
            new TradeServiceCustomHost(serviceType, baseAddresses);
         return customServiceHost;
      }
   }

   public class TradeServiceCustomHost : ServiceHost
   {
      public TradeServiceCustomHost(Type serviceType, params Uri[]
baseAddresses)
         : base(serviceType, baseAddresses)
      {
      }

      protected override void ApplyConfiguration()
      {
         base.ApplyConfiguration();
      }
   }
}</pre>
</div>
</div>
<h3>Recycling</h3>
<p>When you are hosting WCF services on IIS, the WCF services enjoy all the features of ASP.NET applications. You have to be aware of these features because they can cause unexpected behavior in the services world. One of the major features is application recycling, including application domain recycling and process recycling. Through the IIS Management Console, you can configure different rules when you want the recycling to happen. You can set certain thresholds on memory, on time, and on the amount of processed requests, as shown in Figure 5-10. When IIS recycles a worker process, all the application domains within the worker process will be recycled as well. Usually, when critical files in an ASP.NET–based Web application change, the application domain also recycles. This happens, for example, when changing the Web.config file or assemblies in the Bin folder.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-10%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-10(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-10. Application pool recycling settings</strong></p>
<blockquote>
<div><strong>Note</strong> The process recycling described here covers recycling in Windows Server 2003. To enable process recycling in Windows XP and IIS 5.1, you can download the IIS 5.0 process recycling tool from the Microsoft Web site. The process-recycle tool runs as a service on a computer running IIS 5.0 or 5.1.</div>
</blockquote>
<p>After modifying a .svc file, the application domain is also recycled. The hosting environment will try to close all the WCF services&#8217; open connections gracefully in a timely manner. When services somehow don&#8217;t close in time, they will be forced to abort. Through the <strong>HostingEnvironmentSettings</strong> configuration settings, you can influence the behavior of recycling, as you can see in Listing 5-8. The <strong>idleTimeout</strong> setting determines the amount of idle time in seconds for an application domain to be recycled. The <strong>shutdowntimeout</strong> setting determines the amount of time in seconds to gracefully shut down an application. After this time-out, it forces applications to shut down.</p>
<p><strong>Listing 5-8. Web.config with hostingenvironment section for recycling settings</strong></p>
<div id="ctl00_MTCS_main_ctl27_">
<div dir="ltr">
<pre>&lt;system.web&gt;
    &lt;hostingEnvironment idleTimeout="20"
                        shutdownTimeout="30"/&gt;
&lt;/system.web&gt;</pre>
</div>
</div>
<p>When you are using WCF sessions, these recycling features are critical to understand. This is typically the case in the security and reliable messaging scenarios, as you will read in Chapters 6 and 8 of this book. By default, WCF stores session state in memory. This is a different implementation from ASP.NET session state and doesn&#8217;t come with a configuration to switch over to persistent session state storage. However, you can, and should, in the security and reliable messaging scenarios benefit from the ASP.NET implementation. Using the ASP.NET compatibility features of WCF provides you with the SQL Server and state server implementations of ASP.NET session state to support enterprise-ready scenarios. In the next section, you will learn how to benefit from the WCF ASP.NET compatibility mode.</p>
<h3>ASP.NET Compatibility Model</h3>
<p>When hosting your WCF services in a load-balanced or even a Web-garden environment where subsequent requests in a session can be processed by different hosts or processes in the environment, you need out-of-process persistent storage for your session state. Out-of-the box WCF doesn&#8217;t support persistent storage for session state. Instead, WCF stores all its session state in memory. When your WCF services are hosted in IIS, you can end up with recycling scenarios, as described in the previous section. Instead of building persistent storage for sessions all over again, WCF relies on the ASP.NET implementation for session state. This approach has one serious limitation: you limit your services to HTTP.</p>
<p>ASP.NET session state is not the only feature that is supported by the ASP.NET compatibility mode. It also supports features such as the HttpContext, globalization, and impersonation, just like you are used to with ASP.NET Web services (ASMX). Refer to MSDN Help for the ASP.NET–specific features to enable out-of-process session state.</p>
<p>To see the limitation of the ASP.NET compatibility mode, you have to mark your services explicitly with the <strong>AspNetCompatibilityRequirements</strong> attribute, as shown in Listing 5-9.</p>
<p><strong>Listing 5-9. AspNetCompatibilityRequirements attribute</strong></p>
<div id="ctl00_MTCS_main_ctl28_">
<div dir="ltr">
<pre>namespace QuickReturns.StockTrading.ExchangeService
{
    [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
                    ReturnUnknownExceptionsAsFaults=true)]
    [AspNetCompatibilityRequirements(
     RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
    public class TradeService : ITradeService
    {
    ...
    }
}</pre>
</div>
</div>
<p>The <strong>AspNetCompatibilityRequirementsMode</strong> attribute has the following allowed values.</p>
<p><strong>Table 5-1. Values for AspNetCompatibilityRequirementsMode attribute</strong></p>
<div>
<table>
<tbody>
<tr>
<td><strong>Value</strong></td>
<td><strong>Description</strong></td>
</tr>
<tr>
<td><strong>NotAllowed</strong></td>
<td>Indicates that your services may <em>never</em> be run in the ASP.NET compatibility mode. You have to set this in scenarios where your service implementation doesn&#8217;t work in ASP.NET compatibility mode, such as in scenarios where your services are not built for HTTP.</td>
</tr>
<tr>
<td><strong>Allowed</strong></td>
<td>Indicates that your services <em>may </em>run in the ASP.NET compatibility mode. Pick this value only when you know your service may work in this mode.</td>
</tr>
<tr>
<td><strong>Required</strong></td>
<td>Indicates that your service <em>must</em> run in the ASP.NET compatibility mode. Pick this value when your service requires persistent session storage.</td>
</tr>
</tbody>
</table>
</div>
<p>When you choose the <strong>Required</strong> option, WCF will verify that all the supported endpoints for the services are HTTP endpoints and will throw an exception during <strong>ServiceHost</strong> initialization if they aren&#8217;t. In addition to the<strong>AspNetCompatibilityRequirements</strong> attribute, you must set <strong>aspNetCompatibilityEnabled</strong>, as shown in Listing 5-10.</p>
<p><strong>Listing 5-10. Configuration with ASP.NET compatibility enabled</strong></p>
<div id="ctl00_MTCS_main_ctl29_">
<div dir="ltr">
<pre>&lt;?xml version="1.0"?&gt;
&lt;configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"&gt;
   &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt;
      &lt;services&gt;
      ...
      &lt;/services&gt;
      &lt;behaviors&gt;
      ...
      &lt;/behaviors&gt;
  &lt;/system.serviceModel&gt;
&lt;/configuration&gt;</pre>
</div>
</div>
<blockquote>
<div><strong>Note</strong> The sample code that comes with this book contains the <strong>TradeService</strong> service hosted in the ExchangeServiceInline.svc file that is configured to run in ASP.NET compatibility mode. You can find it by opening the Chapter 5 solution file (please refer to the sample code download link).</div>
</blockquote>
<h3>Windows XP and IIS 5.1</h3>
<p>IIS 5.0, which came as part of Windows 2000, split the process model of IIS and introduced worker processes. The primary reason for this change was to isolate applications so that IIS could host different applications that were less dependent on each other. IIS 5.0 was released with Windows 2000, and IIS 5.1 was released with Windows XP. WCF doesn&#8217;t support hosting services on Windows 2000 with IIS 5.0; because of that, we will take a closer look at IIS 5.1 only. IIS 5.1 is supported but has a limitation of only one site, and each application runs in one worker process called aspnet_wp.exe. IIS 5.1 is a great version for developing ASP.NET Web sites and WCF services. It is not ready for enterprise use because it has connection limits and runs only on a client version of earlier Windows versions or Windows XP. In this chapter, we will talk about IIS 5.1</p>
<p>In Figure 5-11, you can see the process model of IIS 5.1. The architecture is split into two pieces. W3svc.exe on the left side hosts an HTTP listener, launches worker processes, and manages the configuration. The worker processes on the other side enable IIS 5.1 to host managed .NET applications, where ASPNET_ISAPI.dll is responsible for creating managed .NET application domains. Please note that on Windows XP, the W3svc.exe Windows service is hosted in the SvcHost.exe process, together with the SMTP and FTP services.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-11%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-11(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-11. IIS 5.1 process-model architecture</strong></p>
<blockquote>
<div><strong>Note</strong> You aren&#8217;t required to have IIS to run ASP.NET and WCF services. For example, you can use the ASP.NET development Web server that is provided with Visual Studio 2005. When Windows XP was released, Visual Studio didn&#8217;t have this feature. You were required to work with IIS 5.1 to be able to develop Web applications on Windows XP.</div>
</blockquote>
<h3>Windows Server 2003 and IIS 6.0</h3>
<p>As of Windows Server 2003, Microsoft introduced the kernel mode HTTP stack called <strong>HTTP.SYS</strong>. <strong>HTTP.SYS</strong> is plugged into the IIS 6.0 architecture through W3svc.exe. W3svc.exe is a user-mode component that bridges the kernel-mode implementation of <strong>HTTP.SYS</strong> and connects this to the process and configuration management system that was already there in IIS 5.1. And as of IIS 6.0, the concept of application pools was more generalized. Although in IIS 5.1 only managed (ASP.NET) applications could be hosted in separate application pools, in IIS 6.0 all types of applications can be hosted in separate application pools. <strong>ASPNET_ISAPI.dll</strong> is still responsible for starting application domains in the managed ASP.NET world. Figure 5-12 illustrates the process model in IIS 6.0.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-12%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-12(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-12. IIS 6.0 process-model architecture hosting on IIS 6.0</strong></p>
<p>The following detailed steps show you how to host a .NET 3.0 WCF Service in IIS 6.0. We will use the sample described earlier to host it in IIS 6.0.</p>
<ol>
<li>Please open the folder that contains the ExchangeServiceIISHost folder from the sample code folder.</li>
<li>The next step is to create a virtual directory out of this in IIS. You can navigate through IIS Manager; but, for simplicity, just right-click on the folder and select <strong>Properties</strong>.</li>
<li>Once the properties dialog appears, click on the <strong>Web Sharing</strong> tab. Just click on the radio button <strong>Share this folder</strong> and the <strong>Edit Alias</strong> dialog appears. Rename the alias from <strong>ExchangeServiceIISHost</strong> to<strong>ExchangeService</strong>. You can enable <strong>Directory Browsing</strong> to make it easier to view and click on items in the Web site. Generally, this is a setting only for development; see Figure 5-13 for the Web Sharing settings.</li>
</ol>
<blockquote>
<div><strong>CAUTION</strong> This setting allows users to browse all files on the site, just like Windows Explorer. While a nice feature, be careful with it in production.</div>
</blockquote>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-13%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-13(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-13. Web Sharing Edit Alias dialog box</strong></p>
<ol>
<li>At this point, just click <strong>OK</strong> several times to dismiss the dialog boxes. The site should now be available through the URL <strong>http://localhost/ExchangeService</strong>. However, we still must check the version of ASP.NET that is set for this site. If you only have .NET 2.0 installed—that is, .NET 1.1 was never installed—there should be nothing else to do; however, it doesn&#8217;t hurt to just check. Therefore, from IIS Manager (<strong>Start</strong> | <strong>Control Panel</strong> |<strong>Administrative Tools</strong> | <strong>Internet Information Services</strong>). Once you see the <strong>Properties</strong> dialog box, click on the <strong>ASP.NET</strong> tab, and then switch the version of ASP.NET by using the drop-down box to the .NET 3.0–supported version—2.0.50727—the RTM version.</li>
<li>There&#8217;s one additional step that is for our example provide access to resources to what is known as the <strong>Anonymous</strong> requests. Anonymous requests are any requests that have no identity or Windows principal associated with the HTTP request.</li>
</ol>
<p>Click on the <strong>Directory Security</strong> tab, and then click on <strong>Edit</strong> under the <strong>Anonymous access and authentication control</strong> section of the dialog box. Ensure that the option <strong>Anonymous access</strong> is enabled. This will allow our example to run without stepping into how to provide Authentication credentials on the requests.</p>
<p>At this point, if you browse to the location <strong>http://localhost/ExchangeService</strong> using Internet Explorer, you&#8217;ll be able to see a directory listing (as long as the settings are like those in the previous figure). If you click on the Service.svc, you are then brought to the default help screen generated by <strong>System.ServiceModel.Activiation.HttpHandler</strong> for *.svc extensions.</p>
<p>At this point, you follow the same steps in a client application, either generation of a proxy class directly through the use of the Svcutil.exe utility, or by right-clicking on the project and generating the proxy through the <strong>Add Service</strong>add-in feature, as is shown later in this chapter in the &#8220;Consuming WCF Services&#8221; section.</p>
<p>The accompanying Solution for this example has a complete Console client that makes a call into the WCF Service we just created.</p>
<h3>Hosting on IIS 7.0</h3>
<p>IIS 7.0 has established another big evolution in the Web server world. As you can see in Figure 5-14, two big changes were made. First, now protocol-specific listener adapters support all four WCF transports, instead of only HTTP in IIS 6.0. In addition, a new operating system service is available called Windows Activation Services (WAS). Both W3svc.exe and WAS are running inside an operating system host called SvcHost.exe. To be able to use the power of the IIS 6.0 process model in conjunction with WCF, these changes were necessary. You might ask, &#8220;Why?&#8221; Well, WCF services also work in IIS 5.1 and IIS 6.0, so what benefits could you get by generalizing the process model and activation features in IIS? Simple: By generalizing the activation concept to make it protocol agnostic, instead of being bound to HTTP, you expand the activation features of the platform to basically all transports.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-14%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-14(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-14. IIS 7.0 process-model architecture</strong></p>
<p>With the release of Windows Vista and Windows Server code name &#8220;Longhorn,&#8221; Microsoft moved the process management and configuration features of IIS and made this generally available inside the operating system. This enables any application built on top of that model to use the power of run-time activation and spawning worker processes based on messages coming in.</p>
<p>The protocol-specific listener adapters for HTTP, TCP/IP, Named Pipes, and MSMQ live inside their own process and are bridging the specific transports over to WAS. Listener adapters ask WAS to activate worker processes and then hand over the actual communication to the specific protocol handler inside these worker processes. So, WAS now has all the features that used to be part of W3svc.exe. By splitting this responsibility into separate processes, the three other transports also benefit from the process model and activation features that used to be built into IIS 6.0, but only for HTTP. To summarize, with IIS 7.0 you can host any WCF service across any transport that is provided out of the box inside IIS. In the next section, you will learn how WAS activation works and what you must be aware of when you want to host your WCF services inside IIS 7.0 and WAS on Windows Vista or Windows Server code name &#8220;Longhorn.&#8221;</p>
<p>To host the <strong>TradeService</strong> that you have been using throughout this book inside IIS 7.0, all you have to do is configure IIS and place the .svc file created for IIS 6.0 in the site you will create. The following steps will enable you to configure IIS 7.0, WAS, and the .NET Framework 3.0 on Windows Server code name &#8220;Longhorn,&#8221; and get your <strong>TradeService</strong> running inside IIS 7.0:</p>
<ol>
<li>Start the Server Manager (found in Administrative Tools).</li>
<li>Add the Web Server (IIS) role to the server.</li>
<li>Note that the Web server installation automatically adds WAS.</li>
<li>On the Detailed Settings screen for IIS, select <strong>ASP.NET</strong>, and, under <strong>Security</strong> select <strong>Basic and Windows Authentication</strong>. Keep the rest in its default settings.This will install IIS and WAS.</li>
<li>By default, Windows Server code name &#8220;Longhorn&#8221; comes without the .NET Framework 3.0 installed. To install .NET Framework 3.0, open the Add Features Wizard (<strong>Control Panel</strong> | <strong>Programs</strong> | <strong>Windows Features</strong>).</li>
<li>Click <strong>Add Features</strong>, and select .<strong>NET Framework 3.0</strong> (if you want to experiment with the WCF MSMQ transport). Select also <strong>MSMQ</strong>.</li>
</ol>
<p>Now, you are all set to run your WCF services on IIS 7.0. The next step is to create an application in IIS in which to run your service. For this you need the Internet Information Services (IIS) Manager. You can find the IIS management tool in Administrative Tools, in the <strong>Start</strong> menu. Then, navigate to your server, then to your Web sites, and finally to the default Web site. Right-click the default Web site and select <strong>Create Application</strong>, as illustrated in Figure 5-15.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-15%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-15(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-15. Creating a new application in the IIS Manager</strong></p>
<p>Now, you need a folder on your local machine where you want to host your application&#8217;s .svc files. As illustrated in Figure 5-16, you can give the application a name where the service can be reached (http://localhost/&lt;<em>chosenname</em>&gt;) and the folder where the files reside, and you can select the application pool.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-16%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-16(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-16. Setting the properties for a new application in the IIS Manager</strong></p>
<p>If you did everything correctly, your service is reachable through IIS 7.0. You can test this by navigating to your newly created application, for example:</p>
<p><strong>http://localhost:8080/QuickReturns/Exchange.svc/ExchangeService</strong></p>
<h3>Windows Activation Services</h3>
<p>WAS enables you to host any WCF service, supporting any transport inside the IIS model. WAS takes over creating worker processes and providing the configuration from the original W3svc.exe Windows service that you know from IIS 6.0 (and runs inside the Inetinfo.exe process). WAS and IIS now share the configuration store that defines sites, applications, application pools, and virtual directories. In this section, we&#8217;ll walk you through the process of activation with WAS, as shown in Figure 5-17.</p>
<p>By default, when no requests are being made to a newly booted server, Windows runs five services (if all of the protocols are enabled). These are the following Windows services:</p>
<ul>
<li>WAS</li>
<li>World Wide Web Publishing Service (hosting the listener adapter)</li>
<li><strong>NET.TCP</strong> listener adapter</li>
<li><strong>NET.PIPE</strong> listener adapter</li>
<li><strong>NET.MSMQ</strong> listener adapter<img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-17%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-17(en-us,MSDN.10).gif" /></li>
</ul>
<p><strong>Figure 5-17. Activation of worker processes with WAS for an HTTP request</strong></p>
<p>When the listener adapters start, they register themselves with WAS and receive the WAS/IIS configuration for their specific protocols. In this way, the listener adapters are aware of the sites and applications they should support. Each listener adapter then starts listening on the appropriate ports provided with the configuration, so it can dispatch the requests coming in to the appropriate application.</p>
<p>As soon as the first request comes in, the listener adapter will call WAS to activate the worker process, including a managed .NET application domain for the specific application for which the request is destined.</p>
<p>The request is then handed over to the so-called application domain protocol handler inside the worker process to handle the request and return the response to the client. It doesn&#8217;t matter whether the request is a WCF service request, an ASP.NET request, or any other request for IIS 7.0. The activation process is created to enable worker processes to start when requests come in.</p>
<p>To start the WCF <strong>ServiceHost</strong> inside the application domain, the application domain protocol handler must call the static method called <strong>EnsureServiceAvailable</strong>. That method is protocol-agnostic and activates the entire service, including all endpoints and transports (not only the transport for the protocol handler that calls the method).</p>
<blockquote>
<div><strong>Note</strong> Inside the listener adapters and protocol handlers, some true magic is happening for HTTP and TCP in particular. Sockets are opened inside the listener adapters hosted in a separate process. Then, when the first request comes in, the socket is actually handed over from the listener adapter to the application domain protocol handler to be able to handle the first request and any subsequent requests!</div>
</blockquote>
<h3>Hosting Options</h3>
<p>In the previous section of this chapter, you learned the different options you have to host your services. In addition, you learned which business requirements (or nonfunctional requirements) can be covered by which hosting scenario. In general, you can apply a &#8220;Why not IIS?&#8221; approach. What do we mean by that? IIS provides the best match in terms of features, in particular in scenarios where your services are exposing key business functionality on which multiple systems rely. When you choose IIS and then have to choose between IIS 6.0 and IIS 7.0, you should obviously choose the latter because of the new activation features. In scenarios where you need interprocess communication, both WinForms and console applications are viable options. Windows services are essentially the only alternative to IIS and will typically be used when you are building a server product or when you need advanced control over the activation and lifetime of your services.</p>
<p>In the next section, we will go through the options you have to consume your services and what the hosting option means for the consumer side.</p>
<h2>Consuming WCF Services</h2>
<p>In the previous sections, you learned about the different hosting options you have. The chosen hosting scenario can have its influence on the consumer side. You can consume WCF services in several ways. If you are using WCF on the client side, you will be very productive because WCF comes with tools that can generate proxy classes to call WCF services. WCF provides the standards and tools support primarily through SvcUtil.exe. You&#8217;ll use this as the primary metadata interpretation tool. That, in combination with the WCF Framework&#8217;s ability to leverage reflection to interrogate types adorned with the appropriate attributes, makes the generation and use of the WCF Framework less complicated than with existing frameworks. In addition, Visual Studio 2005 comes with easy-to-use features to add service references to your projects and seamlessly generate proxy classes for you.</p>
<p>Essentially, you have the following options:</p>
<ul>
<li>Retrieve the WSDL from the service, and handcraft a proxy to call the service. This is a typical scenario when you don&#8217;t have WCF on the client side. For this scenario, please refer to Chapter 13.</li>
<li>Use the <strong>Add Service Reference</strong> features of Visual Studio 2005, and let it generate a proxy to use in your client.</li>
<li>Use the SvcUtil.exe tool to generate proxy classes.</li>
</ul>
<p>In the following sections, we will go through the latter two options: Visual Studio 2005 and SvcUtil.exe.</p>
<h3>Service Proxies</h3>
<p>A <em>service proxy</em> enables you to work with services in an object-oriented way. Proxy classes abstract the communication model used by the service, so you as a client developer are not directly aware you are talking to a (remote) service. It is as if you are calling local code. The proxy class implements the service interface of the service and thus enables you to call methods on the service interface, as if these are local methods. Proxies are generated for any custom type that is used in the service interface. Listing 5-11 contains pieces of a generated proxy for the <strong>TradeService</strong> service in the QuickReturns Ltd. sample. It illustrates that on the client side a <strong>Quote</strong> is available that maps to the <strong>Quote</strong> object on the server side, although they are distinct classes. The <strong>Quote</strong> object serializes according to the contract so that on the service side it can be serialized into the service-side version of the <strong>Quote</strong> data contract. In addition, you can see the <strong>GetQuote</strong> and <strong>PlaceQuote</strong> methods calling a base class that will eventually make the call across the service boundary by way of the configured transport.</p>
<p><strong>Listing 5-11. Sample generated proxy for the TradeService service</strong></p>
<div id="ctl00_MTCS_main_ctl37_">
<div dir="ltr">
<pre>namespace SimpleClientWithProxy.ExchangeService
{
   [DataContract()]
   <strong>public partial class Quote : object, IExtensibleDataObject</strong>
   {
      // Left out the Quote Datamembers in printed code, see sample
code
   }
}

[GeneratedCode("System.ServiceModel", "3.0.0.0")]
[ServiceContract()]
public interface ITradeService
{
   [
      OperationContract(Action =
"http://tempuri.org/ITradeService/GetQuote",
         ReplyAction =
"http://tempuri.org/ITradeService/GetQuoteResponse")]
   Quote GetQuote(string ticker);

   [
      OperationContract(Action =
"http://tempuri.org/ITradeService/PublishQuote",
         ReplyAction =
"http://tempuri.org/ITradeService/PublishQuoteResponse")]
   void PublishQuote(Quote quote);
}

[GeneratedCode("System.ServiceModel", "3.0.0.0")]
public interface ITradeServiceChannel : ITradeService, IClientChannel
{
}

[GeneratedCode("System.ServiceModel", "3.0.0.0")]
public partial class TradeServiceClient : ClientBase&lt;ITradeService&gt;,
ITradeService
{
   // Left out some constructors in printed code, see sample code

   <strong>public SimpleClientWithProxy.ExchangeService.Quote</strong>
<strong>      GetQuote(string ticker)</strong>
<strong>   {</strong>
<strong>      return base.Channel.GetQuote(ticker);</strong>
<strong>   }</strong>

<strong>   public void PublishQuote(</strong>
<strong>      SimpleClientWithProxy.ExchangeService.Quote quote)</strong>
<strong>   {</strong>
<strong>      base.Channel.PublishQuote(quote);</strong>
<strong>   }</strong>
}</pre>
</div>
</div>
<h3>Using Visual Studio 2005</h3>
<p>Similar to ASP.NET proxy creation, if you right-click the project from the IDE, you&#8217;ll see three options for adding references, as shown in Figure 5-18.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-18%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-18(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-18. Adding a reference to a WCF service</strong></p>
<p>The option you&#8217;re looking for is <strong>Add Service Reference</strong>. This menu option is a wrapper around the SvcUtil.exe utility (which is explained in the next section), actually spawning a process with the necessary parameters. Once you&#8217;ve selected <strong>Add Service Reference</strong>, you&#8217;ll see the dialog box that is shown in Figure 5-19.</p>
<p><img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-19%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-19(en-us,MSDN.10).gif" /></p>
<p><strong>Figure 5-19. Add Service Reference dialog box</strong></p>
<p>Once you&#8217;ve clicked <strong>OK</strong> in the dialog box, the add-in spawns SvcUtil.exe, generating the necessary proxy class and the required configuration file (or modifying it) and adding the necessary references to the project. The project&#8217;s references will now list the WCF assemblies.</p>
<blockquote>
<div><strong>Note</strong> For this to work, you have to have the Windows <strong>ServiceHost</strong> running or change the URL to point to any of the services hosted in IIS (a URL pointing to any of the .svc files).</div>
</blockquote>
<p>You&#8217;re now ready to program your first service call in your service tier. The example solution file has been modified in the following ways, to help you review the code:</p>
<ul>
<li><strong>Set Startup Projects</strong> on the solution has multiple projects selected.</li>
<li>The <strong>ExchangeServiceIISHost</strong> Web project has <strong>Use dynamic ports</strong> set to false and a hard-coded setting for <strong>Port Number</strong>.</li>
</ul>
<p>A brief explanation of the objects added to the project is necessary. During the SvcUtil.exe (<strong>Add Service Reference</strong>) call, we added the following items and references to the project automatically. Some are merely to aid the Visual Studio integration; others are required for the direct use of the service through the proxy.</p>
<ul>
<li><em>Service references</em>: Within this folder, we added two items. First, a &#8220;map&#8221; file provides support for the generation and regeneration of the proxy through the Visual Studio add-in. Second, ExchangeService.cs represents the concrete proxy-class implementation that leverages the namespace <strong>System.ServiceModel</strong> to provide a simple integration class.</li>
<li><em>Configuration</em>: The second item is the App.config file. An App.config file (automatically renamed during the Visual Studio build process to <strong>&lt;assembly name&gt;.config</strong>) provides the runtime WCF configuration parameters. What you will notice if you peek inside this file is a tremendous amount of settings, many of which are either defaulted or superfluous. A general approach is to generate the file and then manage the file using the WCF SvcConfigEditor.exe editor utility. This utility is located in the Windows SDK Bin directory. You can also find it in the <strong>Visual Studio 2005 Tools</strong> menu. Figure 5-20 shows the implementation of the tool.<img src="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-20%28en-us,MSDN.10%29.gif" alt="Bb332338.wcf_hosting_and_consuming_figure_5-20(en-us,MSDN.10).gif" /></li>
</ul>
<p><strong>Figure 5-20. SvcConfigEditor.exe</strong></p>
<p>As you can see from the <strong>SvcConfigEditor.exe</strong> screen in Figure 5-20, you can manage a tremendous amount of detailed properties through configuration. This is one of the greatest strengths of WCF: the ability to control many aspects of an implementation without affecting the core service implementation. The concept that a service implementation doesn&#8217;t need to change in order to migrate from an HTTP-based protocol to another message-oriented one is an example. To get more information about the features of the tool, refer to Chapter 3, Chapter 6 of this book, or the MSDN help.</p>
<h3>Command-Line Implementation</h3>
<p>An alternative method is to leverage the <strong>SvcUtil.exe</strong> utility directly, instead of the Visual Studio add-in. Again, the Visual Studio add-in calls the <strong>SvcUtil.exe</strong>, with parameters, to generate the proxy when executed directly from within Visual Studio. You can see the command line and results of that command by viewing the Output window and setting the <strong>Show output</strong> in the drop-down list to <strong>Service Reference</strong>.</p>
<p>To generate manually, choose the CMD window by selecting <strong>Start</strong> | <strong>All Programs</strong> | <strong>Microsoft Windows SDK</strong> | <strong>CMD</strong>. This command prompt is useful because its path is set to the binary directory where the SDK tools and utilities are located.</p>
<p>You&#8217;ll use the <strong>SvcUtil.exe</strong> command-line tool to generate two outputs that could be used in the <strong>SimpleClientWithProxy</strong> project. However, the sample code that comes with this chapter used the <strong>Add Service Reference</strong> method described in the previous section. The steps described here explain how to generate the same outputs as <strong>Add Service Reference</strong>. The output files it generates are the client proxy source code file and the application configuration file. These files are then merged into the client project. The <strong>SvcUtil.exe</strong> can generate both. For this example, the following command (it is all a single line, despite what&#8217;s shown here) produces both a proxy class and a configuration file:</p>
<p><strong>Listing 5-12. Command for producing both proxy class and configuration file</strong></p>
<div id="ctl00_MTCS_main_ctl41_">
<div dir="ltr">
<pre>svcutil /config:app.config /out:"ExchangeService.cs" /language:csharp
/n:*,
SimpleClientWithProxy.ExchangeService
"http://localhost/ExchangeService/?
ExchangeService.svc"</pre>
</div>
</div>
<blockquote>
<div><strong>CAUTION</strong> For this to work, you need a running version of the Windows <strong>ServiceHost</strong>, or you have to change the URL to point to any of the services hosted in IIS (a URL pointing to any of the .svc files discussed in this chapter). In addition, your service requires the <strong>metadataexchange</strong> endpoint, as described in Chapter 3. The code that comes with this chapter has the <strong>metadataexchange</strong> endpoint configured, but it is left out of the inline code in this chapter!</div>
</blockquote>
<p>The command is fairly self-explanatory. The <strong>/n</strong> switch indicates under which namespace the generated proxy class should fall. The last parameter is the URL of the service endpoint where schema information can be found. Note that the <strong>?wsdl</strong> can be replaced by <strong>?mex</strong>, because SvcUtil.exe supports both methods of discovery. Further help is available by executing <strong>svcutil.exe /?</strong> from the command prompt.</p>
<p>The next step is to take the output files ExchangeService.cs and App.config and merge them into the project. You can just add the first file, ExchangeService.cs, directly to the project by choosing <strong>Add Existing Item</strong> from the<strong>Project</strong> menu in Visual Studio 2005.</p>
<p>You must add the second file as an application configuration (App.config) file to the project. If the project does not already have an App.config file, you can add it by again choosing <strong>Add Existing Item</strong> from the <strong>Project</strong> menu. If there is already an existing App.config, you must merge the section <strong>system.serviceModel</strong>, ensuring you take all the appropriate child elements.</p>
<h2>Conclusion</h2>
<p>Now that you know all about your alternatives in terms of hosting, you are able to build WCF applications and host them anywhere you like. In addition, you are now able to explain the benefits of hosting in the most recent environment available, IIS 7.0 on Windows Vista or Windows Server code name &#8220;Longhorn&#8221; in combination with WAS.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnettrick.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnettrick.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnettrick.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnettrick.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnettrick.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnettrick.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnettrick.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnettrick.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnettrick.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnettrick.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnettrick.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnettrick.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnettrick.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnettrick.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnettrick.wordpress.com&amp;blog=10970746&amp;post=4&amp;subd=dotnettrick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnettrick.wordpress.com/2009/12/17/hosting-and-consuming-wcf-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba17c0a39f33d8a281650547aeddb52?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">letter2sanjay1</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-1%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-1(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-2%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-2(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-3%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-3(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-4%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-4(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-5%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-5(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-6%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-6(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-7%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-7(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-8%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-8(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-9%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-9(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-10%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-10(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-11%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-11(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-12%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-12(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-13%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-13(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-14%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-14(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-15%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-15(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-16%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-16(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-17%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-17(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-18%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-18(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-19%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-19(en-us,MSDN.10).gif</media:title>
		</media:content>

		<media:content url="http://i.msdn.microsoft.com/Bb332338.wcf_hosting_and_consuming_figure_5-20%28en-us,MSDN.10%29.gif" medium="image">
			<media:title type="html">Bb332338.wcf_hosting_and_consuming_figure_5-20(en-us,MSDN.10).gif</media:title>
		</media:content>
	</item>
		<item>
		<title>Polymorphism in C#</title>
		<link>http://dotnettrick.wordpress.com/2009/12/15/polymorphism-in-c/</link>
		<comments>http://dotnettrick.wordpress.com/2009/12/15/polymorphism-in-c/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 16:30:45 +0000</pubDate>
		<dc:creator>letter2sanjay1</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://dotnettrick.wordpress.com/2009/12/15/polymorphism-in-c/</guid>
		<description><![CDATA[This lesson teaches about Polymorphism in C#. Our objectives are as follows: * Learn What Polymorphism Is. * Implement a Virtual Method. * Override a Virtual Method. * Use Polymorphism in a Program. Another primary concept of object-oriented programming is Polymorphism. It allows you to invoke derived class methods through a base class reference during [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnettrick.wordpress.com&amp;blog=10970746&amp;post=3&amp;subd=dotnettrick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> This lesson teaches about Polymorphism in C#. Our objectives are as follows:</p>
<p>    * Learn What Polymorphism Is.<br />
    * Implement a Virtual Method.<br />
    * Override a Virtual Method.<br />
    * Use Polymorphism in a Program.</p>
<p>Another primary concept of object-oriented programming is Polymorphism. It allows you to invoke derived class methods through a base class reference during run-time. This is handy when you need to assign a group of objects to an array and then invoke each of their methods. They won&#8217;t necessarily have to be the same object type. However, if they&#8217;re related by inheritance, you can add them to the array as the inherited type. Then if they all share the same method name, that method of each object can be invoked. This lesson will show you how to accomplish this.<br />
Listing 9-1. A Base Class With a Virtual Method: DrawingObject.cs</p>
<p>using System;</p>
<p>public class DrawingObject<br />
{<br />
    public virtual void Draw()<br />
    {<br />
        Console.WriteLine(&#8220;I&#8217;m just a generic drawing object.&#8221;);<br />
    }<br />
}</p>
<p>Listing 9-1 shows the DrawingObject class. This will be the base class for other objects to inherit from. It has a single method named Draw(). The Draw() method has a virtual modifier. The virtual modifier indicates to derived classes that they can override this method. The Draw() method of the DrawingObject class performs a single action of printing the statement, &#8220;I&#8217;m just a generic drawing object.&#8221;, to the console.<br />
Listing 9-2. Derived Classes With Override Methods: Line.cs, Circle.cs, and Square.cs</p>
<p>using System;</p>
<p>public class Line : DrawingObject<br />
{<br />
    public override void Draw()<br />
    {<br />
        Console.WriteLine(&#8220;I&#8217;m a Line.&#8221;);<br />
    }<br />
}</p>
<p>public class Circle : DrawingObject<br />
{<br />
    public override void Draw()<br />
    {<br />
        Console.WriteLine(&#8220;I&#8217;m a Circle.&#8221;);<br />
    }<br />
}</p>
<p>public class Square : DrawingObject<br />
{<br />
    public override void Draw()<br />
    {<br />
        Console.WriteLine(&#8220;I&#8217;m a Square.&#8221;);<br />
    }<br />
}</p>
<p>Listing 9-2 shows three classes. These classes inherit the DrawingObject class. Each class has a Draw() method and each Draw() method has an override modifier. The override modifier allows a method to override the virtual method of its base class at run-time. The override will happen only if the class is referenced through a base class reference. Overriding methods must have the same signature, name and parameters, as the virtual base class method it is overriding.<br />
Listing 9-3. Program Implementing Polymorphism: DrawDemo.cs</p>
<p>using System;</p>
<p>public class DrawDemo<br />
{<br />
    public static int Main( )<br />
    {<br />
        DrawingObject[] dObj = new DrawingObject[4];</p>
<p>        dObj[0] = new Line();<br />
        dObj[1] = new Circle();<br />
        dObj[2] = new Square();<br />
        dObj[3] = new DrawingObject();</p>
<p>        foreach (DrawingObject drawObj in dObj)<br />
        {<br />
            drawObj.Draw();<br />
        }</p>
<p>        return 0;<br />
    }<br />
}</p>
<p>Listing 9-3 shows a program that uses the classes defined in Listing 9-1 and Listing 9-2. This program implements polymorphism. In the Main() method of the DrawDemo class, there is an array being created. The type of object in this array is the DrawingObject class. The array is named dObj and is being initialized to hold four objects of type DrawingObject.</p>
<p>Next the dObj array is initialized. Because of their inheritance relationship with the DrawingObject class, the Line, Circle, and Square classes can be assigned to the dObj array. Without this capability, you would have to create an array for each type. Inheritance allows derived objects to act like their base class, which saves work.</p>
<p>After the array is initialized, there is a foreach loop that looks at each element of the array. Within the foreach loop the Draw() method is invoked on each element of the dObj array. Because of polymorphism, the run-time type of each object is invoked. The type of the reference object from the dObj array is a DrawingObject. However, that doesn&#8217;t matter because the derived classes override the virtual Draw() method of the DrawingObject class. This makes the overriden Draw() methods of the derived classes execute when the Draw() method is called using the DrawingObject base class reference from the dObj array. Here&#8217;s what the output looks like:</p>
<p>Output:</p>
<p>        I&#8217;m a Line.<br />
        I&#8217;m a Circle.<br />
        I&#8217;m a Square.<br />
        I&#8217;m just a generic drawing object.</p>
<p>The override Draw() method of each derived class executes as shown in the DrawDemo program. The last line is from the virtual Draw() method of the DrawingObject class. This is because the actual run-time type of the fourth array element was a DrawingObject object.</p>
<p>The code in this lesson can be compiled with the following command line:</p>
<p>    csc DrawDemo.cs DrawingObject.cs Circle.cs Line.cs Square.cs</p>
<p>It will create the file DrawDemo.exe, which defaulted to the name of the first file on the command line.<br />
Summary</p>
<p>You should now have a basic understanding of polymorphism. You know how to define a virtual method. You can implement a derived class method that overrides a virtual method. This relationship between virtual methods and the derived class methods that override them enables polymorphism. This lesson showed how to use this relationship between classes to implement polymorphism in a program.</p>
<p>I invite you to return for Lesson 10: Properties.</p>
<p>Your feedback and constructive contributions are welcome.  Please feel free to contact me for feedback or comments you may have about this lesson.</p>
<p>Feedback</p>
<p>I like this site and want to support it! </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnettrick.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnettrick.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnettrick.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnettrick.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnettrick.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnettrick.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnettrick.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnettrick.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnettrick.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnettrick.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnettrick.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnettrick.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnettrick.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnettrick.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnettrick.wordpress.com&amp;blog=10970746&amp;post=3&amp;subd=dotnettrick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnettrick.wordpress.com/2009/12/15/polymorphism-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba17c0a39f33d8a281650547aeddb52?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">letter2sanjay1</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello world!</title>
		<link>http://dotnettrick.wordpress.com/2009/12/15/hello-world/</link>
		<comments>http://dotnettrick.wordpress.com/2009/12/15/hello-world/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 16:26:22 +0000</pubDate>
		<dc:creator>letter2sanjay1</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnettrick.wordpress.com&amp;blog=10970746&amp;post=1&amp;subd=dotnettrick&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to <a href="http://wordpress.com/">WordPress.com</a>. This is your first post. Edit or delete it and start blogging!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/dotnettrick.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dotnettrick.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/dotnettrick.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/dotnettrick.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/dotnettrick.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/dotnettrick.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/dotnettrick.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/dotnettrick.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/dotnettrick.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/dotnettrick.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/dotnettrick.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/dotnettrick.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/dotnettrick.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/dotnettrick.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=dotnettrick.wordpress.com&amp;blog=10970746&amp;post=1&amp;subd=dotnettrick&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://dotnettrick.wordpress.com/2009/12/15/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0ba17c0a39f33d8a281650547aeddb52?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">letter2sanjay1</media:title>
		</media:content>
	</item>
	</channel>
</rss>
