<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Bashmohandes (Mohamed Elsherif)</title><subtitle type="html">If Debuging is fixing bugs, so Coding is making new ones</subtitle><id>http://blogs.msdn.com/b/bashmohandes/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/bashmohandes/atom.aspx" /><generator uri="http://telligent.com" version="5.6.583.17018">Telligent Community 5.6.583.17018 (Build: 5.6.583.17018)</generator><updated>2006-05-17T01:20:00Z</updated><entry><title>Microsoft Maren, Write Arabic in English letter anywhere you like</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2009/06/30/microsoft-maren-write-arabic-in-english-letter-anywhere-you-like.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2009/06/30/microsoft-maren-write-arabic-in-english-letter-anywhere-you-like.aspx</id><published>2009-06-30T19:41:00Z</published><updated>2009-06-30T19:41:00Z</updated><content type="html">
&lt;p&gt;By&lt;i&gt; Mostafa Ashour&lt;/i&gt;, PM of Maren Team&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;span style="color: rgb(38, 38, 38);"&gt;&lt;font face="Calibri"&gt;&lt;font size="3"&gt;Dear All,&lt;o:p&gt;&lt;/o:p&gt;&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;span style="color: rgb(38, 38, 38);"&gt;&lt;o:p&gt;&lt;font size="3" face="Calibri"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;font face="Calibri"&gt;&lt;font size="3"&gt;&lt;span style="color: rgb(38, 38, 38);"&gt;&lt;img src="http://www.microsoft.com/middleeast/egypt/cmic/maren/images/maren-logo.png" style="width: 86px; height: 86px;" mce_src="http://www.microsoft.com/middleeast/egypt/cmic/maren/images/maren-logo.png" align="right" width="86" height="86"&gt;We’re pleased to announce that today &lt;/span&gt;the Cairo Microsoft Innovation Center (CMIC) is releasing Microsoft Maren&lt;span style="color: rgb(38, 38, 38);"&gt;, &lt;/span&gt;a Windows extension that allows you to type Arabic in Roman characters and have it converted on the fly to Arabic script. &amp;nbsp;Maren integrates seamlessly with Windows and works in most Windows applications and websites.&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;o:p&gt;&lt;font size="3" face="Calibri"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;font size="3" face="Calibri"&gt;We are inviting you to download and install Maren from: &lt;/font&gt;&lt;a href="http://www.getmaren.com/"&gt;&lt;font size="3" face="Calibri"&gt;www.GetMaren.com&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;o:p&gt;&lt;font size="3" face="Calibri"&gt;&lt;/font&gt;&lt;/o:p&gt;&amp;nbsp;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;font face="Calibri"&gt;&lt;font size="3"&gt;&lt;span style="color: rgb(38, 38, 38);"&gt;Email or &lt;/span&gt;IM &lt;span style="color: rgb(38, 38, 38);"&gt;a &lt;/span&gt;friend&lt;span style="color: rgb(38, 38, 38);"&gt;. C&lt;/span&gt;omment on &lt;span style="color: rgb(38, 38, 38);"&gt;a photo. Search the web. Write a document. Blog. Keep a to do list. &lt;/span&gt;Maren &lt;span style="color: rgb(38, 38, 38);"&gt;makes it easier &lt;/span&gt;to &lt;span style="color: rgb(38, 38, 38);"&gt;complete many day to day tasks &lt;/span&gt;in Arabic&lt;span style="color: rgb(38, 38, 38);"&gt; and using the applications you use today for accomplishing these tasks. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;span style="color: rgb(38, 38, 38);"&gt;&lt;o:p&gt;&lt;font size="3" face="Calibri"&gt;&amp;nbsp;&lt;/font&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;font face="Calibri"&gt;&lt;font size="3"&gt;&lt;span style="color: rgb(38, 38, 38);"&gt;So please help us out and spread the word&lt;/span&gt;:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;" class="MsoListParagraph"&gt;&lt;span style="font-family: Symbol;"&gt;&lt;span style=""&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span dir="ltr"&gt;&lt;/span&gt;&lt;font face="Calibri"&gt;&lt;font size="3"&gt;Tell people about &lt;span style="color: rgb(38, 38, 38);"&gt;&lt;a href="http://www.getmaren.com/"&gt;GetMaren.com&lt;/a&gt;&lt;/span&gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;" class="MsoListParagraph"&gt;&lt;span style="font-family: Symbol;"&gt;&lt;span style=""&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span dir="ltr"&gt;&lt;/span&gt;&lt;font size="3" face="Calibri"&gt;Forward this email to your friends and family&lt;/font&gt;&lt;/p&gt;

&lt;p style="margin: 0in 0in 0pt 0.25in; text-indent: -0.25in;" class="MsoListParagraph"&gt;&lt;span style="font-family: Symbol;"&gt;&lt;span style=""&gt;&lt;font size="3"&gt;·&lt;/font&gt;&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span dir="ltr"&gt;&lt;/span&gt;&lt;font size="3" face="Calibri"&gt;Join the &lt;/font&gt;&lt;a href="http://www.facebook.com/group.php?gid=98514073667"&gt;&lt;span style="color: windowtext;"&gt;&lt;font size="3" face="Calibri"&gt;Facebook&lt;/font&gt;&lt;/span&gt;&lt;/a&gt;&lt;font size="3" face="Calibri"&gt; group&lt;/font&gt;&lt;/p&gt;

&lt;p mce_keep="true"&gt;&lt;a href="http://download.microsoft.com/download/E/4/D/E4D21001-54C5-4A1E-977D-5FBC28B32BAF/MicrosoftMaren.msi" mce_href="http://download.microsoft.com/download/E/4/D/E4D21001-54C5-4A1E-977D-5FBC28B32BAF/MicrosoftMaren.msi"&gt;&lt;img src="http://www.microsoft.com/middleeast/egypt/cmic/maren/images/downlaod.png" style="width: 165px; height: 41px;" mce_src="http://www.microsoft.com/middleeast/egypt/cmic/maren/images/downlaod.png" align="absmiddle" border="0" width="165" height="41"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9809804" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="CMIC" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/CMIC/" /><category term="Arabic" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Arabic/" /></entry><entry><title>Windows 7 RC downloads will end August 15th</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2009/06/23/windows-7-rc-downloads-will-end-august-15th.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2009/06/23/windows-7-rc-downloads-will-end-august-15th.aspx</id><published>2009-06-23T19:10:00Z</published><updated>2009-06-23T19:10:00Z</updated><content type="html">&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;From Windows Team Blog post at &lt;/FONT&gt;&lt;A href="http://windowsteamblog.com/blogs/springboard/default.aspx" mce_href="http://windowsteamblog.com/blogs/springboard/default.aspx"&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;http://windowsteamblog.com/blogs/springboard/default.aspx&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3 face=Calibri&gt; &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN" lang=EN&gt;&lt;FONT size=3 face=Calibri&gt;“Still on the Windows 7 Beta,? You need to move to the RC &lt;B&gt;&lt;I&gt;&lt;U&gt;and fast&lt;/U&gt;&lt;/I&gt;&lt;/B&gt;. Starting July 1&lt;SUP&gt;st&lt;/SUP&gt;, the Beta will start to reboot every 2 hrs and expire Aug 1&lt;SUP&gt;st&lt;/SUP&gt;. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-ansi-language: EN" lang=EN&gt;Want to download the RC? &lt;B&gt;&lt;I&gt;. The RC download program closes August 15th.&lt;/I&gt;&lt;/B&gt; After that, you won’t be able to get the download, but you &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt"&gt;can still install the RC and get a key if you need one. (To get a key, just go to the &lt;U&gt;&lt;SPAN style="COLOR: #00b0f0"&gt;&lt;A href="http://www.microsoft.com/springboard" mce_href="http://www.microsoft.com/springboard"&gt;&lt;SPAN style="COLOR: #00b0f0"&gt;Downloads&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/U&gt; page and follow the instructions&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN" lang=EN&gt;&lt;FONT size=3&gt;&lt;FONT face="Times New Roman"&gt;.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-ansi-language: EN" lang=EN&gt;If you’re using the Windows 7 Release Candidate, we hope you like what you see. Let us know -- go to &lt;U&gt;&lt;SPAN style="COLOR: #00b0f0"&gt;&lt;A href="http://input.microsoft.com/" mce_href="http://input.microsoft.com/"&gt;&lt;SPAN style="COLOR: #00b0f0; mso-ansi-language: EN-US" lang=EN-US&gt;http://input.microsoft.com&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/U&gt; and tell us what you think. You’ll be able to give feedback on various aspects of the operating system.”&amp;nbsp;&lt;/SPAN&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9799695" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="Windows" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Windows/" /></entry><entry><title>Microsoft to ship &amp; support jQuery</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/09/28/microsoft-to-ship-support-jquery.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/09/28/microsoft-to-ship-support-jquery.aspx</id><published>2008-09-28T23:57:23Z</published><updated>2008-09-28T23:57:23Z</updated><content type="html">&lt;p&gt;A fresh announcement from ScottGu today, that Microsoft will be shipping jQuery (the light weight javascript library) in the long term with Visual Studio as well as shipping it in the short term with the next versions of Microsoft ASP.net MVC.&lt;/p&gt;  &lt;p&gt;Microsoft also is going to develop new controls on top of jQuery, not only this but also full support for jQuery, which mean enterprises can open cases on Microsoft PSS for jQuery.&lt;/p&gt;  &lt;p&gt;Great news, and very nice move&lt;/p&gt;  &lt;p&gt;Here are some more details from &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/09/28/jquery-and-microsoft.aspx"&gt;ScottGu&lt;/a&gt;, &lt;a href="http://www.hanselman.com/blog/jQueryToShipWithASPNETMVCAndVisualStudio.aspx"&gt;Scott Henselman&lt;/a&gt; and &lt;a href="http://jquery.com/blog/2008/09/28/jquery-microsoft-nokia/"&gt;jQuery&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8968189" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="News" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/News/" /><category term="Microsoft" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Microsoft/" /><category term="ASP.net" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/ASP-net/" /><category term="javascript" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/javascript/" /></entry><entry><title>I'm a PC in MCDC</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/09/26/i-m-a-pc-in-mcdc.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/09/26/i-m-a-pc-in-mcdc.aspx</id><published>2008-09-27T02:59:00Z</published><updated>2008-09-27T02:59:00Z</updated><content type="html">&lt;p&gt;&lt;img src="http://farm4.static.flickr.com/3238/2890385819_f03a868f3c.jpg?v=0" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8967204" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="MCDC" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/MCDC/" /></entry><entry><title>I’m a PC, Do you have a problem with that?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/09/21/i-m-a-pc-do-you-have-a-problem-with-that.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/09/21/i-m-a-pc-do-you-have-a-problem-with-that.aspx</id><published>2008-09-21T10:30:00Z</published><updated>2008-09-21T10:30:00Z</updated><content type="html">&lt;p&gt;I am a PC guy, I always was, for me PC gives more freedom, you can do whatever you like, build the craziest machine you think it is good for you, and you will never be over priced, with PC you are always in control, if you want to add more capacity, just go and buy a new hard drive, if you need more gaming capabilities upgrade your display adapter, more memory, get a new memory stick, as simple as this, you can make your machine evolves easily with your needs, if you want your pc to become a business machine you can, a gaming platform you can, a parent machine you can, you can find a pc from $100 to thousands of dollars depending on your needs, and for sure you can have fun building your own, I built a lot for me and my friends and it is always fun.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px auto; padding-left: 0px; width: 425px; padding-right: 0px; display: block; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:3975e8d9-b308-40a2-aa91-4a5e468f2d55" class="wlWriterEditableSmartContent"&gt;&lt;div id="957113a6-b7c5-43a5-b305-82fbeae90aed" style="margin: 0px; padding: 0px; display: inline;"&gt;&lt;div&gt;&lt;a href="http://www.youtube.com/watch?v=7hhVjSbV_oQ&amp;amp;hl=en&amp;amp;fs=1" target="_new"&gt;&lt;img src="https://blogs.msdn.com/blogfiles/bashmohandes/WindowsLiveWriter/ImaPCDoyouhaveaproblemwiththat_1E/videof209bd6cdc02.jpg" style="border-style: none" galleryimg="no" onload="var downlevelDiv = document.getElementById('957113a6-b7c5-43a5-b305-82fbeae90aed'); downlevelDiv.innerHTML = &amp;quot;&amp;lt;div&amp;gt;&amp;lt;object width=\&amp;quot;425\&amp;quot; height=\&amp;quot;355\&amp;quot;&amp;gt;&amp;lt;param name=\&amp;quot;movie\&amp;quot; value=\&amp;quot;http://www.youtube.com/v/7hhVjSbV_oQ&amp;amp;hl=en&amp;amp;fs=1&amp;amp;hl=en\&amp;quot;&amp;gt;&amp;lt;\/param&amp;gt;&amp;lt;embed src=\&amp;quot;http://www.youtube.com/v/7hhVjSbV_oQ&amp;amp;hl=en&amp;amp;fs=1&amp;amp;hl=en\&amp;quot; type=\&amp;quot;application/x-shockwave-flash\&amp;quot; width=\&amp;quot;425\&amp;quot; height=\&amp;quot;355\&amp;quot;&amp;gt;&amp;lt;\/embed&amp;gt;&amp;lt;\/object&amp;gt;&amp;lt;\/div&amp;gt;&amp;quot;;" alt=""&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="clear:both;font-size:.8em;"&gt;I'm PC, are you?&lt;/div&gt;&lt;/div&gt;  &lt;p&gt;If you don’t like to build a pc, and prefer to buy it from a vendor, you still have a lot of choices, Dell, Toshiba, IBM, HP, Sony, Lenovo, … you name it, and every vendor has a great number of choices for you to choose from, and here are some of my favorite desktop &amp;amp; notebooks&lt;/p&gt;  &lt;p&gt;First check out these fancy All-in-one PC’s from Dell,Hp and Sony&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="400" align="center"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="201"&gt;&lt;img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://images.bestbuy.com/BestBuy_US/images/products/8647/8647921cv2a.jpg" width="240" height="228" /&gt;&lt;/td&gt;        &lt;td valign="top" width="199"&gt;&lt;img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://images.bestbuy.com/BestBuy_US/images/products/8882/8882925cv7a.jpg" width="240" height="227" /&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="201"&gt;         &lt;h3 align="center"&gt;Dell - XPS One E4500 All-in-One&lt;/h3&gt;       &lt;/td&gt;        &lt;td valign="top" width="199"&gt;         &lt;h3 align="center"&gt;HP - TouchSmart All-In-One Desktop&lt;/h3&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="201"&gt;&lt;img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://www.krunkerhome.com/wp-content/uploads/2006/08/WindowsLiveWriter/SonyVAIOAllinOneDesktopPCVGCLS1_B18/Sony All-in-One Desktop PC VGC-LS1[3].jpg" width="224" height="240" /&gt;&lt;/td&gt;        &lt;td valign="top" width="199"&gt;&lt;img src="http://sonybrands.com/wp-content/uploads/2008/09/sony_vaio_js_1-300x253.jpg" width="240" height="202" /&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="201"&gt;         &lt;h3 align="center"&gt;&lt;strong&gt;Sony – All-in-one Desktop&lt;/strong&gt;&lt;/h3&gt;       &lt;/td&gt;        &lt;td valign="top" width="199"&gt;         &lt;h3 align="center"&gt;VAIO JS Series Desktop PC&lt;/h3&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;And check these amazing notebooks&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="400" align="center"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;&lt;img src="http://www.prix-ordi.com/ordinateur/sony-vaio-vgn-fw11zu.jpg" width="240" height="240" /&gt; &lt;/td&gt;        &lt;td valign="top" width="200"&gt;&lt;img src="http://i.dell.com/images/global/products/314x314/xps_m1530_alternate_black_314.jpg" width="240" height="240" /&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;         &lt;h3 align="center"&gt;Sony Vaio FW Series&lt;/h3&gt;       &lt;/td&gt;        &lt;td valign="top" width="200"&gt;         &lt;h3 align="center"&gt;Dell XPS M1530&lt;/h3&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;&lt;img src="http://www.hp.com/hpinfo/newsroom/feature_stories/2008/images/08standout-1.jpg" width="240" height="161" /&gt; &lt;/td&gt;        &lt;td valign="top" width="200"&gt;&lt;img src="http://explore.toshiba.com/images/showcase/satellite-a300-hero.png" width="240" height="159" /&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;         &lt;h3 align="center"&gt;HP HDX Series&lt;/h3&gt;       &lt;/td&gt;        &lt;td valign="top" width="200"&gt;         &lt;h3 align="center"&gt;Toshiba Satellite A300&lt;/h3&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p align="left"&gt; And this is not the whole thing, these are just samples of the choices you have with a PC.&lt;/p&gt;  &lt;p align="left"&gt;I’m a PC, are you? &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8960437" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="News" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/News/" /><category term="Microsoft" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Microsoft/" /></entry><entry><title>Live Mesh, Synchronizing Life</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/09/20/live-mesh-synchronizing-life.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/09/20/live-mesh-synchronizing-life.aspx</id><published>2008-09-20T16:11:46Z</published><updated>2008-09-20T16:11:46Z</updated><content type="html">&lt;p&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" align="left" src="http://www.liveside.net/main/WindowsLiveWriter/LiveMeshitseverythingwetoldyouaboutandal_12839/mesh_thumb.png" width="90" height="84" /&gt; Windows Live has some great products, and you are already using bunch of them, Windows Live Messenger, Windows Live Hotmail, Windows Live Writer, Windows Live Photo Gallery, Windows Live Mail … etc, but the newest and the most interesting one is &lt;strong&gt;Windows Live Mesh.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Windows Live Mesh is simply one of those products that after you use it for couple of days, you find yourself saying “how I used to live before??” it solves so many problems that you used to live with them even though they are annoying.&lt;/p&gt;  &lt;p&gt;With so many devices you deal with today for example (Your home PC, your work PC, your notebook, your Zune, your mom’s MAC, your mobile phone, your kids XBOX, … etc) keeping these devices in sync is very annoying, and simply you can get out of sync, and lose track with which device has the latest version of my documents, spreadsheets, images, files, contacts … etc&lt;/p&gt;  &lt;p&gt;What Live Mesh is proposing, is a very simple elegant and natural solution, you simply need nothing more than what you do now, and you get a completely new experience, Imagine that you have this magic folder on your computer, that when you put anything in it, woooosh it appears in a matter of seconds on all your other devices, not just this, but if you want, your friends devices as well ;)&lt;/p&gt;  &lt;p&gt;This is it, this is exactly what you do, any folder on your PC, MAC, Phone can be turned into this magic folder, with Windows Live Mesh.&lt;/p&gt;  &lt;p&gt;So imagine this concept applies to your most important folders (Your documents, projects, music library, pictures, … whatever), how cool is that!!&lt;/p&gt;  &lt;p&gt;&lt;img style="display: inline; margin-left: 0px; margin-right: 0px" align="right" src="http://i299.photobucket.com/albums/mm315/phanop_photograph/ACCOMPLISHED EMPERORSIP LIVE MESH/0004EMPERORSHIPLiveMesh.png" width="92" height="92" /&gt; Is this the whole thing, simply NO, you can also access your files even if you are not using any of your devices, from any internet device (as long as it has a browser) you can access your online windows live mesh desktop, and access your magic folders, even add some new folders/files to them and everything gets synced in seconds, what about a device that is not connected at the moment, no problem, once it gets connected, it will receive the updates.&lt;/p&gt;  &lt;p&gt;Is this the whole thing, Still NO, it also gives you another amazing feature, you can access any of your devices in the Mesh remotely from the web, so even if you are not around your device, you can connect to it inside the browser, and do whatever you like on it, it is awesome.&lt;/p&gt;  &lt;p&gt;If you like what you read so far, you like this the most, it is completely &lt;font size="5"&gt;Free&lt;/font&gt;.&lt;/p&gt;  &lt;p&gt;Here is a very nice video summarizes what I said earlier&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px auto; padding-left: 0px; width: 425px; padding-right: 0px; display: block; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:396fb7a6-3aef-4986-812d-2dc02519234b" class="wlWriterEditableSmartContent"&gt;&lt;div id="817b15a8-1749-49b1-9c46-e05769652181" style="margin: 0px; padding: 0px; display: inline;"&gt;&lt;div&gt;&lt;a href="http://www.youtube.com/watch?v=-RY-q8k2RRI&amp;amp;hl=en&amp;amp;fs=1" target="_new"&gt;&lt;img src="https://blogs.msdn.com/blogfiles/bashmohandes/WindowsLiveWriter/LiveMeshSynchronizingLife_52AC/video2eabb7eb6c55.jpg" style="border-style: none" galleryimg="no" onload="var downlevelDiv = document.getElementById('817b15a8-1749-49b1-9c46-e05769652181'); downlevelDiv.innerHTML = &amp;quot;&amp;lt;div&amp;gt;&amp;lt;object width=\&amp;quot;425\&amp;quot; height=\&amp;quot;355\&amp;quot;&amp;gt;&amp;lt;param name=\&amp;quot;movie\&amp;quot; value=\&amp;quot;http://www.youtube.com/v/-RY-q8k2RRI&amp;amp;hl=en&amp;amp;fs=1&amp;amp;hl=en\&amp;quot;&amp;gt;&amp;lt;\/param&amp;gt;&amp;lt;embed src=\&amp;quot;http://www.youtube.com/v/-RY-q8k2RRI&amp;amp;hl=en&amp;amp;fs=1&amp;amp;hl=en\&amp;quot; type=\&amp;quot;application/x-shockwave-flash\&amp;quot; width=\&amp;quot;425\&amp;quot; height=\&amp;quot;355\&amp;quot;&amp;gt;&amp;lt;\/embed&amp;gt;&amp;lt;\/object&amp;gt;&amp;lt;\/div&amp;gt;&amp;quot;;" alt=""&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="clear:both;font-size:.8em;"&gt;Windows Live Mesh, Synchronizes Life&lt;/div&gt;&lt;/div&gt;  &lt;p&gt;Now you can start simply by logging in &lt;a href="http://www.mesh.com"&gt;&lt;font size="4"&gt;www.mesh.com&lt;/font&gt;&lt;/a&gt;&amp;#160;&lt;em&gt;cool URI isn’t it ;)&lt;/em&gt; with your windows live ID, and add your devices, and be part of the Mesh, The current CTP supports only Windows XP/Vista, soon it will support Mac &amp;amp; Mobile Phones ;)&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9e5cec52-25fc-4793-8b2b-9b28c17b3dcc" class="wlWriterEditableSmartContent"&gt;LiveJournal Tags: &lt;a href="http://www.livejournal.com/interests.bml?int=News" rel="tag"&gt;News&lt;/a&gt;,&lt;a href="http://www.livejournal.com/interests.bml?int=Live" rel="tag"&gt;Live&lt;/a&gt;,&lt;a href="http://www.livejournal.com/interests.bml?int=Mesh" rel="tag"&gt;Mesh&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8959908" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="News" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/News/" /><category term="Mesh" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Mesh/" /><category term="Windows Live" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Windows+Live/" /></entry><entry><title>Project Astoria is now RTM</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/08/11/project-astoria-is-now-rtm.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/08/11/project-astoria-is-now-rtm.aspx</id><published>2008-08-11T22:01:00Z</published><updated>2008-08-11T22:01:00Z</updated><content type="html">&lt;P&gt;Whohoooo, &lt;A class="" href="http://blogs.msdn.com/astoriateam/archive/2008/08/11/rtm-is-here.aspx" mce_href="http://blogs.msdn.com/astoriateam/archive/2008/08/11/rtm-is-here.aspx"&gt;Astoria is RTM&lt;/A&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8848851" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="News" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/News/" /><category term="Astoria" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Astoria/" /><category term="REST" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/REST/" /></entry><entry><title>C# 4.0 Meet the team</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/07/14/c-4-0-meet-the-team.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/07/14/c-4-0-meet-the-team.aspx</id><published>2008-07-14T19:51:00Z</published><updated>2008-07-14T19:51:00Z</updated><content type="html">
&lt;p&gt;Almost an hour of conversation about C# 4.0 from the (Almost new) C# team, you will be surprised who joined the new C# team which can give you a hint about the future of C#.&lt;/p&gt;&lt;p&gt;C# 4.0 is one of the greatest achievements of MS and it is still proving that with every new release, I can't wait to get my hands on some new bits :)&lt;br&gt;&lt;/p&gt;
&lt;iframe src="http://channel9.msdn.com/posts/Charles/409364/player/" mce_src="http://channel9.msdn.com/posts/Charles/409364/player/" scrolling="no" width="320" frameborder="0" height="325"&gt;&lt;/iframe&gt;&lt;br&gt; &lt;a href="http://channel9.msdn.com/posts/Charles/C-40-Meet-the-Design-Team/" mce_href="http://channel9.msdn.com/posts/Charles/C-40-Meet-the-Design-Team/"&gt;C# 4.0: Meet the Design Team&lt;/a&gt;&lt;br&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8731742" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="C#" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/C_2300_/" /></entry><entry><title>Bill Gates, Looking Back, Moving Ahead</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/06/28/bill-gates-looking-back-moving-ahead.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/06/28/bill-gates-looking-back-moving-ahead.aspx</id><published>2008-06-29T07:04:00Z</published><updated>2008-06-29T07:04:00Z</updated><content type="html">
&lt;p&gt;&lt;img src="http://i.microsoft.com/global/En/us/PublishingImages/Feature%20Panels/BillG_F.jpg" title="Billg moving ahead" alt="Billg moving ahead" mce_src="http://i.microsoft.com/global/En/us/PublishingImages/Feature%20Panels/BillG_F.jpg" align="middle" width="690" height="325"&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;I know you are not waiting for me to know that last Full Time day for Bell Gates was yesterday, however I couldn't help it to write about this great journey that inspired everybody.&lt;/p&gt;

&lt;p&gt;Bill Gates was always the perfect geek, and will always be, he is an inspiration for everybody, inside Microsoft, or outside, even his competitors can't deny his influence on them and how he could give the right vision and direction for the company in the last 3 decades.&lt;/p&gt;

&lt;p&gt;&amp;nbsp;I will try to give you some goodies about Bill Gates, that I personally like&lt;/p&gt;

&lt;p style="font-weight: bold;"&gt;Bill Gates Harvard Speech (Believe me this one is funny :) )&lt;br&gt;&lt;/p&gt;

&lt;object width="425" height="344"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/AP5VIhbJwFs&amp;amp;hl=en"&gt;
&lt;embed src="http://www.youtube.com/v/AP5VIhbJwFs&amp;amp;hl=en" type="application/x-shockwave-flash" width="425" height="344"&gt;&lt;/object&gt;

&lt;p style="font-weight: bold;"&gt;Bill Gates Looking Back, Moving Ahead&lt;/p&gt;

&lt;object width="425" height="344"&gt;
&lt;param name="movie" value="http://www.youtube.com/v/T8XDCilta5k&amp;amp;hl=en"&gt;
&lt;embed src="http://www.youtube.com/v/T8XDCilta5k&amp;amp;hl=en" type="application/x-shockwave-flash" width="425" height="344"&gt;&lt;/object&gt;

&lt;p&gt;&lt;b&gt;Bill Gates in MacWorld in 1997&lt;/b&gt; (The funniest part when Microsoft was planning to help Apple in Java)&lt;/p&gt;
&lt;object width="425" height="344"&gt;&lt;param name="movie" value="http://www.youtube.com/v/WxOp5mBY9IY&amp;amp;hl=en"&gt;&lt;embed src="http://www.youtube.com/v/WxOp5mBY9IY&amp;amp;hl=en" type="application/x-shockwave-flash" width="425" height="344"&gt;&lt;/object&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666088" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="Microsoft" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Microsoft/" /></entry><entry><title>Hello World</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/06/19/hello-world.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/06/19/hello-world.aspx</id><published>2008-06-19T21:53:00Z</published><updated>2008-06-19T21:53:00Z</updated><content type="html">&lt;P&gt;Hey, this is my first blog post for my new blogs :) &lt;/P&gt;
&lt;P mce_keep="true"&gt;I will copy some of my old blog posts that I personally like to this new blog, so you will find it being updated every now and then, keep in touch ;)&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8622732" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="News" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/News/" /></entry><entry><title>My longest two weeks ever</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/05/19/my-longest-two-weeks-ever.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/05/19/my-longest-two-weeks-ever.aspx</id><published>2008-05-20T00:23:00Z</published><updated>2008-05-20T00:23:00Z</updated><content type="html">&lt;P&gt;Hey, It's been a while since my last blog post, I was somehow busy getting married, moving to another country, dealing with tons of paper work, however finally I had a weekend, and I am back to blogging, I have a lot to say, and I think it will be interesting enough for you to keep reading till the end&lt;/P&gt;
&lt;P&gt;So basically this is what I am going to blog about today&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Last days in Cairo 
&lt;LI&gt;Moving to Canada &amp;amp; Vancouver City 
&lt;LI&gt;Microsoft Canada Development Center (MCDC) 
&lt;OL&gt;
&lt;LI&gt;First Days 
&lt;LI&gt;MCDC Cares Day&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;H2&gt;Last days in Cairo&lt;/H2&gt;
&lt;P&gt;The past two weeks started with my wedding arrangement and God, this is very exhausting, lots of stuff to deal with, writing a guest list, however Thanks to Facebook I didn't have to call everybody, and the result I came out of the wedding experience is, my kids whatever their IQ will be, they will have one of two options in their career life, either being a wedding planner or a hair dresser and/or make up artist.&lt;/P&gt;
&lt;P&gt;The wedding was nice, it was a very nice opportunity for me to see everybody before being relocated to Canada, I really thank everyone for showing up that night, I was really proud of my friends.&lt;/P&gt;
&lt;H2&gt;Moving to Canada &amp;amp; Vancouver City&lt;/H2&gt;
&lt;P&gt;Couple of days after my wedding I was in the plane with my wife heading to Vancouver, we had a 20 hours journey from Cairo, we had a connection in London, the flight went smooth and very nice, however my back hurts when I recall sitting for 10 hours from London to Vancouver.&lt;/P&gt;
&lt;P&gt;Once we arrived to Vancouver, we took a cab to our temp house, the first thing I noticed the high-tech cabs, the cab has a GPS with maps for the city, and also a very interesting fare counter, the counter was moving like a stop watch, even when the cab wasn't moving, the counter continues to move, the ride from the Airport to the temp house, which took around 15 mins cost about 27 CAD.&lt;/P&gt;
&lt;P&gt;The city is wonderful, the streets are clean, nice and easy to learn, people are extra friendly, both cars and people are moving according to traffic rules, &lt;EM&gt;this is quite interesting for anyone coming from a country like Egypt :)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The temp house is in a very nice area, &lt;A href="http://maps.google.com/maps/ms?ie=UTF8&amp;amp;hl=en&amp;amp;msa=0&amp;amp;msid=106452306885848120539.00044c4615cc3b99f6258&amp;amp;t=h&amp;amp;z=17" target=_blank mce_href="http://maps.google.com/maps/ms?ie=UTF8&amp;amp;hl=en&amp;amp;msa=0&amp;amp;msid=106452306885848120539.00044c4615cc3b99f6258&amp;amp;t=h&amp;amp;z=17"&gt;Map&lt;/A&gt;, I am in the 29th floor, so I have an amazing view of the sea and the mountains.&lt;/P&gt;
&lt;P&gt;My first couple of days were very hard, because of the electricity here in Vancouver, the problem that the voltage range here is 100~110, while Egypt is 200~220 so many devices I had didn't work, also I found the strange outlet in the wall, which is different from the Egyptian outlets, so all devices like Laptops, Mobiles ... etc went out of charge during the first couple of days, I had to find a store where I can buy some adapters, in these days I felt like stone age, no mobile phones, no computers, no Internet, how could we live 15 years before today, Once I got the adapters I could communicate with my friends who arrived in Vancouver city couple of days before me (Haytham, Mustafa and Abdullah)&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Also a nice tip, when I was changing money from Egypt, CAD was cheaper than USD, in Vancouver, CAD is higher than USD, so I lost some money when I exchanged some USD to CAD here in Vancouver.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Live/Google maps works great in Vancouver, and all Canada area, providing great help for directions and finding addresses, Google Maps though has a nice feature to give direction in public transit, so you can see which busses you'll need to take and at what time.&lt;/P&gt;
&lt;H2&gt;Microsoft Canada Development Center&lt;/H2&gt;
&lt;P align=center&gt;&lt;IMG src="http://farm3.static.flickr.com/2385/2504083019_40386a892d.jpg?v=0" mce_src="http://farm3.static.flickr.com/2385/2504083019_40386a892d.jpg?v=0"&gt; &lt;BR&gt;&lt;EM&gt;In the picture from left, Abdullah, Mostafa and Me&lt;/EM&gt;&lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://farm3.static.flickr.com/2261/2504080939_364a88f51a.jpg?v=0" mce_src="http://farm3.static.flickr.com/2261/2504080939_364a88f51a.jpg?v=0"&gt;&lt;BR&gt;&lt;EM&gt;In the picture from left, Abdullah, Mustafa and Haytham&lt;/EM&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here comes the first day @ Microsoft, the first day started in a park nearby Microsoft, the day started with some introductory sessions about Microsoft Canada, and Microsoft future of Computing, and the future vision of MS.&lt;/P&gt;
&lt;P&gt;After couple of hours we went to MCDC, we had a nice tour around the facility, the place is very amazing, simple and fun, some parts still under construction.&lt;/P&gt;
&lt;P&gt;People there are from everywhere, it is like a small united nations, Egyptians are all over the place and we are increasing, in our batch there was 7 Egyptians out 31 new hires, this is quite nice number.&lt;/P&gt;
&lt;P&gt;Then after the tour we had another session about the needed paperwork, lots of forms to fill, I had to write my name about 50 times later this night when filling in the forms, then we head to our offices.&lt;/P&gt;
&lt;P&gt;My office is in Building 3, Office 1077B, I am sharing the same office room with Mostafa, every dev is using two machines, one for web surfing, email, IM, ... etc and the other for development, the machines are GREAT, I even found people working in triple machine setup according to their work needs.&lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://farm3.static.flickr.com/2091/2504913060_b113fbfa0d.jpg?v=0" mce_src="http://farm3.static.flickr.com/2091/2504913060_b113fbfa0d.jpg?v=0"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the first day my manager called me from Redmond, I IMed the other team mates, I found out that I am the only dev outside Redmond in my team.&lt;/P&gt;
&lt;P&gt;During the first days, we were all busy finishing the paperwork, we didn't start working yet, however in the forth day we had a great experience.&lt;/P&gt;
&lt;H4&gt;MCDC Cares&lt;/H4&gt;
&lt;P&gt;Since our first day, we were asked to join this event, the event called MCDC Cares, is a community work program that Microsoft will help the Richmond city in building a 700ft long boardwalk in Richmond Park, the idea is that this part of the park is very muddy that no visitors can get inside, so Microsoft decided to help in building this boardwalk by providing manpower (150 computer geeks) for a whole day.&lt;/P&gt;
&lt;P&gt;So early on May 15th, all Microsoft Canada Development Center gathered in the cafeteria where Parminder (Par) Singh, the Managing Director of MCDC gave a short speech to everybody&lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://farm4.static.flickr.com/3112/2504913600_e498f05925.jpg?v=0" mce_src="http://farm4.static.flickr.com/3112/2504913600_e498f05925.jpg?v=0"&gt; &lt;BR&gt;&lt;EM&gt;In the picture Parminder Singh&lt;/EM&gt;&lt;/P&gt;
&lt;P align=left&gt;After this we all moved to the park, the park is quite big, it was my first time to actually feel being in the woods, were the trees are very high and land is either very green or very muddy.&lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://farm3.static.flickr.com/2415/2504082181_b8d44c7a28.jpg?v=0" mce_src="http://farm3.static.flickr.com/2415/2504082181_b8d44c7a28.jpg?v=0"&gt; &lt;/P&gt;
&lt;P align=center&gt;In this picture the completed part of the boardwalk we were about to complete, the&amp;nbsp; boardwalk goes very deep into the woods.&lt;/P&gt;
&lt;P align=left&gt;So first things first, we had to move 1500 pieces of wood from the parking area outside the park to the working place deep into the woods, about 800m distance, this part of the job took around 4~5 hours.&lt;/P&gt;
&lt;P align=left&gt;After this phase we had a lunch break and during this break&lt;/P&gt;
&lt;P align=center&gt;&lt;IMG src="http://farm3.static.flickr.com/2240/2504914480_b4e4f17d19.jpg?v=0" mce_src="http://farm3.static.flickr.com/2240/2504914480_b4e4f17d19.jpg?v=0"&gt;&lt;/P&gt;
&lt;P align=left&gt;Then phase 2 started, the phase 2 was to nail the 1500 pieces of wood we moved in phase 1 with 6 nails per piece, so in a period of 3 hours we had to hummer about 9000 nails manually.&lt;/P&gt;
&lt;P align=left&gt;Then we head back to MCDC, very exhausted but very happy with the work we've done, this boardwalk will be there for ages, and this was a very nice opportunity to do something useful.&lt;/P&gt;
&lt;P align=left&gt;In MCDC we had a BBQ party for everyone so the day ended pretty much after the BBQ, then I believe that everybody slept like a baby for more than 9 hours :)&lt;/P&gt;
&lt;P align=left&gt;&lt;A href="http://www.ctvbc.ctv.ca/servlet/an/local/CTVNews/20080107/WhereWeLive/20080107" target=_blank mce_href="http://www.ctvbc.ctv.ca/servlet/an/local/CTVNews/20080107/WhereWeLive/20080107"&gt;Here you can find the TV coverage of MCDC Cares day&lt;/A&gt;&lt;/P&gt;
&lt;P align=left&gt;If you read this line so you survived the whole blog post, thank you for reading this, I will be blogging again &amp;amp; again, so keep in touch :)&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8623171" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="News" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/News/" /><category term="Microsoft" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Microsoft/" /><category term="MCDC" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/MCDC/" /></entry><entry><title>Using WebHttpBinding &amp; JSON Support in WCF</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2008/01/05/using-webhttpbinding-json-support-in-wcf.aspx" /><link rel="enclosure" type="application/x-zip-compressed" length="6683" href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-08-62-61-85/Chat.zip" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2008/01/05/using-webhttpbinding-json-support-in-wcf.aspx</id><published>2008-01-05T22:03:00Z</published><updated>2008-01-05T22:03:00Z</updated><content type="html">&lt;P&gt;I had some cool time working with WCF new features shipped with .net 3.5, one of the most ineteresting and useful features is the JSON support and how easy you can enable the JSON support for your current WCF services by changing the configurations.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Why do we need JSON support?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Well, JSON (JavaScript Object Notation) is very suitable for building ajax based applications for some reasons.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The other popular alternative (XML) requires parsing code in the client side to extract the data from the document, which is not the best thing to do using Javascript. 
&lt;LI&gt;XML documents size are relatively bigger than JSON documents containing the same data&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;To get more info about JSON check &lt;A href="http://www.json.org/" target=_blank mce_href="http://www.json.org/"&gt;here&lt;/A&gt; and &lt;A href="http://en.wikipedia.org/wiki/Json" target=_blank mce_href="http://en.wikipedia.org/wiki/Json"&gt;here&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What WCF offers to support JSON&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;All what you need is doing two things&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Create an end point that uses the new binding (WebHttpBinding) 
&lt;LI&gt;Configure the end point behavior and enabling the WebScript (which will generate a javascript proxy for your service contract and data contracts)&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;This is a sample configuration&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpointBehaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ChatAspNetAjaxBehavior"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;          &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;enableWebScript&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpointBehaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ChatService"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt; &lt;SPAN class=attr&gt;address&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt; &lt;SPAN class=attr&gt;behaviorConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ChatAspNetAjaxBehavior"&lt;/SPAN&gt; &lt;/PRE&gt;&lt;PRE class=alteven&gt;                &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ajaxEndpoint"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="IChat"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;As you can see the endpiont configuration is using the Binding "webHttpBinding" and it is also configured in the behavior tag to enable web script.&lt;/P&gt;
&lt;P&gt;Now the WCF runtime will generate a javascript proxy containing all services and data contracts as javascript classes, we will see an example shortly.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Example: Building a Chat Application using WCF &amp;amp; JSON support&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;It is time for more detailed example, in this example we will develop a small web based chat application using javascript as a client language and WCF as a server side.&lt;/P&gt;
&lt;P&gt;The chat application will be able to do these functionalities&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Register users 
&lt;LI&gt;User logins 
&lt;LI&gt;Retrieve users list 
&lt;LI&gt;Check new messages 
&lt;LI&gt;Send message 
&lt;LI&gt;Log out&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;So let's write down the contract for this service (we will ignore good design practices for the sake of simplicity and will make one service that does both the user management and chatting)&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;[ServiceContract(Namespace = &lt;SPAN class=str&gt;""&lt;/SPAN&gt;)]&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;interface&lt;/SPAN&gt; IChat&lt;/PRE&gt;&lt;PRE class=alt&gt;{&lt;/PRE&gt;&lt;PRE class=alteven&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE class=alt&gt;    User Register(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; username, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; password);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE class=alteven&gt;    User Login(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; username, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; password);&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alteven&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; Call(Guid fromUserId, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; toUsername, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; message);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE class=alteven&gt;    Message[] GetMyMessages(Guid userId);&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alteven&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;bool&lt;/SPAN&gt; SignOut(Guid userId);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;    [OperationContract]&lt;/PRE&gt;&lt;PRE class=alteven&gt;    User[] GetUsers();&lt;/PRE&gt;&lt;PRE class=alt&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is basically how the service contract looks like, we are still missing two data contracts User &amp;amp; Message and here they are.&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;[DataContract]&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; Message&lt;/PRE&gt;&lt;PRE class=alt&gt;{&lt;/PRE&gt;&lt;PRE class=alteven&gt;    [DataMember]&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; Guid ID { get; set; }&lt;/PRE&gt;&lt;PRE class=alteven&gt;    [DataMember]&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; Body { get; set; }&lt;/PRE&gt;&lt;PRE class=alteven&gt;    [DataMember]&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; DateTimeOffset Date { get; set; }&lt;/PRE&gt;&lt;PRE class=alteven&gt;    [DataMember]&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; FromUsername { get; set; }&lt;/PRE&gt;&lt;PRE class=alteven&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; Message()&lt;/PRE&gt;&lt;PRE class=alteven&gt;    {&lt;/PRE&gt;&lt;PRE class=alt&gt;        ID = Guid.NewGuid();&lt;/PRE&gt;&lt;PRE class=alteven&gt;        Date = DateTimeOffset.Now;&lt;/PRE&gt;&lt;PRE class=alt&gt;    }&lt;/PRE&gt;&lt;PRE class=alteven&gt;}&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alteven&gt;[DataContract]&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; User&lt;/PRE&gt;&lt;PRE class=alteven&gt;{&lt;/PRE&gt;&lt;PRE class=alt&gt;    [DataMember]&lt;/PRE&gt;&lt;PRE class=alteven&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; Guid ID { get; set; }&lt;/PRE&gt;&lt;PRE class=alt&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alteven&gt;    [DataMember]&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; Username { get; set; }&lt;/PRE&gt;&lt;PRE class=alteven&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; Password { get; set; }&lt;/PRE&gt;&lt;PRE class=alteven&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE class=alt&gt;    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; User()&lt;/PRE&gt;&lt;PRE class=alteven&gt;    {&lt;/PRE&gt;&lt;PRE class=alt&gt;        ID = Guid.NewGuid();&lt;/PRE&gt;&lt;PRE class=alteven&gt;    }&lt;/PRE&gt;&lt;PRE class=alt&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;The implementation of the service is not very important and the code is attached with the blog entry, basically it saves all the messages and users in static collections, in real life cases the implementation will be different most probably a database is going to be used.&lt;/P&gt;
&lt;P&gt;Now let's start building the client side of the chat application.&lt;/P&gt;
&lt;P&gt;We will be hosting the chat service on IIS so we will create a .svc file &lt;EM&gt;chat.svc&lt;/EM&gt; which will contain one line&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&amp;lt;%@ ServiceHost Language=&lt;SPAN class=str&gt;"C#"&lt;/SPAN&gt; Debug=&lt;SPAN class=str&gt;"true"&lt;/SPAN&gt; Service=&lt;SPAN class=str&gt;"ChatService"&lt;/SPAN&gt; CodeBehind=&lt;SPAN class=str&gt;"~/App_Code/Chat.cs"&lt;/SPAN&gt; %&amp;gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;And this will be the address of our service.&lt;/P&gt;
&lt;P&gt;and then we will place the configuration of the service in web.config&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;1:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;2:&lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;3:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpointBehaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;4:&lt;/SPAN&gt;       &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ChatAspNetAjaxBehavior"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;5:&lt;/SPAN&gt;         &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;enableWebScript&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;6:&lt;/SPAN&gt;       &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behavior&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;7:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpointBehaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;8:&lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;behaviors&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;9:&lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;serviceHostingEnvironment&lt;/SPAN&gt; &lt;SPAN class=attr&gt;aspNetCompatibilityEnabled&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="true"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;10:&lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;11:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ChatService"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;12:&lt;/SPAN&gt;       &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;endpoint&lt;/SPAN&gt; &lt;SPAN class=attr&gt;address&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;=""&lt;/SPAN&gt; &lt;SPAN class=attr&gt;behaviorConfiguration&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ChatAspNetAjaxBehavior"&lt;/SPAN&gt; &lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;13:&lt;/SPAN&gt;         &lt;SPAN class=attr&gt;binding&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="webHttpBinding"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;name&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="ajaxEndpoint"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;contract&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="IChat"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;14:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;service&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;15:&lt;/SPAN&gt;   &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;16:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.serviceModel&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;The configuration is similar to the above one, except for the line #9 which is the serviceHostEnvironment, all what you need to know about this attribute that enabling it will make asp.net treats the WCF service as regular asmx service, for more details about different modes of running WCF services with ASP.net check this &lt;A href="http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx" target=_blank mce_href="http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx"&gt;article&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;We will now create two views&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Login View 
&lt;LI&gt;Chat View&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The login view is basically like this&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://farm3.static.flickr.com/2174/2170036304_ff7f080f9b.jpg?v=0" mce_src="http://farm3.static.flickr.com/2174/2170036304_ff7f080f9b.jpg?v=0"&gt; &lt;/P&gt;
&lt;P&gt;Two text boxes (txtUsername, txtPassword) and two input type buttons for register and login actions&lt;/P&gt;
&lt;P&gt;The Chat View will look like this&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://farm3.static.flickr.com/2248/2169251383_ebbbf28de0.jpg?v=0" mce_src="http://farm3.static.flickr.com/2248/2169251383_ebbbf28de0.jpg?v=0"&gt; &lt;/P&gt;
&lt;P&gt;Which contains two more textboxes (txtToUsername, txtMessage) and a select control containing the current users (slGuests) and a panel that will show the message history (pnlMessageHistory)&lt;/P&gt;
&lt;P&gt;May be it is not the best user interface but it will do the basic things.&lt;/P&gt;
&lt;P&gt;now we will need to add the ScriptManager to the page and add a reference to the wcf service&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;1:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:scriptmanager&lt;/SPAN&gt; &lt;SPAN class=attr&gt;id&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="scrptMgr"&lt;/SPAN&gt; &lt;SPAN class=attr&gt;runat&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="server"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;2:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;3:&lt;/SPAN&gt;         &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:servicereference&lt;/SPAN&gt; &lt;SPAN class=attr&gt;path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="~/Chat.svc"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;4:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;services&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;5:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;asp:scriptmanager&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;This will add a script element with a source pointing to this url &lt;A href="http://[domain]/Chat.svc/js" mce_href="http://[domain]/Chat.svc/js"&gt;http://[domain]/Chat.svc/js&lt;/A&gt; which will download the javascript proxy code.&lt;/P&gt;
&lt;P&gt;We will now do some initialization codes let's see how it looks like...&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;1:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; user;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;2:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; chatService = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; IChat();&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;3:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; guests = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Array();&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;4:&lt;/SPAN&gt; window.onload = &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt;(){&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;5:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; btnRegister = $get(&lt;SPAN class=str&gt;"btnRegister"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;6:&lt;/SPAN&gt;     $addHandler(btnRegister, &lt;SPAN class=str&gt;"click"&lt;/SPAN&gt;, doRegister);&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;7:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let's check line #2, this is the neat part of using WebScript, the IChat class is the generated proxy object for the IChat service contract, and for this application we need only one object so the object is created and initialized globaly.&lt;/P&gt;
&lt;P&gt;Now let's write the register function&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;1:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; doRegister()&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;2:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;3:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; username = $get(&lt;SPAN class=str&gt;"&amp;lt;%=txtUsername.ClientID %&amp;gt;"&lt;/SPAN&gt;).value;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;4:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; password = $get(&lt;SPAN class=str&gt;"&amp;lt;%=txtPassword.ClientID %&amp;gt;"&lt;/SPAN&gt;).value;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;5:&lt;/SPAN&gt;     chatService.Register(username, password, onRegisterSuccess);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;6:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;7:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;8:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; onRegisterSuccess(result)&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;9:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;10:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt;(result != &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;11:&lt;/SPAN&gt;     {&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;12:&lt;/SPAN&gt;         user = result;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;13:&lt;/SPAN&gt;         &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; btnRegister = $get(&lt;SPAN class=str&gt;"btnRegister"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;14:&lt;/SPAN&gt;         btnRegister.value = &lt;SPAN class=str&gt;"Sign Out"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;15:&lt;/SPAN&gt;         $clearHandlers(btnRegister);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;16:&lt;/SPAN&gt;         $addHandler(btnRegister, &lt;SPAN class=str&gt;"click"&lt;/SPAN&gt;, doSignOut);&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;17:&lt;/SPAN&gt;         &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; btnLogin = $get(&lt;SPAN class=str&gt;"btnLogin"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;18:&lt;/SPAN&gt;         btnLogin.style.display = &lt;SPAN class=str&gt;"none"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;19:&lt;/SPAN&gt;         $get(&lt;SPAN class=str&gt;"&amp;lt;%=txtUsername.ClientID
            %&amp;gt;"&lt;/SPAN&gt;).disabled = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;20:&lt;/SPAN&gt;         $get(&lt;SPAN class=str&gt;"&amp;lt;%=txtPassword.ClientID
            %&amp;gt;"&lt;/SPAN&gt;).disabled = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;21:&lt;/SPAN&gt;         $get(&lt;SPAN class=str&gt;"divChat"&lt;/SPAN&gt;).style.display = &lt;SPAN class=str&gt;"inline"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;22:&lt;/SPAN&gt;         setTimeout(doCheckMessages, 1500);&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;23:&lt;/SPAN&gt;     }&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;24:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;{&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;25:&lt;/SPAN&gt;         alert(&lt;SPAN class=str&gt;'Error!'&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;26:&lt;/SPAN&gt;     }&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;27:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the doRegister function is calling the Register method defined in the IChat service contract, you will notice a nice feature that VS intellisence is working nice in this part&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://farm3.static.flickr.com/2078/2170090134_bc26164bdd_o.png" mce_src="http://farm3.static.flickr.com/2078/2170090134_bc26164bdd_o.png"&gt; &lt;/P&gt;
&lt;P&gt;All the proxy function will have the same parameters defined in the contract, but because of the nature of the asynchronous call, all the functions will add three extra parameters (onSuccessCallback, onFailureCallback, userContext)&lt;/P&gt;
&lt;P&gt;The onSuccess callback is very important, as this where you will get to know the return value (if any), and also where you can say that the server finished working on the request, so in the Register example, in the onRegisterSuccess if the user is created, the Login view is disabled and the Chat view is displayed, also an important part is a timer configured for polling the server for new messages, and the timer is called once every 1.5 seconds, and the result parameter to the onRegisterSuccess function is the return value of the Register method on the IChat service, which in our case it is either a User object or null, if the user object is returned it is saved to the global variable user.&lt;/P&gt;
&lt;P&gt;Now let's see when we send a new message to a certain user&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;1:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; doSend()&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;2:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;3:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; pnlHistory = $get(&lt;SPAN class=str&gt;"&amp;lt;%=pnlMessageHistory.ClientID %&amp;gt;"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;4:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; txtMessage = $get(&lt;SPAN class=str&gt;"&amp;lt;%=txtMessage.ClientID %&amp;gt;"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;5:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; txtTo = $get(&lt;SPAN class=str&gt;"&amp;lt;%=txtToUsername.ClientID %&amp;gt;"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;6:&lt;/SPAN&gt;     pnlHistory.innerHTML += &lt;SPAN class=str&gt;"&amp;lt;b&amp;gt;"&lt;/SPAN&gt; + user.Username + &lt;SPAN class=str&gt;" says:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;"&lt;/SPAN&gt; + txtMessage.value + &lt;SPAN class=str&gt;"&amp;lt;br&amp;gt;"&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;7:&lt;/SPAN&gt;     chatService.Call(user.ID, txtTo.value, txtMessage.value, onSendSuccess);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;8:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;9:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;10:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; onSendSuccess(result)&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;11:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;12:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; txtMessage = $get(&lt;SPAN class=str&gt;"&amp;lt;%=txtMessage.ClientID %&amp;gt;"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;13:&lt;/SPAN&gt;     txtMessage.value = &lt;SPAN class=str&gt;""&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;14:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P&gt;The send message function will call the Call function on the service, and also writes down the message details on the message history panel.&lt;/P&gt;
&lt;P&gt;The callback of this function is simply clears the message textbox.&lt;/P&gt;
&lt;P&gt;Now when you send a message to someone else, the message is temporarily saved on server till the recipient user queries the server for his messages, this logic is done through a client side timer.&lt;/P&gt;
&lt;DIV class=csharpcode-wrapper&gt;
&lt;DIV class=csharpcode&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;1:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; doCheckMessages()&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;2:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;3:&lt;/SPAN&gt;     chatService.GetMyMessages(user.ID, onCheckMessagesSuccess, onCheckMessagesFail);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;4:&lt;/SPAN&gt;     chatService.GetUsers(onGetUsersSuccess);&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;5:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;6:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;7:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; onCheckMessagesSuccess(result)&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;8:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;9:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt;(result == &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;10:&lt;/SPAN&gt;         &lt;SPAN class=kwrd&gt;return&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;11:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; pnlHistory = $get(&lt;SPAN class=str&gt;"&amp;lt;%=pnlMessageHistory.ClientID %&amp;gt;"&lt;/SPAN&gt;);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;12:&lt;/SPAN&gt;     &lt;SPAN class=kwrd&gt;for&lt;/SPAN&gt;(&lt;SPAN class=kwrd&gt;var&lt;/SPAN&gt; i=0; i&amp;lt;result.length; i++)&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;13:&lt;/SPAN&gt;     {&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;14:&lt;/SPAN&gt;        pnlHistory.innerHTML += &lt;SPAN class=str&gt;"&amp;lt;b&amp;gt;"&lt;/SPAN&gt; + result[ i].FromUsername + &lt;SPAN class=str&gt;" says:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;"&lt;/SPAN&gt; + result[ i].Body + &lt;SPAN class=str&gt;"&amp;lt;br&amp;gt;"&lt;/SPAN&gt;; &lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;15:&lt;/SPAN&gt;     }&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;16:&lt;/SPAN&gt;     setTimeout(doCheckMessages, 1500);&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;17:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;18:&lt;/SPAN&gt;&amp;nbsp; &lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;19:&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;function&lt;/SPAN&gt; onCheckMessagesFail(err)&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;20:&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;21:&lt;/SPAN&gt;     alert(err.message);&lt;/PRE&gt;&lt;PRE class=alteven&gt;&lt;SPAN class=lnum&gt;22:&lt;/SPAN&gt;     setTimeout(doCheckMessages, 1500);&lt;/PRE&gt;&lt;PRE class=alt&gt;&lt;SPAN class=lnum&gt;23:&lt;/SPAN&gt; }&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The doCheckMessages function does two things, first it checks for the new messages from server, and the other thing is checking for new users in the chat.&lt;/P&gt;
&lt;P&gt;the onCheckMessagesSuccess is reading all the messages in the result array of messages, and print them out on the message history with proper format, and then it initialzes the timer again.&lt;/P&gt;
&lt;P&gt;This is typically how the chat will look like&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://farm3.static.flickr.com/2277/2170114002_5773c2c37e_o.png" mce_src="http://farm3.static.flickr.com/2277/2170114002_5773c2c37e_o.png"&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Summary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In today's entry I was giving a small overview of one of the new features introduced in WCF 2.0 (.net 3.5) which is WebScript and JSON support, this feature allowed us to create a rich web based application using only Javascript as a client code, we also developed a simple Chatting application to prove the concept and the code is attached with this post for further information and details.&lt;/P&gt;
&lt;P&gt;Have a nice day.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class=wlWriterSmartContent id=scid:0767317B-992E-4b12-91E0-4F059A8CECA8:5573c655-14d0-4981-9510-e3813e395409 style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;Technorati Tags: &lt;A href="http://technorati.com/tags/WCF" rel=tag mce_href="http://technorati.com/tags/WCF"&gt;WCF&lt;/A&gt;,&lt;A href="http://technorati.com/tags/C#" rel=tag mce_href="http://technorati.com/tags/C#"&gt;C#&lt;/A&gt;,&lt;A href="http://technorati.com/tags/JSON" rel=tag mce_href="http://technorati.com/tags/JSON"&gt;JSON&lt;/A&gt;,&lt;A href="http://technorati.com/tags/Javascript" rel=tag mce_href="http://technorati.com/tags/Javascript"&gt;Javascript&lt;/A&gt;,&lt;A href="http://technorati.com/tags/ASP.net" rel=tag mce_href="http://technorati.com/tags/ASP.net"&gt;ASP.net&lt;/A&gt;&lt;/DIV&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8626185" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="ASP.net" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/ASP-net/" /><category term="C#" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/C_2300_/" /><category term="javascript" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/javascript/" /><category term="json" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/json/" /><category term="soa" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/soa/" /><category term="wcf" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/wcf/" /></entry><entry><title>PLINQ is coming up soon (PFX)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2007/10/14/plinq-is-coming-up-soon-pfx.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2007/10/14/plinq-is-coming-up-soon-pfx.aspx</id><published>2007-10-14T10:59:00Z</published><updated>2007-10-14T10:59:00Z</updated><content type="html">&lt;p&gt;I've been hearing about PLINQ &lt;i&gt;(Parallel Linq)&lt;/i&gt; since the first days of announcing LINQ, the idea of making use of the new functional style programming provided in DotNet 3.5 in order to give better performance on Multi Core machines, the idea sounds cool since first day, and it now comes true in a new name Parallel FX or PFX&lt;/p&gt; &lt;p&gt;The programming model provided is quite simple and utilizes the same LINQ model, the new assembly is called &lt;b&gt;System.Concurrency.dll&lt;/b&gt; which is the library that contains the new interface called IParallelEnumerable&amp;lt;T&amp;gt;, also it adds an extension methods for all collections and arrays that implement old IEnumerable, the extension method is called AsParrallel&amp;lt;T&amp;gt; which converts any collection to a Parallel enabled collection of type IParallelEnumerable&amp;lt;T&amp;gt;&lt;/p&gt; &lt;p&gt;Take a look of the following code&lt;/p&gt; &lt;div class="csharpcode-wrapper"&gt; &lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; data = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[] {1, 2, 3, 4, 5, 6}; &lt;span class="rem"&gt;// or whatever complex data collection&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alteven"&gt;var q = data.Where(x =&amp;gt; x &amp;gt; 4).OrderBy(x=&amp;gt;x).Select(x =&amp;gt; x);&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var i &lt;span class="kwrd"&gt;in&lt;/span&gt; q) ....&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This code is what you already write in C# 3.0, now if you want to add PLINQ support all what you have to do is adding the AsParallel function call before using any query operation so the previous code will look like this&lt;/p&gt;
&lt;div class="csharpcode-wrapper"&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; data = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[] {1, 2, 3, 4, 5, 6}; &lt;span class="rem"&gt;// or whatever complex data collection&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alteven"&gt;var q = data.AsParallel().Where(x =&amp;gt; x &amp;gt; 4).OrderBy(x=&amp;gt;x).Select(x =&amp;gt; x);&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var i &lt;span class="kwrd"&gt;in&lt;/span&gt; q) ....&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;or you can write it in the LINQ query style&lt;/p&gt;
&lt;div class="csharpcode-wrapper"&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; data = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[] {1, 2, 3, 4, 5, 6}; &lt;span class="rem"&gt;// or whatever complex data collection&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alteven"&gt;var q = from i &lt;span class="kwrd"&gt;in&lt;/span&gt; data.AsParallel()&lt;/pre&gt;&lt;pre class="alt"&gt;        &lt;span class="kwrd"&gt;where&lt;/span&gt; i &amp;gt; 4&lt;/pre&gt;&lt;pre class="alteven"&gt;        orderby i&lt;/pre&gt;&lt;pre class="alt"&gt;        select i;&lt;/pre&gt;&lt;pre class="alteven"&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt;(var i &lt;span class="kwrd"&gt;in&lt;/span&gt; q) .... &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Once you've added the AsParallel function call, PLINQ will be ready to execute transparently all the OrderBy, Where, Select, GroupBy ... etc on all the available processors.&lt;/p&gt;
&lt;p&gt;You don't need to explicitly create threads, locks and manage concurrent execution &lt;i&gt;(Unless you are making something big).&lt;/i&gt;&lt;/p&gt;
&lt;p&gt;This doesn't mean that you can make use of the PLINQ power on anything other than Queries, the ParallelEnumerable class also adds some extra extension methods like the ForAll method&lt;/p&gt;
&lt;p&gt;The ForAll method is useful if you are applying some kind of operation on all the members of a certain collection, so the ForAll function will do this operation in parallel for all the members of the collection&lt;/p&gt;
&lt;div class="csharpcode-wrapper"&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;IEnumerable&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; data = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt;[] {1, 2, 3, 4, 5, 6}; &lt;span class="rem"&gt;// or whatever complex data collection&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alteven"&gt;data.ForAll(i=&amp;gt;Console.WriteLine(i));&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The previous code sample will print out all the members of the array, if you imagined calling more complex function that does some heavy work on each array member, the ForAll will give you extra power to do the job faster by making use of the parallel data processing techniques.&lt;/p&gt;
&lt;p&gt;This is not all the new stuff introduced in the System.Concurrency library, the new &lt;b&gt;Parallel&lt;/b&gt; class is also a nice addition, it provides some extra general purpose parallel execution, so it is not related to LINQ, the most important part is the Parallel.For function, which as you expected from the name executes a parallel loop.&lt;/p&gt;
&lt;p&gt;Check the following code&lt;/p&gt;
&lt;div class="csharpcode-wrapper"&gt;
&lt;div class="csharpcode"&gt;&lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;void&lt;/span&gt; ParMatrixMult(&lt;span class="kwrd"&gt;int&lt;/span&gt; size, &lt;span class="kwrd"&gt;double&lt;/span&gt;[,] m1, &lt;span class="kwrd"&gt;double&lt;/span&gt;[,] m2, &lt;span class="kwrd"&gt;double&lt;/span&gt;[,] result)&lt;/pre&gt;&lt;pre class="alteven"&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;  Parallel.For( 0, size, &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; i) {&lt;/pre&gt;&lt;pre class="alteven"&gt;    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; j = 0; j &amp;lt; size; j++) {&lt;/pre&gt;&lt;pre class="alt"&gt;      result[i, j] = 0;&lt;/pre&gt;&lt;pre class="alteven"&gt;      &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; k = 0; k &amp;lt; size; k++) {&lt;/pre&gt;&lt;pre class="alt"&gt;        result[i, j] += m1[i, k] * m2[k, j];&lt;/pre&gt;&lt;pre class="alteven"&gt;      }&lt;/pre&gt;&lt;pre class="alt"&gt;    }&lt;/pre&gt;&lt;pre class="alteven"&gt;  });&lt;/pre&gt;&lt;pre class="alt"&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;This is an example I got from &lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx" mce_href="http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx" target="_blank"&gt;here&lt;/a&gt;, it illustrates a Matrix Multiplication using Parallel.For, as you can see the Parallel.For method accepts the start index and the length, then a delegate to execute.&lt;/p&gt;
&lt;p&gt;There is also Parallel.Aggregate function which can be used to aggregate a certain data item over a parallel loop safely.&lt;/p&gt;
&lt;p&gt;This all what I could write in one post, however the System.Concurrency contains more cool API's.&lt;/p&gt;
&lt;p&gt;Here comes the resources for further readings.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx" mce_href="http://msdn.microsoft.com/msdnmag/issues/07/10/Futures/default.aspx" target="_blank"&gt;Optimize Managed Code for Multi-Core Machines&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/msdnmag/issues/07/10/PLINQ/default.aspx" mce_href="http://msdn.microsoft.com/msdnmag/issues/07/10/PLINQ/default.aspx" target="_blank"&gt;Running Queries on Multi-Core processors&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://channel9.msdn.com/showpost.aspx?postid=347531" mce_href="http://channel9.msdn.com/showpost.aspx?postid=347531" target="_blank"&gt;Channel9 Video Programming in the Age of Concurrency (Andres Hejlsberg and Joe Duffy)&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fspellcoder.com%2fblogs%2fbashmohandes%2farchive%2f2007%2f10%2f14%2f8530.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fspellcoder.com%2fblogs%2fbashmohandes%2farchive%2f2007%2f10%2f14%2f8530.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fspellcoder.com%2fblogs%2fbashmohandes%2farchive%2f2007%2f10%2f14%2f8530.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fspellcoder.com%2fblogs%2fbashmohandes%2farchive%2f2007%2f10%2f14%2f8530.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666704" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>SOA via WCF - Part 2 -</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2007/09/17/soa-via-wcf-part-2.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2007/09/17/soa-via-wcf-part-2.aspx</id><published>2007-09-17T11:07:00Z</published><updated>2007-09-17T11:07:00Z</updated><content type="html">This is the second part of my presentation in SilverKey Demo Day 2 (SKDD 2) last July, for the first part, &lt;a href="http://blogs.msdn.com/bashmohandes/archive/2007/08/11/soa-via-wcf-part-1.aspx" target="_blank" mce_href="http://blogs.msdn.com/bashmohandes/archive/2007/08/11/soa-via-wcf-part-1.aspx"&gt;Check Here&lt;/a&gt;, &lt;i&gt;you will also find the presentation slides &amp;amp; samples attached in Part 1 or you can &lt;a href="http://blogs.msdn.com/blogs/bashmohandes/attachment/7830.ashx" mce_href="http://blogs.msdn.com/blogs/bashmohandes/attachment/7830.ashx"&gt;download from here&lt;/a&gt;&lt;/i&gt;&lt;br&gt;So let's start&lt;br&gt;Let's check our Agedna&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1146/1086579354_0df7c93fa1.jpg" mce_src="http://farm2.static.flickr.com/1146/1086579354_0df7c93fa1.jpg"&gt;&lt;br&gt;&lt;br&gt;In Part 1 we discussed what is SOA and the concepts behind it, also we had a walk through different approaches to apply SOA in our applications in terms of standards and patterns.&lt;br&gt;In Part 2 we are going to discuss WCF or (Windows Communication Foundation) which is Microsoft new framework to unify communication mechanisms and provide an infrastructure for our SOA applications.&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1218/1399102114_006658efbe.jpg" mce_src="http://farm2.static.flickr.com/1218/1399102114_006658efbe.jpg"&gt;&lt;br&gt;&lt;br&gt;As we've just mentioned WCF stands for Windows Communication Foundation and also it used to be called Indigo.&lt;br&gt;WCF was shipped with Windows Vista in November 2006 as part of .net framework 3.0, however it is also available for Windows 2000, XP and 2003.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1360/1398216021_da3de28986.jpg?v=0" mce_src="http://farm2.static.flickr.com/1360/1398216021_da3de28986.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;WCF is all about providing an unified infrastructure that handles all communication scenarios and protocols, which includes different transport, messaging patterns, encoding .... etc.&lt;br&gt;WCF also playing a great role in making the life easier for .net developer, so the messages exchanged between different services are exposed as CLR types (classes), and also the services are represented as interfaces and classes, so it provides a good and very high level of abstraction.&lt;br&gt;So as one sentence you can say that WCF is the infrastructure for building Services.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1343/1398216389_2a3174c025.jpg?v=0" mce_src="http://farm2.static.flickr.com/1343/1398216389_2a3174c025.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;As we said WCF unifies the communication techniques, but how ?&lt;br&gt;Before the WCF days, we used to have different technologies for different communication problem, so if you are doing TCP communication you will be using Sockets for example, and if you are providing online services over HTTP, you will be using Web Services, and if you are doing message queues you will be using MSMQ ... etc&lt;br&gt;So this was good, however it has some drawbacks.&lt;br&gt;&lt;ol&gt;&lt;li&gt;You have to learn different models for every communication technique. &lt;/li&gt;&lt;li&gt;You can't change the communication technique you are using in a certain application to another without massive changes in your code.&lt;/li&gt;&lt;/ol&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1094/1399105528_8430511edd.jpg?v=0" mce_src="http://farm2.static.flickr.com/1094/1399105528_8430511edd.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;So what WCF provides is a &lt;b&gt;One Right Solution for all problems&lt;/b&gt;, which saves your time and effort, also it comes with a full fledged set of goodies such as Tracing, Logging which can be used regardless of the communication technique you are using.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1353/1399106030_41a3c00916.jpg?v=0" mce_src="http://farm2.static.flickr.com/1353/1399106030_41a3c00916.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;One of WCF great benefits that it provides a very handy extensible model, that you can add support for new protocols easily, or even slight changes to current protocols like adding a new encoding or encryption algorithm.or a new tracing mechanism.&lt;br&gt;Another thing that WCF is supporting almost all the WS-* standards like WS-Addressing, WS-AtomicTransaction which makes the messages generated from WCF runtime interoperable with any current or future application built with same standard messaging.&lt;br&gt;and The most elegant feature of WCF, that all the configuration of the services and protocol specific properties can be configured using XML config files outside the application, which is a great feature that allows administrators to be part of the game, so they can change stuff like the impersonation options, and security settings, enabling and disabling trace listeners and logging, without the need to ask developers to do it, which is somehow similar to ASP.net configuration. &lt;br&gt;Also this config file can be edited using a UI tool..&lt;br&gt;For architects it is really easy to stay in the high level design and forget about implementation details and technology limitations.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1432/1398217659_f6303fcc94.jpg?v=0" mce_src="http://farm2.static.flickr.com/1432/1398217659_f6303fcc94.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;So let's have a sample service&lt;br&gt;In this demo we will be discussing the basic elements in any WCF application.&lt;br&gt;The most basic three elements are&lt;br&gt;&lt;ol&gt;&lt;li&gt;Address&lt;/li&gt;&lt;li&gt;Binding&lt;/li&gt;&lt;li&gt;Contract&lt;/li&gt;&lt;/ol&gt;They are also called the ABC's of WCF, because every service has to define these three elements.&lt;br&gt;We will be discussing everyone of these elements in details, &lt;br&gt;let's now see how a Service is defined in WCF. in steps we will discuss how to build a simple News service.&lt;br&gt;&lt;b&gt;&lt;font size="4"&gt;1. Define the Contracts&lt;/font&gt;&lt;br&gt;&lt;/b&gt;In this step we will define the different contracts of the service the first type is&lt;br&gt;&lt;br&gt;&lt;b&gt;Service Contracts&lt;/b&gt;&lt;br&gt;&lt;b&gt;&lt;/b&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;[ServiceContract(Namespace=&lt;span class="str"&gt;"com.silverkeytech.news"&lt;/span&gt;)]&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; INewsService&lt;br&gt;{&lt;br&gt;    [OperationContract(IsOneWay=&lt;span class="kwrd"&gt;false&lt;/span&gt;)]&lt;br&gt;    Article[] GetArticles();&lt;br&gt;}&lt;/pre&gt;&lt;br&gt;As you see the Service Definition is just an &lt;b&gt;interface &lt;i&gt;(Contract)&lt;/i&gt;&lt;/b&gt; which is decorated with an attribute called ServiceContract.&lt;br&gt;This interface defines the different functions provided by the service in terms of inputs/outputs and exchange patterns.&lt;br&gt;Every service function is represented in a form of interface method, and the inputs of the service function are represented as inputs to the method and also the output is represented as return type of the method.&lt;br&gt;The exchange pattern is by default Request/Response which is represented using the Attribute OperationContract with the IsOneWay property set to false, if it was set to true this means that this service function is a fire &amp;amp; forget type of service, which the service clients will not expect any response for the messages sent to this functions.&lt;br&gt;&lt;br&gt;&lt;b&gt;Data Contracts&lt;/b&gt;&lt;br&gt;Also if you noticed in our method return type is a complex type &lt;b&gt;Article &lt;/b&gt;this is not a primitive type in .net, it is a user defined type which has to be defined like this.&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;[DataContract]&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Article&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; title;&lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; details;&lt;br&gt;&lt;br&gt;    [DataMember]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Title&lt;br&gt;    {&lt;br&gt;        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; title; }&lt;br&gt;        set { title = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;br&gt;    }&lt;br&gt;    [DataMember]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Details&lt;br&gt;    {&lt;br&gt;        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; details; }&lt;br&gt;        set { details = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;&lt;br&gt;As you can see it is a simple data class that is decorated with a &lt;b&gt;DataContract &lt;/b&gt;attribute, so it tells the WCF runtime that this class will be converted to a message that will be sent or received by one or more service functions, also every field or property of interest has to be decorated with another attribute called &lt;b&gt;DataMember.&lt;br&gt;&lt;br&gt;&lt;font size="4"&gt;2. Implement the Service&lt;/font&gt;&lt;br&gt;&lt;/b&gt;Now we need to provide the implementation of the Service Contract interface, which will do the actual job of the service, all what we need is to implement the interface in a class like this.&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; NewsService : INewsService&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Article[] GetArticles()&lt;br&gt;    {&lt;br&gt;        List&amp;lt;Article&amp;gt; articles = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Article&amp;gt;();&lt;br&gt;        &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 10; i++)&lt;br&gt;        {&lt;br&gt;            Article article = &lt;span class="kwrd"&gt;new&lt;/span&gt; Article();&lt;br&gt;            article.Title = &lt;span class="str"&gt;"Title "&lt;/span&gt; + i.ToString();&lt;br&gt;            article.Details = &lt;span class="str"&gt;"Details "&lt;/span&gt; + i.ToString();&lt;br&gt;            articles.Add(article);&lt;br&gt;        }&lt;br&gt;        &lt;span class="kwrd"&gt;return&lt;/span&gt; articles.ToArray();&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;&lt;br&gt;So the class NewsService implements the interface INewsService and provides an implementation of the service that does the actual job of how the service will handle the incoming requests.&lt;br&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;3. Hosting the Service&lt;br&gt;&lt;/b&gt;&lt;/font&gt;Now after we implemented the service, we have to host it on an application, there are different choices depending on your need, you can host the service on Windows Applications (Console, Windows Forms, Windows Services) or Web Applications (IIS), for simplicity I will host my service on a console application.&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Host&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (ServiceHost host = &lt;span class="kwrd"&gt;new&lt;/span&gt; ServiceHost(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(NewsService)))&lt;br&gt;            {&lt;br&gt;                host.Open();&lt;br&gt;                Console.ReadKey();&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;As you see, the host is very simple, all the hard work is done in the ServiceHost class which its constructor requires the type of the &lt;b&gt;class that implements my service&lt;/b&gt;, in our case NewsService class.&lt;br&gt;Then we call the Open method to allow the service to accept any incoming requests and process them, the last Console.ReadKey is just for not allowing the application to exit unless somebody presses any key.&lt;br&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;4. Configuring the Service&lt;br&gt;&lt;/b&gt;&lt;/font&gt;After we hosted the service we need to configure this service, we need to write how the service is going to interact with its clients, this will be done using the App.Config file of the host &lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;="1.0"&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;="utf-8"&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt; &lt;span class="attr"&gt;&lt;/span&gt;&lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="BeebcNews.NewsService"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;endpoint&lt;/span&gt; &lt;span class="attr"&gt;address&lt;/span&gt;&lt;span class="kwrd"&gt;="EndPoint1"&lt;/span&gt; &lt;span class="attr"&gt;binding&lt;/span&gt;&lt;span class="kwrd"&gt;="basicHttpBinding"&lt;/span&gt;
                    &lt;span class="attr"&gt;bindingConfiguration&lt;/span&gt;&lt;span class="kwrd"&gt;=""&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="HttpEndpoint"&lt;/span&gt; &lt;span class="attr"&gt;contract&lt;/span&gt;&lt;span class="kwrd"&gt;="BeebcNews.INewsService"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;host&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;baseAddresses&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;baseAddress&lt;/span&gt;&lt;span class="kwrd"&gt;="http://localhost:9000/beeBC"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;baseAddresses&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;host&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;service&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;services&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.serviceModel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;configuration&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;This is sample configuration file that is used to configure the NewsService we've just implemented &lt;br&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;5. Consuming The Service&lt;br&gt;&lt;/b&gt;&lt;/font&gt;After we host and deploy our service, we need to consume it, which mean we need to write client applications that sends and receives requests and responses from the service.&lt;br&gt;&lt;br&gt;&lt;b&gt;Generating Proxy Class&lt;/b&gt;&lt;br&gt;So for the client application to be able to use the service we need to use a proxy class, the proxy class is generated using a tool called &lt;b&gt;svcutil.exe&lt;/b&gt; this tool can be applied either on the Service dll or on the WSDL file url of the service.&lt;br&gt;so let's assume our NewsService dll is called MyLibrary.dll&lt;br&gt;We will write this command in the command prompt.&lt;br&gt;&lt;br&gt;svcutil.exe MyLibrary.dll&lt;br&gt;&lt;br&gt;This command will generate the XSD files &amp;amp; WSDL file for the types and services inside the library, there are more switches can be used for more specific options.&lt;br&gt;Then after we generate the XSD, WSDL of the wcf service we apply this command on the generated files.&lt;br&gt;&lt;br&gt;svcutil.exe *.xsd *.wsdl /language:C#&lt;br&gt;&lt;br&gt;This command will use the XSD, WSDL file we generated with the first command to generate a proxy class in C# and an XML config file.&lt;br&gt;&lt;br&gt;Then we can use the new files to write our client applications.&lt;br&gt;Another way of generating the Proxy classes is to switch on the MetaData publishing for the service, so the service will have a http url that contains the WSDL file, then we can use this command&lt;br&gt;&lt;br&gt;svcutil.exe http://[the service url]&lt;br&gt;&lt;br&gt;and this will generate the C# proxy and the config file&lt;br&gt;&lt;br&gt;&lt;b&gt;Implementing the Client Application&lt;/b&gt;&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Client&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br&gt;        {&lt;br&gt;            NewsServiceClient client = &lt;span class="kwrd"&gt;new&lt;/span&gt; NewsServiceClient(&lt;span class="str"&gt;"HttpEndpoint"&lt;/span&gt;);&lt;br&gt;            Article[] myArticles = client.GetArticles();&lt;br&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt;(Article a &lt;span class="kwrd"&gt;in&lt;/span&gt; myArticles)&lt;br&gt;                Console.WriteLine(a.Title);&lt;br&gt;            Console.ReadKey();&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;The previous code is a simple example of a client application that uses the generated proxy class we've just generated that generated the &lt;b&gt;NewsServiceClient &lt;/b&gt;class, which has the same functions provided by the INewsService interface so we can call them and the WCF will handle the communication between the client and server.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1083/1398218189_aa66515634.jpg?v=0" mce_src="http://farm2.static.flickr.com/1083/1398218189_aa66515634.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;Now let's have an overview of the architecture of WCF, or let's call it the journey of the incoming message to the service and how it is going to be handled.&lt;br&gt;The architecture of WCF is basically a pipeline, the message arrives on the transport layer which is going to pass it to the next layer to be decoded and then it passes through different protocol specific layers till it reaches the dispatcher, which is going to decide this message belongs to which method in the running instance of the service, and then deliver it to the method to be processed then the return value (if any) takes a similar path down the pipeline back to the original sender.&lt;br&gt;This pipeline is configured using the Configuration and the Contract, the configuration defines the layers in the WCF pipeline and the Contract helps the Dispatcher to find the destination of the message.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1196/1399107110_b4862a07eb.jpg?v=0" mce_src="http://farm2.static.flickr.com/1196/1399107110_b4862a07eb.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;If you take a look on the XML Configuration in the previous example, you will find that under the Service element there is something called EndPoint&lt;br&gt;The EndPoint is the container that has the three basic elements of the service we mentioned before (Address, Binding &amp;amp; Contract).&lt;br&gt;So in our previous example the &lt;b&gt;Address &lt;/b&gt;was EndPoint1, which is going to be concatenated with the baseAddress of the Service in our case &lt;i&gt;"http://localhost:9000/beeBC"&lt;/i&gt;so the result address will be&lt;b&gt;http://localhost:9000/beeBC/EndPoint1,&lt;/b&gt; then the &lt;b&gt;Binding&lt;/b&gt; which was &lt;b&gt;"basicHttpBinding"&lt;/b&gt; which is the simply SOAP messages over HTTP using text encoding.&lt;br&gt;and the &lt;b&gt;Contract&lt;/b&gt; which has the full name of the INewsService interface which defines our service contract.&lt;br&gt;Now let's see each Endpoint element in details&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1333/1398219039_27a1fedb20.jpg?v=0" mce_src="http://farm2.static.flickr.com/1333/1398219039_27a1fedb20.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;The Address&lt;br&gt;&lt;/b&gt;Defines &lt;u&gt;Where&lt;/u&gt; the endpoint resides&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1210/1398213987_0bfe11d990.jpg?v=0" mce_src="http://farm2.static.flickr.com/1210/1398213987_0bfe11d990.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;The Binding&lt;/b&gt;&lt;br&gt;Defines &lt;u&gt;How&lt;/u&gt; the service is communicating with the outside world.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1133/1398214405_e023dfd294.jpg?v=0" mce_src="http://farm2.static.flickr.com/1133/1398214405_e023dfd294.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;The Contract&lt;br&gt;&lt;/b&gt;Defines &lt;u&gt;What&lt;/u&gt; the service will offer to its clients.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1040/1399103818_8d5e526caa.jpg?v=0" mce_src="http://farm2.static.flickr.com/1040/1399103818_8d5e526caa.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;Before we end this presentation, I would like to highlight that WCF 2 is on the way, it will be shipped with next version of Visual Studio 2008 and .net framework 3.5&lt;br&gt;The new version of WCF will have better support for Webby style services such as REST style services and also supports different encodings like RSS, ATOM and JSON.&lt;br&gt;Also the huge change will be that WCF and WF are merged together in what is called Silver project, which will enable developers to develop WCF service with Workflow as an implementation.&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1044/1399104308_07a8338bc7.jpg?v=0" mce_src="http://farm2.static.flickr.com/1044/1399104308_07a8338bc7.jpg?v=0"&gt;&lt;br&gt;&lt;br&gt;These are some resources for more information about WCF and SOA also some books for further information.&lt;br&gt;&lt;br&gt;I hope you read this line, which means that you kept reading the whole presentation, I hope it was useful for you, if you have any questions write them as a comment to this blog post and I will be answering them immediately.&lt;br&gt;&lt;br&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/09/17/8169.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/09/17/8169.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/09/17/8169.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/09/17/8169.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666720" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>SOA via WCF - Part 1-</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2007/08/11/soa-via-wcf-part-1.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2007/08/11/soa-via-wcf-part-1.aspx</id><published>2007-08-11T11:05:00Z</published><updated>2007-08-11T11:05:00Z</updated><content type="html">&lt;font size="4"&gt;&lt;b&gt;Service Oriented Architecture via Windows Communications Foundation&lt;br&gt;&lt;br&gt;&lt;/b&gt;&lt;/font&gt;I should have blogged this very much earlier, because this was my presentation in &lt;a href="http://www.demoday.us" mce_href="http://www.demoday.us"&gt;SilverKey Demo&lt;/a&gt; Day II last July 7th, so it&amp;nbsp; took me more than a month, I hope I still rememebr :)&lt;br&gt;&lt;b&gt;You will find the presentation attached with this blog post&lt;/b&gt;&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1399/1085712925_d731ee1d7d_o.png" mce_src="http://farm2.static.flickr.com/1399/1085712925_d731ee1d7d_o.png"&gt;&lt;br&gt;&lt;br&gt;So today, I will be talking about Service Oriented Architecture (SOA) in general also I will&amp;nbsp; give an introduction to Windows Communications Foundation (WCF) and how to apply SOA concepts in real life.&lt;br&gt;Let's see the Agenda&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1146/1086579354_6b5057cb64_o.png" mce_src="http://farm2.static.flickr.com/1146/1086579354_6b5057cb64_o.png"&gt;&lt;br&gt;&lt;ul&gt;&lt;li&gt;Part 1- Service Oriented Architecture&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Background&lt;/li&gt;&lt;li&gt;Motivations&lt;/li&gt;&lt;li&gt;What is a service ?&lt;/li&gt;&lt;li&gt;Message Exchange Patterns (MEP's)&lt;/li&gt;&lt;li&gt;Industry Standards&lt;/li&gt;&lt;li&gt;Web Standards&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Part 2- Introducing WCF&lt;br&gt;&lt;/li&gt;&lt;ul&gt;&lt;li&gt;What is WCF &lt;br&gt;&lt;/li&gt;&lt;li&gt;WCF Architecture Overview&lt;/li&gt;&lt;li&gt;Demos&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;i&gt;In today's blog post I will be only discussing Part-1 in the coming days, I will be writing Part 2 in a separate blog post.&lt;/i&gt;&lt;br&gt;&lt;br&gt;Let's start with First part Service Oriented Architecture (SOA).&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1195/1086581076_6a25737b69_o.png" mce_src="http://farm2.static.flickr.com/1195/1086581076_6a25737b69_o.png"&gt;&lt;br&gt;&lt;br&gt;Service Oriented Architecture is a buzz word in the world for many years, architects have been talking, writing, blogging and also building applications using SOA, but before we go with the wave, why don't we stop for a while and go back with time to see the software evolution since its early days.&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1034/1085725455_22877aad26_o.png" mce_src="http://farm2.static.flickr.com/1034/1085725455_22877aad26_o.png"&gt;&lt;br&gt;&lt;br&gt;Since the early days of software industry, just when people started to use general purpose programming languages such as &lt;b&gt;C&lt;/b&gt;, the concept of &lt;u&gt;reuse&lt;/u&gt; was in mind, but the reusable unit couldn't me more than a function or a &lt;b&gt;procedure&lt;/b&gt;, or may be some unstructured and unorganized pieces of codes, that used to get copied and pasted whenever needed, &lt;br&gt;However, this was developed by time, till the days of &lt;b&gt;Object Oriented&lt;/b&gt;, when a bigger unit of code was defined, this unit was called Class, the &lt;b&gt;Class&lt;/b&gt; &lt;i&gt;which consists of data and Logic&lt;/i&gt;, became the major unit of organized reusable code for the past couple of decades, but there was a major problem, that class objects are not exchangeable outside the technology, in other words an object built with C++ can't be used as is in another class written with Java, so the reuse was limited by the technology,&lt;br&gt;Component Oriented came to the rescue with technologies such as COM, DCOM, COM+ for windows and other technologies were developed for other platforms, so different technologies can exchange objects between each others, for example, in windows environment you can use the UI elements such as Buttons, TextBoxes from any technology even though those UI elements are not developed using the same technology you are using for your application, this was great but what about exchanging objects and data between technologies running on different platforms, like a C# application developed on Windows want to send an object for a Java application running on a Unix platform, here is when &lt;b&gt;Service Oriented&lt;/b&gt; came to rescue.&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1078/1085726965_d7dbd1c2bc_o.png" mce_src="http://farm2.static.flickr.com/1078/1085726965_d7dbd1c2bc_o.png"&gt;&lt;br&gt;&lt;br&gt;Why do we need to exchange objects through different platforms?&lt;br&gt;The answer is one word &lt;b&gt;Integration&lt;/b&gt;, when you are building an applications that needs to integrate with another Existing application, which happened to be developed using a different technology and runs on different platform, what will you do ? you have to find a way to integrate with this application.&lt;br&gt;For example, if you want to add Maps support in your application, are you going to build a GIS system to view some maps in your application, surely no, but you are going to integrate with something like Google Maps or Microsoft Virtual Earth to send the coordinates and receive the map.&lt;br&gt;In our example we will find ourselves calling Google Maps or MS Virtual Earch a Service, which leads us to the next question&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1119/1085729327_274a25c800_o.png" mce_src="http://farm2.static.flickr.com/1119/1085729327_274a25c800_o.png"&gt;&lt;br&gt;&lt;br&gt;What is a Service ?&lt;br&gt;A Service is a reusable piece of software, but the main difference that this piece is as large as a full application, this application might be built using any technology and deployed on any platform, these details are not important as long as the Service provides a Structured Messaging Scheme, this structured messaging scheme in most cases is XML document(s) or any other text-based structure, that can be exchanged on Http, but the fact is it is not only XML nor HTTP, it can be any other format on any transport as long as it is well defined.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1332/1086590686_20f73426a4_o.png" mce_src="http://farm2.static.flickr.com/1332/1086590686_20f73426a4_o.png"&gt;&lt;br&gt;&lt;br&gt;This model of separation comes with some other benefits, like Versioning independence, which means that as long as the Service doesn't change its messaging structure, it can change any inner implementation details and add more features without the need for all other applications that use this service to be aware of these changes.&lt;br&gt;Also the nature of the separation between the Service and other clients or even other Services, introduced some concepts like Message Exchange Patterns which is how the structured messages are exchanged between Service and Clients.&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1045/1086592746_077a1651e9_o.png" mce_src="http://farm2.static.flickr.com/1045/1086592746_077a1651e9_o.png"&gt;&lt;br&gt;&lt;br&gt;The message exchange patterns used are either&lt;br&gt;&lt;ol&gt;&lt;li&gt;One Way&lt;/li&gt;&lt;li&gt;Request/Reply&lt;/li&gt;&lt;li&gt;Duplex&lt;/li&gt;&lt;/ol&gt;The &lt;b&gt;One Way&lt;/b&gt; is when the sender sends a message to the receiver but the sender doesn't expect the receiver to reply to this message, it is something like Fire &amp;amp; Forget.&lt;br&gt;The &lt;b&gt;Request / Reply&lt;/b&gt; is when the sender sends a message to the receiver and expects ONLY one reply from the receiver, as an example any web page you request for it in your browser you expect a reply (Response) which is the Page you requested.&lt;br&gt;The &lt;b&gt;Duplex&lt;/b&gt; is when both Sender &amp;amp; Receiver construct a channel between them and everyone of them can send messages to the other at well, it is just like a Phone Call.&lt;br&gt;&lt;br&gt;Every MEP has its best use, depends on the Scenario, in Part 2, I will be doing samples with WCF that show how to use different MEP's with WCF.&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1333/1085734313_c9fdefd50c_o.png" mce_src="http://farm2.static.flickr.com/1333/1085734313_c9fdefd50c_o.png"&gt;&lt;br&gt;&lt;br&gt;From the previous talk about Integration you might have imagined if everything gets standardized so no matter what system you want to integrate with, you know that there is a standard way of doing this.&lt;br&gt;Actually this is somehow true, there are some initiatives by Software Industry leaders such as Microsoft, IBM, Oracle, Sun ... etc, to standardize the Service Structure Exchange Scheme thing into something real, which results in what we call SOAP (Simple Object Access Protocol) which is a XML based protocol that defines the message that is going to be exchanged between different Services &amp;amp; Clients, also there are some standard protocols that were built on top of SOAP which all of them starts with WS-, so they were all called WS-* Protocols like WS-Addressing, WS-AtomicTransaction, WS-Security ... etc, everyone of them is defining a standard way of handling a specific scenario in terms of the Exchanged Message structure and parties involved, like WS-AtomicTransaction it defines a protocol for performing distributed transactions between Services.&lt;br&gt;These standards are being used in different technologies under several names, that most common technology is Web Services &amp;amp; WSE&lt;br&gt;&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1375/1085714089_9a8e6bbc01_o.png" mce_src="http://farm2.static.flickr.com/1375/1085714089_9a8e6bbc01_o.png"&gt;&lt;br&gt;&lt;br&gt;The SOAP &amp;amp; WS-* are NOT the ONLY method available but there is another ways which are most commonly used over the web, and so called Web Standard, or Webby Standard.&lt;br&gt;These methods can be grouped under REST.&lt;br&gt;REST (Representational State Transfer) which relies on HTTP verbs such as GET, which most of the time uses the URI as a function call, so you request a URI with a specific parameters and gets the result in any format such as XML, text, or JSON.&lt;br&gt;This method is used because it is very simple and especially for listing data&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1068/1085715589_06c6de8a20_o.png" mce_src="http://farm2.static.flickr.com/1068/1085715589_06c6de8a20_o.png"&gt;&lt;br&gt;&lt;br&gt;Give SOAP a REST&lt;br&gt;You will find a lot of debates online about which is better SOAP &amp;amp; WS-* or REST, which I think is not the right question, because you will always find situations where you find REST better and vise versa.&lt;br&gt;&lt;img src="http://farm2.static.flickr.com/1418/1085717625_e1c4d7d3c4_o.png" mce_src="http://farm2.static.flickr.com/1418/1085717625_e1c4d7d3c4_o.png"&gt;&lt;br&gt;&lt;br&gt;As a summarization of this part of the presentation, Here is a list of online services that most of them are free and available using either SOAP, REST or both.&lt;br&gt;&lt;br&gt;&lt;b&gt;Summary&lt;br&gt;&lt;/b&gt;Service Oriented Architecture is one of most important techniques that introduces new way of thinking and designing systems in order to provide better integration options.&lt;br&gt;&lt;br&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/08/11/7830.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/08/11/7830.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/08/11/7830.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/08/11/7830.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666711" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="soa" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/soa/" /><category term="wcf" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/wcf/" /></entry><entry><title>Javascript tricks for ASP.net developers</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2007/06/17/javascript-tricks-for-asp-net-developers.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2007/06/17/javascript-tricks-for-asp-net-developers.aspx</id><published>2007-06-17T11:11:00Z</published><updated>2007-06-17T11:11:00Z</updated><content type="html">This is a post I wanted to write really long time ago, but I never had enough time to sit and write.&lt;br&gt;The following listing will be my agenda for this post&lt;br&gt;&lt;ol&gt;&lt;li&gt;Why Javascript for ASP.net developers is different ?&lt;/li&gt;&lt;li&gt;Javascript tricks for ASP.net developers&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Reading ASP.net controls values from Javascript&lt;/li&gt;&lt;li&gt;Passing values calculated by Javascript to the server side.&lt;/li&gt;&lt;li&gt;Passing values from ASP.net to Javascript&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Javascript development tools&lt;/li&gt;&lt;/ol&gt;So let's go through the previous points and see if this will be interesting enough for you to read it to the end.&lt;br&gt;&lt;br&gt;&lt;b&gt;&lt;font size="4"&gt;Why Javascript for ASP.net developers is different ?&lt;/font&gt;&lt;br&gt;&lt;br&gt;&lt;/b&gt;&lt;u&gt;The first difference&lt;/u&gt; between ASP.net and other web technologies that it has its own web controls which &lt;i&gt;&lt;u&gt;sometimes&lt;/u&gt;&lt;/i&gt; map to standard HTML controls, so sometimes what you see in ASP.net as a control doesn't mean that it will be rendered as one control in the final HTML which means that Javascript can't deal with it directly as it does with basic control.&lt;br&gt;Taking the ASP.net Calendar control as an example, in ASP.net you use it as one control just drag it and drop it in the page and boom! you have a full functional calendar, but in reality this calendar renders as a Table with rows and columns and links and also lots of Javascript, so you can't expect that you will deal with it as a calendar in the Javascript side, this also applies to Repeater, Grid, DataList ... etc&lt;br&gt;&lt;br&gt;&lt;u&gt;The second difference&lt;/u&gt; is that even with asp.net server controls that maps directly to standard HTML controls like TextBox or Button, the asp.net runtime changes the control &lt;b&gt;Id's&lt;/b&gt; so if placed a code like this in your ASP.net page directly&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&lt;b&gt;"myTextBox"&lt;/b&gt;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;the rendered equivalent HTML will look like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&lt;b&gt;"myTextBox"&lt;/b&gt;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="myTextBox"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
As you can see the asp:TextBox id is the same as the input text id which is &lt;b&gt;"myTextBox"&lt;/b&gt;, but watch out, if you put the previous asp:TextBox in a UserControl instead of adding it directly to the page, and then added the UseControl to the page like this lets name our usercontrol &lt;b&gt;"MyControl"&lt;/b&gt;&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;uc1:MyControl&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="MyControl1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;the rendered equivalent HTML will look like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="&lt;b&gt;MyControl1_myTextBox&lt;/b&gt;"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="&lt;b&gt;MyControl1$myTextBox&lt;/b&gt;"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;As you can see the rendered input field Id is not &lt;b&gt;"myTextBox"&lt;/b&gt; but it is a combination of the usercontrol id and the textbox id separated by underscore "_" and the name of the control is similar but separated by dollar sign "$".&lt;br&gt;So that's why you will face some difficulties when you try to use &lt;u&gt;document.getElementById&lt;/u&gt; on the "myTextBox" because the name is not known until the page renders.&lt;b&gt;&lt;br&gt;&lt;/b&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;Javascript tricks for ASP.net developers&lt;br&gt;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&lt;b&gt;&lt;i&gt;Reading ASP.net Controls Values from Javascript&lt;/i&gt;&lt;/b&gt;&lt;br&gt;I think now you have seen the problem and it is time for the solution so let's see the basic solutions for most of Javascript problems with ASP.net.&lt;br&gt;The solutions comes from the fact that almost all ASP.net controls have a property called ClientID which returns the Id of the rendered equivalent HTML control. so in our last Example the myTextBox.ClientID will return "MyControl1_myTextBox" so you can apply the document.getElementById , buy wait a second how could I get this property value inside my Javascript code ?&lt;br&gt;This will require writing some ASP classic style code to this job inside the javascript so let's see how our UserControl code will look like&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyControl.ascx.cs" Inherits="MyControl" %&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;function&lt;/span&gt; myFunc()&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;var&lt;/span&gt; myTextBox = document.getElementById(&lt;span class="str"&gt;"&amp;lt;%= myTextBox.ClientID %&amp;gt;"&lt;/span&gt;);&lt;br&gt;    myTextBox.value = &lt;span class="str"&gt;"value from JS"&lt;/span&gt;;&lt;br&gt;}&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="myTextBox"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="myFunc()"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;So if you have a look into the myFunc function&lt;br&gt;the document.getElementById parameter is actually a asp.net code which is written&amp;nbsp; &amp;lt;%= myTextBox.ClientID %&amp;gt;&lt;br&gt;and this how myFunc code will be in the browser.&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;function&lt;/span&gt; myFunc()&lt;br&gt;{&lt;br&gt; &lt;span class="kwrd"&gt;var&lt;/span&gt; myTextBox = document.getElementById(&lt;span class="str"&gt;"MyControl1_myTextBox"&lt;/span&gt;);&lt;br&gt; myTextBox.value = &lt;span class="str"&gt;"value from JS"&lt;/span&gt;;&lt;br&gt;}&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;so the asp.net code between the &amp;lt;%%&amp;gt; is executed and the property ClientID was evaluated.&lt;br&gt;&lt;br&gt;&lt;i&gt;&lt;b&gt;Passing values calculated by Javascript to the server side&lt;br&gt;&lt;/b&gt;&lt;/i&gt;Yeah this is very important, sometimes you calculate some values or get some inputs from the user using Javascript code but you want to process these result in the backend, and you find yourself asking this question, how can I send those results back to the asp.net ?&lt;br&gt;The answer is simple use your best friend The &lt;b&gt;HiddenField&lt;/b&gt;. &lt;br&gt;Write all your results in the hidden field &lt;b&gt;BUT &lt;/b&gt;make sure that this hidden field is either a asp:HiddenField or a regular input type="hidden" field with runat="server" attribute, so the asp.net runtime picks its value from the form and post it to the field in the backend. &lt;br&gt;&lt;br&gt;&lt;i&gt;&lt;b&gt;Passing values from ASP.net to Javascript&lt;/b&gt;&lt;/i&gt;&lt;br&gt;Sometimes you need to pass values or initialize some variables in javascript using code behind, in this case you need to use your other friend the &lt;b&gt;Literal Control&lt;br&gt;&lt;/b&gt;The literal control is amazing because it simply renders to nothing but the values inside, so it doesn't render to Span like Label or div like Panel, so take this example&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Literal&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="litData"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;My Text&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:Literal&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;This code will render to this&lt;br&gt;&lt;br&gt;
My Text&lt;br&gt;&lt;br&gt;Consider the example when you need to use the server date in the client javascript code, because the javascript Date function returns the client date so sometimes you need to use the Server time not the client time, so this is a way to do it using the Literal trick.&lt;br&gt;in your asp.net markup code define a similar javascript block&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;var&lt;/span&gt; serverDate = &lt;span class="str"&gt;'&amp;lt;asp:literal runat="server" id="litServerDate" &amp;gt;&amp;lt;/asp:literal&amp;gt;'&lt;/span&gt;;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;and then in your Page_Load code you can do this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;br&gt;{&lt;br&gt;    litServerDate.Text = DateTime.Now.ToShortDateString();&lt;br&gt;}&lt;/pre&gt;In the javascript code you define a variable which takes its value from a literal control, the literal control is your connection to the backend code,&lt;br&gt;the backend code puts the data inside the literal and completes the javascript sentence, so the result javascript will look like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;var&lt;/span&gt; serverDate = &lt;span class="str"&gt;'6/17/2007'&lt;/span&gt;;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;So the literal is gone and the result is just the date string provided by the server, which you can use later to do whatever you want.&lt;br&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;Javascript development tools&lt;br&gt;&lt;/b&gt;&lt;/font&gt;If you decided to write some code in Javascript so be ready and use the proper tools&lt;br&gt;&lt;ol&gt;&lt;li&gt;First of all I prefer you develop your code on FireFox because it is more strict and if you made your code run fine on FireFox most probably it will run fine on every other browser.&lt;/li&gt;&lt;li&gt;Second you need Debugger so I strongly recommend &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/1843" mce_href="https://addons.mozilla.org/en-US/firefox/addon/1843"&gt;FireBug&lt;/a&gt; which is an addin to FireFox which has lots of useful tools one of those tools is a Javascript debugger&lt;/li&gt;&lt;li&gt;Visual Studio is a good IDE however there is another IDE especially dedicated to Javascript which is &lt;a href="http://www.aptana.com" mce_href="http://www.aptana.com"&gt;APTANA&lt;/a&gt; , aptana also provides a debugger for FireFox&amp;nbsp; so you can use Aptana debugger to debug your javascript running in FireFox&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;So that's what I could write in a single post, soon I will post some hints and tricks for developers to make it easier for them to write AJAX applications without using UpdatePanel.&lt;br&gt;Have fun.&lt;br&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/06/17/7297.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/06/17/7297.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/06/17/7297.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/06/17/7297.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666728" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="ASP.net" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/ASP-net/" /><category term="javascript" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/javascript/" /></entry><entry><title>Command Design Pattern in C# 2.0</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2007/03/25/command-design-pattern-in-c-2-0.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2007/03/25/command-design-pattern-in-c-2-0.aspx</id><published>2007-03-25T11:13:00Z</published><updated>2007-03-25T11:13:00Z</updated><content type="html">I have posted before about &lt;a href="http://blogs.msdn.com/blogs/bashmohandes/archive/2007/03/10/6212.aspx" mce_href="http://blogs.msdn.com/blogs/bashmohandes/archive/2007/03/10/6212.aspx"&gt;how to implement the observer pattern using C#&lt;/a&gt; in a way that is more suitable to C# and uses its functionalities to produce more elegant code.&lt;br&gt;This time I am re-implementing the Command pattern in a C# way.&lt;br&gt;First of all, let's see the classic Command Pattern UML diagram&lt;br&gt;&lt;img src="http://dofactory.com/Patterns/Diagrams/command.gif" mce_src="http://dofactory.com/Patterns/Diagrams/command.gif"&gt;&lt;br&gt;As you can see the pattern consists of five actors&lt;br&gt;&lt;ol&gt;&lt;li&gt;Invoker&lt;/li&gt;&lt;li&gt;Command (interface)&lt;/li&gt;&lt;li&gt;Concrete Command class(es)&lt;br&gt;&lt;/li&gt;&lt;li&gt;Receiver&lt;/li&gt;&lt;li&gt;Client&lt;/li&gt;&lt;/ol&gt;for more information about &lt;a href="http://dofactory.com/Patterns/PatternCommand.aspx#_self2" mce_href="http://dofactory.com/Patterns/PatternCommand.aspx#_self2"&gt;Command pattern check here&lt;/a&gt;&lt;br&gt;Now let's see how it can look like in C# world.&lt;br&gt;&lt;br&gt;Let's see how the Command interface will look like&lt;br&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CommandHandle&amp;lt;T&amp;gt;(T receiver);&lt;/pre&gt;Awesome doesn't it, just one line :)
&lt;br&gt;&lt;br&gt;Let's see the Command Concrete Class
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Command&amp;lt;T&amp;gt;&lt;br&gt;{&lt;br&gt;    T _receiver;&lt;br&gt;&lt;br&gt;    CommandHandle&amp;lt;T&amp;gt; _doCommand;&lt;br&gt;    CommandHandle&amp;lt;T&amp;gt; _undoCommand;&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Command(CommandHandle&amp;lt;T&amp;gt; doCommand, T receiver)&lt;br&gt;    {&lt;br&gt;        _doCommand = doCommand;&lt;br&gt;        _receiver = receiver;&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Command(CommandHandle&amp;lt;T&amp;gt; doCommand, CommandHandle&amp;lt;T&amp;gt; undoCommand, T receiver)&lt;br&gt;        : &lt;span class="kwrd"&gt;this&lt;/span&gt;(doCommand, receiver)&lt;br&gt;    {&lt;br&gt;        _undoCommand = undoCommand;&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Execute()&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt;(_doCommand != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br&gt;            _doCommand(_receiver);&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Undo()&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;if&lt;/span&gt;(_undoCommand != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br&gt;            _undoCommand(_receiver);&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;&lt;br&gt;This is a generic class so it can be used for most cases instead of creating multiple inherited classes, the class has two references of the CommandHandler delegate one for the DoCommand and the other is for the UndoCommand&lt;br&gt;&lt;br&gt;Let's see how the Receiver class will look like,&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Receiver&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; _state;&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; State&lt;br&gt;    {&lt;br&gt;        get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _state; }&lt;br&gt;        set { _state = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;Actually it doesn't matter how it looks like, so the previous code is just a sample class.&lt;br&gt;&lt;br&gt;Let's now see how the Invoker class will look like&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Invoker&lt;br&gt;{&lt;br&gt;    List&amp;lt;Command&amp;lt;Receiver&amp;gt;&amp;gt; _commands;&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; Invoker()&lt;br&gt;    {&lt;br&gt;        _commands = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Command&amp;lt;Receiver&amp;gt;&amp;gt;();&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddCommand(Command&amp;lt;Receiver&amp;gt; command)&lt;br&gt;    {&lt;br&gt;        _commands.Add(command);&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RemoveCommand(Command&amp;lt;Receiver&amp;gt; command)&lt;br&gt;    {&lt;br&gt;        _commands.Remove(command);&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CallCommands()&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Command&amp;lt;Receiver&amp;gt; command &lt;span class="kwrd"&gt;in&lt;/span&gt; _commands)&lt;br&gt;        {&lt;br&gt;            command.Execute();&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UndoCommands()&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Command&amp;lt;Receiver&amp;gt; command &lt;span class="kwrd"&gt;in&lt;/span&gt; _commands)&lt;br&gt;        {&lt;br&gt;            command.Undo();&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;&lt;br&gt;The invoker is just a class that is interested in the Receiver objects and want to apply certain actions on instance(s) of the Receiver class, so it uses a list of Command&amp;lt;Receiver&amp;gt; to encapsulate the executing code.&lt;br&gt;&lt;br&gt;Finally, we should see how the Client will use these classes.&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br&gt;    {&lt;br&gt;        Receiver recv1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Receiver();&lt;br&gt;        Receiver recv2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Receiver();&lt;br&gt;        Command&amp;lt;Receiver&amp;gt; command1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Command&amp;lt;Receiver&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; CommandHandle&amp;lt;Receiver&amp;gt;(Func1), &lt;span class="kwrd"&gt;new&lt;/span&gt; CommandHandle&amp;lt;Receiver&amp;gt;(UndoFunc1), recv1);&lt;br&gt;        Command&amp;lt;Receiver&amp;gt; command2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Command&amp;lt;Receiver&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; CommandHandle&amp;lt;Receiver&amp;gt;(Func2), recv2);&lt;br&gt;        Invoker invoker = &lt;span class="kwrd"&gt;new&lt;/span&gt; Invoker();&lt;br&gt;        invoker.AddCommand(command1);&lt;br&gt;        invoker.AddCommand(command2);&lt;br&gt;        invoker.CallCommands();&lt;br&gt;        invoker.UndoCommands();&lt;br&gt;&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Func1(Receiver recv1)&lt;br&gt;    {&lt;br&gt;        recv1.State ++;&lt;br&gt;        Console.WriteLine(recv1.State);&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Func2(Receiver recv2)&lt;br&gt;    {&lt;br&gt;        recv2.State+=2;&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UndoFunc1(Receiver recv)&lt;br&gt;    {&lt;br&gt;        recv.State--;&lt;br&gt;        Console.WriteLine(recv.State);&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;So the main difference between the classic implementation and this one, that &lt;br&gt;&lt;ol&gt;&lt;li&gt;We didn't define an interface and we juts used a generic delegate&lt;/li&gt;&lt;li&gt;We don't need to inherit from the interface every time we want to use the command pattern for different Receiver type, we replaced this with a generic Command class.&lt;/li&gt;&lt;/ol&gt;I hope you like it, I attached the previous code with the post&lt;br&gt;Have fun&lt;br&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/03/25/6447.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/03/25/6447.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/03/25/6447.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/03/25/6447.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666731" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="C#" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/C_2300_/" /><category term="design patterns" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/design+patterns/" /></entry><entry><title>Observer Pattern in C# = Events &amp; delegates</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2007/03/10/observer-pattern-in-c-events-delegates.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2007/03/10/observer-pattern-in-c-events-delegates.aspx</id><published>2007-03-10T12:14:00Z</published><updated>2007-03-10T12:14:00Z</updated><content type="html">One of the most interesting patterns in Design Patterns is the Observer pattern which is listed under Behavioral Patterns, it is really important how to make other classes which are interested in the state of another object get notified when the state changed.&lt;br&gt;&lt;img src="http://dofactory.com/Patterns/Diagrams/observer.gif" mce_src="http://dofactory.com/Patterns/Diagrams/observer.gif"&gt;&lt;br&gt;&lt;a href="http://dofactory.com/Patterns/PatternObserver.aspx" mce_href="http://dofactory.com/Patterns/PatternObserver.aspx"&gt;To read more about Observer pattern&lt;/a&gt;&lt;br&gt;This is the classic Observer pattern which used to be good with C++ and Java, however in C# you can implement the same idea using Delegates and Events which is really more concise and elegant way of writing this pattern&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Patterns&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; StateChangeHandler(State newState);&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;enum&lt;/span&gt; State&lt;br&gt;    {&lt;br&gt;        State1, State2, State3&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Product&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; State _state;&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; State MyState&lt;br&gt;        {&lt;br&gt;            get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _state; }&lt;br&gt;            set&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (_state != &lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;br&gt;                {&lt;br&gt;                    _state = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br&gt;                    Notify();&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Notify()&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (_onChange != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br&gt;                _onChange(_state);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; StateChangeHandler _onChange;&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; StateChangeHandler OnStateChange&lt;br&gt;        {&lt;br&gt;            add&lt;br&gt;            {&lt;br&gt;                _onChange += &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br&gt;            }&lt;br&gt;            remove&lt;br&gt;            {&lt;br&gt;                _onChange -= &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;Take a look on the previous code, the Product class has an important piece of info called _state, and is encapsulated in the property MyState, this class expects that other classes may be interested in observing the changes in the MyState, so the class adds another member which is an Event (_onChange) of type StateChangeHandler delegate, and encapsulated in the Event Property called OnStateChange, and in the setter of the property MyState a small check is made to see whether the new value is different than the older value then the event gets fired.&lt;br&gt;A typical class which makes use of the Product class will look similar to this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Patterns&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;class&lt;/span&gt; Program&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)&lt;br&gt;        {&lt;br&gt;            Product myProduct = &lt;span class="kwrd"&gt;new&lt;/span&gt; Product();&lt;br&gt;            myProduct.OnStateChange += &lt;span class="kwrd"&gt;new&lt;/span&gt; StateChangeHandler(myProduct_OnStateChange);&lt;br&gt;            myProduct.MyState = State.State3;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; myProduct_OnStateChange(State newState)&lt;br&gt;        {&lt;br&gt;            Console.WriteLine(&lt;span class="str"&gt;"State changed to {0}"&lt;/span&gt;, newState);&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;So now the Program class instantiates an object of type Product and registers itself in the OnStateChange event so whoever changes the MyState property of the object myProduct, the Program class gets notified.&lt;br&gt;I am not a Design Pattern Guru, however I think this implementation is more suitable for C# and makes use of the unique C# features that produces elegant code.&lt;br&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/03/10/6212.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/03/10/6212.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/03/10/6212.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/03/10/6212.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666733" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="C#" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/C_2300_/" /><category term="design patterns" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/design+patterns/" /></entry><entry><title>.Net &amp; C# Interview question, along with general programming questions</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2007/02/26/net-c-interview-question-along-with-general-programming-questions.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2007/02/26/net-c-interview-question-along-with-general-programming-questions.aspx</id><published>2007-02-27T04:19:00Z</published><updated>2007-02-27T04:19:00Z</updated><content type="html">&lt;A href="http://tech.groups.yahoo.com/group/middle-east-developers/" mce_href="http://tech.groups.yahoo.com/group/middle-east-developers/"&gt;&lt;IMG src="http://farm1.static.flickr.com/138/330370229_3def87d088_o.jpg" align=right border=0 mce_src="http://farm1.static.flickr.com/138/330370229_3def87d088_o.jpg"&gt;&lt;/A&gt;Hey, These are some Interview Questions with suggested answers we collected in &lt;A href="http://tech.groups.yahoo.com/group/middle-east-developers/" mce_href="http://tech.groups.yahoo.com/group/middle-east-developers/"&gt;Middle-East-Developers&lt;/A&gt;, for more questions in other fields like C++, you can check the group.&lt;BR&gt;These questions are collected by&lt;BR&gt;
&lt;UL&gt;
&lt;LI&gt;Adel Khalil 
&lt;LI&gt;Yehia Megahed 
&lt;LI&gt;Hisham Abd El-Hafez&lt;BR&gt;
&lt;LI&gt;Mohammed Hossam&lt;/LI&gt;&lt;/UL&gt;&lt;B&gt;Q1: Can DateTime variables be null?&lt;BR&gt;&lt;/B&gt;A1: No, because it is a value type (Struct)&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q2: Describe the Asp.net Page Life Cycle?&lt;BR&gt;&lt;/B&gt;A2: &lt;A href="http://msdn2.microsoft.com/en-us/library/ms178472.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms178472.aspx"&gt;http://msdn2.microsoft.com/en-us/library/ms178472.aspx&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q3: Describe the Asp.net pipeline ? Give an Example when you need to extend it? How do you do so?&lt;BR&gt;&lt;/B&gt;A3: &lt;A href="http://msdn.microsoft.com/msdnmag/issues/02/09/HTTPPipelines/" mce_href="http://msdn.microsoft.com/msdnmag/issues/02/09/HTTPPipelines/"&gt;http://msdn.microsoft.com/msdnmag/issues/02/09/HTTPPipelines/&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q4: Describe the accessibility modifier protected internal&lt;BR&gt;&lt;/B&gt;A4: Members are accessible to derived classes and classes within the same Assembly&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q5: Difference between an interface and abstract class?&lt;/B&gt;&lt;BR&gt;A5: In the interface all methods must be abstract, in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q6: How do you perform pre- and post-processing to extend a WebMethod ?&lt;/B&gt;&lt;BR&gt;A6: Use SOAP extensions ...&lt;A href="http://msdn.microsoft.com/msdnmag/issues/04/03/ASPColumn/" mce_href="http://msdn.microsoft.com/msdnmag/issues/04/03/ASPColumn/"&gt;http://msdn.microsoft.com/msdnmag/issues/04/03/ASPColumn/&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q7: What are Design Patterns?&lt;/B&gt;&lt;BR&gt;A7: It is a big topic in Object Oriented, so for more information see this, &lt;A href="http://dofactory.com/Patterns/Patterns.aspx" mce_href="http://dofactory.com/Patterns/Patterns.aspx"&gt;http://dofactory.com/Patterns/Patterns.aspx&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q8: What do you know about .net framework 3.0 ?&lt;/B&gt;&lt;BR&gt;A8: any answer that introduces Windows Communication Foundation (WCF), Windows Workflow Foundation (WF), Windows Presentation Foundation (WPF) and Windows Card Space (WCS) is right, also you can mention that it was originally called WinFX&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q9: What do you know about ATLAS (Microsoft ASP.net AJAX Extensions) ?&lt;/B&gt;&lt;BR&gt;A9: for more information check here, &lt;A href="http://ajax.asp.net/" mce_href="http://ajax.asp.net"&gt;http://ajax.asp.net&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q10: What do you know about Agile software methodologies?&lt;/B&gt;&lt;BR&gt;A10: &lt;A href="http://en.wikipedia.org/wiki/Agile_software_development" mce_href="http://en.wikipedia.org/wiki/Agile_software_development"&gt;http://en.wikipedia.org/wiki/Agile_software_development&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q11: What do you know about Web Services Enhancements (WSE)?&lt;/B&gt;&lt;BR&gt;A11: &lt;A href="http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx" mce_href="http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx"&gt;http://msdn.microsoft.com/webservices/webservices/building/wse/default.aspx&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q12: What is AJAX ?&lt;/B&gt;&lt;BR&gt;A12: Asynchronous Javascript And XML&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q13:What is NUnit, or What is Unit testing?&lt;/B&gt;&lt;BR&gt;A13: Unit testing: is a procedure used to validate that a particular module of source code is working properly from each modification to the next. The procedure is to write test cases for all functions and methods so that whenever a change causes a regression, it can be quickly identified and fixed. Ideally, each test case is separate from the others; constructs such as mock objects can assist in separating unit tests. This type of testing is mostly done by the developers, NUnit is a famous tool for Unit Testing in .net&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q14: What is an Asp.net Http Handler &amp;amp; Http Module?&lt;/B&gt;&lt;BR&gt;A14: &lt;A href="http://www.15seconds.com/issue/020417.htm" mce_href="http://www.15seconds.com/issue/020417.htm"&gt;http://www.15seconds.com/issue/020417.htm&lt;/A&gt;&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q15: What is mutable type ? immutable type ?&lt;/B&gt;&lt;BR&gt;A15: Immutable type are types whose instance data, fields and properties, does not change after the instance is created. Most value types are immutable, but the mutable type are A type whose instance data, fields and properties, can be changed after the instance is created. Most Reference Types are mutable.&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q16: What is the HttpContext Object? Where is it accessible?&lt;/B&gt;&lt;BR&gt;A16: It's is an Object that Encapsulates all HTTP-specific information about an individual HTTP request. it is avaliable through out the Asp.net request pipline.&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q17: What is the difference between String &amp;amp; StringBuilder classes?&lt;/B&gt;&lt;BR&gt;A17: String is an immutable type while StringBuilder is a mutable type&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q18: What's the difference between C# 1.0 &amp;amp; C# 2.0?&lt;/B&gt;&lt;BR&gt;A18: Any answer that introduces stuff like, Generics, Anonymous Methods, Nullable types, Iterators ... etc, is correct&lt;BR&gt;&lt;BR&gt;&lt;B&gt;Q19: Without using the multiplication or addition operations, how can you multiply a number x by 8?&lt;/B&gt;&lt;BR&gt;A19: Shift x to the left 3 times, x &amp;lt;&amp;lt; 3, because every shift left multiplies the number by 2 
&lt;TABLE class="" cellSpacing=0 cellPadding=2 width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class=""&gt;&lt;WBR&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;BR&gt;&lt;B&gt;Q20: What is the difference between ASP.net 1.x &amp;amp; ASP.net 2.0 ?&lt;/B&gt;&lt;BR&gt;A20: Any answer that include stuff like Provider model (membership provider, role provider ... etc) and Master Pages, Code Beside model, new web controls will be ok.&lt;BR&gt;&lt;BR&gt;If you have more questions feel free to join the user group and add them directly to the database.&lt;BR&gt;&lt;A href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/02/26/5991.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/02/26/5991.aspx"&gt;&lt;IMG alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/02/26/5991.aspx" border=0 mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2007/02/26/5991.aspx"&gt;&lt;/A&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8623445" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="ASP.net" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/ASP-net/" /><category term="C#" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/C_2300_/" /></entry><entry><title>StructLayout attribute magic</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2006/12/21/structlayout-attribute-magic.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2006/12/21/structlayout-attribute-magic.aspx</id><published>2006-12-21T12:16:00Z</published><updated>2006-12-21T12:16:00Z</updated><content type="html">I've been reading for a while in the great &lt;a href="http://www.amazon.com/CLR-via-Second-Jeffrey-Richter/dp/0735621632" mce_href="http://www.amazon.com/CLR-via-Second-Jeffrey-Richter/dp/0735621632"&gt;CLR via C# &lt;/a&gt;&lt;i&gt;second edition&lt;/i&gt; book, and here is one of the best things I've seen there,&lt;br&gt;When you declare a type, the CLR in runtime automatically rearrange the order of your type members for performance, so the access to these members are faster, and also trying to use minimum memory, &lt;i&gt;stuff like making the variables reserves even memory locations for faster access and all these stuff&lt;/i&gt;, but you still have control on the CLR to force him follow the sequence you defined, and this helps especially in the interoperability with some C/C++ API's that accepts structs, so you have to stick with the structure layout, and in this case you have to add the StructLayout attribute to your class or struct like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;[StructLayout(LayoutKind.Sequential)]&lt;br&gt;&lt;span class="kwrd"&gt;struct&lt;/span&gt; Point&lt;br&gt;{&lt;br&gt;   &lt;span class="kwrd"&gt;int&lt;/span&gt; x;&lt;br&gt;   &lt;span class="kwrd"&gt;int&lt;/span&gt; y;&lt;br&gt;}&lt;/pre&gt;If you are declaring a struct type, the default Layout is Sequential, so you don't need to add the StructLayout. &lt;br&gt;However, developers add the attribute to struct when they want to mention that this struct is defined for interop with unmanaged stuff.&lt;br&gt;&lt;br&gt;So where is the fun ?? I already know this&lt;br&gt;The fun comes here, the LayoutKind actually has three options which are&lt;br&gt;&lt;ol&gt;&lt;li&gt;Auto (which is the default behavior)&lt;br&gt;&lt;/li&gt;&lt;li&gt;Sequential&lt;/li&gt;&lt;li&gt;&lt;b&gt;Explicit&lt;/b&gt;&lt;/li&gt;&lt;/ol&gt;The Explicit is how you can have full control of how the &lt;b&gt;Struct&lt;/b&gt; members are stuffed in the main memory, &lt;br&gt;so you can declare the point like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;[StructLayout(LayoutKind.Explicit)]&lt;br&gt;&lt;span class="kwrd"&gt;struct&lt;/span&gt; Point&lt;br&gt;{&lt;br&gt;    [FieldOffset(0)]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; x;&lt;br&gt;    [FieldOffset(&lt;span class="kwrd"&gt;sizeof&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt;))]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; y;&lt;br&gt;}&lt;/pre&gt;So here I defined the struct member X to reserve the bytes starting from offset 0, then the member Y to reserve the bytes starting from offset 4 &lt;i&gt;which is sizeof(int), &lt;/i&gt;so the Y will come immediately after X in memory, However you can play with the numbers like making them overlap together and get the garbage data we used to see in C :).&lt;br&gt;and as long as we are considering overlapping so we can define something like the old C Union data structure, which we can define a data structure that will contain multiple definitions of variables types and the memory that will be reserved is the memory required to store the largest type.&lt;a href="http://www.cplusplus.com/doc/tutorial/other_data_types.html" mce_href="http://www.cplusplus.com/doc/tutorial/other_data_types.html"&gt; for more information about C/C++ Union&lt;/a&gt;&lt;br&gt;So all what you need here, is setting all the variables' offsets declared in the struct to 0, so all of them occupy the same locations in memory, and the memory reserved for them all is the memory for the largest one, and you are only allowed to use &lt;span style="font-weight: bold;"&gt;ONLY&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;ONE&lt;/span&gt; of them, if you tried assigning values to more than one member, this will lead to unexpected behavior and results, so consider this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;[StructLayout(LayoutKind.Explicit)]&lt;br&gt;&lt;span class="kwrd"&gt;struct&lt;/span&gt; UnionLike&lt;br&gt;{&lt;br&gt;    [FieldOffset(0)]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; iValue;&lt;br&gt;    [FieldOffset(0)]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; lValue;&lt;br&gt;    [FieldOffset(0)]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;double&lt;/span&gt; dValue; &lt;br&gt;}&lt;/pre&gt;and this will lead to this memory organization (conceptually)&lt;br&gt;&lt;img src="http://msdn2.microsoft.com/en-us/library/5dxy4b7b.Local_-567443686_vc38ul1%28en-us,VS.85%29.gif" mce_src="http://msdn2.microsoft.com/en-us/library/5dxy4b7b.Local_-567443686_vc38ul1%28en-us,VS.85%29.gif"&gt;&lt;br&gt;So the whole UnionLike type reserves 8 bytes in memory which is the size of the largest member (in this case dValue) &lt;br&gt;&lt;br&gt;This was amazing to me when I first saw it, and I think it worths a try from you.&lt;br&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/12/21/4654.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/12/21/4654.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/12/21/4654.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/12/21/4654.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666741" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="C#" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/C_2300_/" /></entry><entry><title>Parallel Event Handling in Windows Workflow</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2006/10/02/parallel-event-handling-in-windows-workflow.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2006/10/02/parallel-event-handling-in-windows-workflow.aspx</id><published>2006-10-02T11:18:00Z</published><updated>2006-10-02T11:18:00Z</updated><content type="html">I've been using Windows Work Flow (WF) for a while, and I faced a lot of problems that I could solve, and this article is about one of them,&lt;br&gt;I am working on a project that faced the situation which I need to raise the same event to more than one HandleExternalEventActivity activities working in parallel, and I wanted just one of the HandleExternalEventActivity's to handle the coming event according to an identifier that I'm going to send with the EventArgs.&lt;br&gt;The problem comes, that by default, if you have a ParallelActivity and inside each branch you have a HandleExternalEventActivity activity, when you raise the event from the host, you can't control which HandleExternalEventActivity gets the event, so the most left HandleExternalEventActivity gets and handles the event before the other even if I wasn't targeting it in the first place.&lt;br&gt;So how to solve this,&lt;br&gt;after some searching and reading some working or sometimes old &amp;amp; not-working samples, I found out something called Correlation.&lt;br&gt;so as I could understand, Correlation is how you specify a parameter in the ExternalDataExchange that is going to identify who is going to handle the Event, and only the HandleExternalEventActivity that has the same parameter in its CorrelationToken will handle the event.&lt;br&gt;so it first sounds like a big blah blah blah blah.&lt;br&gt;but after some trials I managed to write some steps of how you do that.&lt;br&gt;1- Write your custom ExternalDataEventArgs by inheriting from ExternalDataEventArgs
&lt;div class="csharpcode"&gt;&lt;br&gt;[Serializable]&lt;br&gt;&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TaskEventArgs : ExternalDataEventArgs&lt;br&gt;{&lt;br&gt;   &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; _identifier;&lt;br&gt;&lt;br&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Id&lt;br&gt;   {&lt;br&gt;      get { &lt;span class="kwrd"&gt;return&lt;/span&gt; _identifier; }&lt;br&gt;      set { _identifier = &lt;span class="kwrd"&gt;value&lt;/span&gt;; }&lt;br&gt;   }&lt;br&gt;&lt;br&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; TaskEventArgs(Guid instanceId): &lt;span class="kwrd"&gt;base&lt;/span&gt;(instanceId)&lt;br&gt;   {&lt;br&gt;            &lt;br&gt;   }&lt;br&gt;}&lt;/div&gt;2- Write your ExternalDataExchange interface like this&lt;br&gt;&lt;br&gt;
&lt;div class="csharpcode"&gt;[ExternalDataExchange]&lt;br&gt;[CorrelationParameter(&lt;span class="str"&gt;"Identifier"&lt;/span&gt;)]&lt;br&gt;&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IService&lt;br&gt;{&lt;br&gt;    [CorrelationInitializer]
   &lt;span class="kwrd"&gt;&lt;br&gt;void&lt;/span&gt; Initialize(&lt;span class="kwrd"&gt;string&lt;/span&gt; Identifier);&lt;br&gt;&lt;br&gt;   [CorrelationAlias(&lt;span class="str"&gt;"Identifier"&lt;/span&gt;, &lt;span class="str"&gt;"e.Id"&lt;/span&gt;)]
   &lt;br&gt;&lt;span class="kwrd"&gt;event&lt;/span&gt; EventHandler&amp;lt;TaskEventArgs&amp;gt; TaskFinished;&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;/div&gt;as you can see, we used three different Attributes&lt;br&gt;&lt;b&gt;CorrelationParameter:&lt;/b&gt; this is where you specify the name of the parameter that will hold the value that Identifies the event destination&lt;br&gt;&lt;b&gt;CorrelationInitializer: &lt;/b&gt;this is where you are going to specify the correlation parameter value, the CorrelationParameter should be a parameter to this method, and take care to write it exactly as you wrote it in the CorrelationParameter attribute with the same casing.&lt;br&gt;&lt;b&gt;CorrelationAlias: &lt;/b&gt;this is where you specify the location of the parameter in the event arguments, because as we said before, the event argument will hold the destination identifier.&lt;br&gt;&lt;br&gt;3- Implement the IService Interface&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Service:IService&lt;br&gt;{&lt;br&gt;   &lt;span class="preproc"&gt;#region&lt;/span&gt; IService Members&lt;br&gt;&lt;br&gt;   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize(&lt;span class="kwrd"&gt;string&lt;/span&gt; Identifier)&lt;br&gt;   {&lt;br&gt;       &lt;span class="rem"&gt;// Actually you don't need to do anything here;&lt;/span&gt;
   }

   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;event&lt;/span&gt; EventHandler&amp;lt;TaskEventArgs&amp;gt; TaskFinished;&lt;br&gt;&lt;br&gt;   &lt;span class="preproc"&gt;#endregion&lt;/span&gt;

   &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RaiseEvent(Guid instanceId, &lt;span class="kwrd"&gt;string&lt;/span&gt; identifier)&lt;br&gt;   {&lt;br&gt;       &lt;span class="rem"&gt;//initializing the TaskEventArgs.&lt;/span&gt;
       TaskEventArgs args = &lt;span class="kwrd"&gt;new&lt;/span&gt; TaskEventArgs(instanceId);&lt;br&gt;       args.Id = identifier; &lt;span class="rem"&gt;// setting the specified identifier to the Id property in the TaskEventArgs.&lt;/span&gt;
       &lt;span class="kwrd"&gt;if&lt;/span&gt; (TaskFinished != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br&gt;          TaskFinished(&lt;span class="kwrd"&gt;null&lt;/span&gt;, args);   &lt;span class="rem"&gt;// Firing the event&lt;/span&gt;
   }

}&lt;/pre&gt;4- Now go to your Workflow designer, and add in every Parallel branch a CallExternalMethodActivity before the HandleExternalEventActivity you already have.&lt;br&gt;your workflow should look similar to this&lt;br&gt;&lt;img src="http://static.flickr.com/97/257927810_520523a6dc_o.png" mce_src="http://static.flickr.com/97/257927810_520523a6dc_o.png"&gt;&lt;br&gt;as you can see in every branch you have a CallExternalMethodActivity, and HandelExternalEventActivity.&lt;br&gt;&lt;i&gt;forget about the other two code activities right now.&lt;br&gt;&lt;/i&gt;5- Now configure the first CallExternalMethodActivity, in our case InitializeFirst&lt;br&gt;5.1 set the interface type to your ExternalDataExchange interface, in our case the IService interface&lt;br&gt;5.2 set the Method Name to the method that has the CorrelationInitializer attribute, in our case the Initialized Method in IService.&lt;br&gt;5.3 now you will notice that you have another option in the properties of the CallExternalMethodActivities called CorrelationToken, write a name inside this box "C1" for example and then expand the node by clicking on the + sign beside the CorrelationToken text and set the OwnerActivityName property with the name of Activity that holds the CallExternalMethodActivity, in our case it is sequenceActivity1.&lt;br&gt;5.4 also you will find the parameter of the Method you are calling shown in the property grid, in our case it is Identifier, set it to the identifier value you want, or bind it to a member of property, in our case we will bind it to the string "First"&lt;br&gt;5.4 repeat the same settings for the second CallExternalMethodActivity, in our case InitializeSecond but use different name for the CorrelationToken "C2" with OwnerActivityName to sequenceActivity2&lt;br&gt;the property grid should look similar to this&lt;br&gt;&lt;img src="http://static.flickr.com/102/257942734_7e69c8d555.jpg?v=0" mce_src="http://static.flickr.com/102/257942734_7e69c8d555.jpg?v=0"&gt;&lt;br&gt;6- Configure the HandleExternalEventActivity, in our case HandleFirst&lt;br&gt;6.1 Choose the interface type as same as the one in the CallExternalMethod, in our case IService interface&lt;br&gt;6.2 Choose the Event Name, in our case TaskFinished&lt;br&gt;6.3 You will find a property CorrelationToken appeared, choose "C1" from the list you have&lt;br&gt;6.4 Repeat this settings for all other HandleExternalEventActivities you have, in our case HandleSecond but use the C2 CorrelationToken for this one.&lt;br&gt;The Property Grid of the HandleExternalEventActivity should look similar to this&lt;br&gt;&lt;img src="http://static.flickr.com/84/257961423_69916ef8a6.jpg?v=0" mce_src="http://static.flickr.com/84/257961423_69916ef8a6.jpg?v=0"&gt;&lt;br&gt;7 now you are almost done, just go to the workflow creation code, usually in the Program.cs file and add an ExternalDataExchangeService to the runtime and add an instance of the IService service to it like this&lt;br&gt;
&lt;pre class="csharpcode"&gt;ExternalDataExchangeService exchange = &lt;span class="kwrd"&gt;new&lt;/span&gt; ExternalDataExchangeService();&lt;br&gt;workflowRuntime.AddService(exchange);&lt;br&gt;Service service = &lt;span class="kwrd"&gt;new&lt;/span&gt; Service();&lt;br&gt;exchange.AddService(service);&lt;/pre&gt;Then after you start the instance and the runtime, you can start raising the event by using (in our case) RaiseEvent function and specify the Identifier you are targeting as a parameter to the function like this&lt;br&gt;
&lt;pre class="csharpcode"&gt;service.RaiseEvent(instance.InstanceId, &lt;span class="str"&gt;"First"&lt;/span&gt;);&lt;/pre&gt;also for a complete example, I attached the complete version of the last code with this blog post. with enough documentation in the code.&lt;br&gt;Have fun coding.&lt;br&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/10/02/690.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/10/02/690.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/10/02/690.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/10/02/690.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;br&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666743" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="WF" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/WF/" /></entry><entry><title>C# 3.0 Lambda Expressions and Expression Trees</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2006/06/12/c-3-0-lambda-expressions-and-expression-trees.aspx" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2006/06/12/c-3-0-lambda-expressions-and-expression-trees.aspx</id><published>2006-06-12T11:19:00Z</published><updated>2006-06-12T11:19:00Z</updated><content type="html">From the first days of C# 1.0 we could do stuff like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Add(&lt;span class="kwrd"&gt;int&lt;/span&gt; x, &lt;span class="kwrd"&gt;int&lt;/span&gt; y)&lt;br&gt;{&lt;br&gt;   &lt;span class="kwrd"&gt;return&lt;/span&gt; x + y;&lt;br&gt;}&lt;/pre&gt;and also C# gives you the ability to write the function signature in the form of delegate, that allows function pointers so you can do something like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MathOperation(&lt;span class="kwrd"&gt;int&lt;/span&gt; x, &lt;span class="kwrd"&gt;int&lt;/span&gt; y);&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; ApplyFunction(&lt;span class="kwrd"&gt;int&lt;/span&gt; x, &lt;span class="kwrd"&gt;int&lt;/span&gt; y, MathOperation operation)&lt;br&gt;{&lt;br&gt;   &lt;span class="kwrd"&gt;return&lt;/span&gt; operation(x, y);&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Add(&lt;span class="kwrd"&gt;int&lt;/span&gt; x, &lt;span class="kwrd"&gt;int&lt;/span&gt; y)&lt;br&gt;{&lt;br&gt;   &lt;span class="kwrd"&gt;return&lt;/span&gt; x + y;&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()&lt;br&gt;{&lt;br&gt;   &lt;span class="kwrd"&gt;int&lt;/span&gt; result = ApplyOperation(1, 3, &lt;span class="kwrd"&gt;new&lt;/span&gt; MathOperation(Add));&lt;br&gt;   Console.WriteLine(result);&lt;br&gt;}&lt;/pre&gt;and so this gives the ability to apply any other function you want as long as you provide a function that has the same signature...&lt;br&gt;&lt;br&gt;Then in C# 2.0 we were introduced to Anonymous methods, which gives you a faster way of writing functions in case that these functions are going to be used only one time&lt;br&gt;like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MathOperation(&lt;span class="kwrd"&gt;int&lt;/span&gt; x, &lt;span class="kwrd"&gt;int&lt;/span&gt; y);&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()&lt;br&gt;{&lt;br&gt;   MathOperation op = &lt;span class="kwrd"&gt;new&lt;/span&gt; MathOperation(&lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; x, &lt;span class="kwrd"&gt;int&lt;/span&gt; y)&lt;br&gt;                        {&lt;br&gt;                            &lt;span class="kwrd"&gt;return&lt;/span&gt; x + y;&lt;br&gt;                        });&lt;br&gt;   Console.WriteLine(op(10, 5));&lt;br&gt;}&lt;/pre&gt;So, this syntax is very much faster in writing delegate functions that will be used only one time.&lt;br&gt;and also, this syntax allows the new function to access the local variables in the outer scope of it, which means in the last method if the Main has a variable called myVar, the new delegate function op can access this myVar without passing it to the function.&lt;br&gt;&lt;br&gt;Now after we see the case of C# 1.0, 1.1 and 2.0. Let's see what C# 3.0 says about this..&lt;br&gt;C# 3.0 introduces Lambda Expressions and Expression Trees,&lt;br&gt;lamdba expressions gives a very fast way to define delegates like in dynamic languages (e.g. Python)&lt;br&gt;so as an example .&lt;br&gt;&amp;nbsp;&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;delegate&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; MathOperation(&lt;span class="kwrd"&gt;int&lt;/span&gt; x, &lt;span class="kwrd"&gt;int&lt;/span&gt; y);&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()&lt;br&gt;{&lt;br&gt;   MathOperation op = (i, j) =&amp;gt; i + j;&lt;br&gt;   Console.WriteLine(op(1,2));&lt;br&gt;&lt;br&gt;}&lt;/pre&gt;so it is really easy to define functions using lamdba expressions, first put all the function parameters comma separated then =&amp;gt; then the expression that evaluates the result. &lt;br&gt;&lt;br&gt;Also because C# gives you a predefined delegate called Func that can be used for most cases of function delegates because it is a generic delegate in this form&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;delegate&lt;/span&gt; T Func&amp;lt;A, T&amp;gt;(A param)&lt;br&gt;or&lt;br&gt;&lt;span class="kwrd"&gt;delegate&lt;/span&gt; T Func&amp;lt;A0, A1, T&amp;gt;(A0 param0, A1 param1)&lt;br&gt;or&lt;br&gt;&lt;span class="kwrd"&gt;delegate&lt;/span&gt; T Func&amp;lt;A0, A1, A2, T&amp;gt;(A0 param0, A1 param1, A2 param2)&lt;br&gt;or&lt;br&gt;&lt;span class="kwrd"&gt;delegate&lt;/span&gt; T Func&amp;lt;A0, A1, A2, A3, T&amp;gt;(A0 param0, A1 param1, A2 param2, A3 param3)&lt;/pre&gt;So you can define any lambda expression without writing the delegate just using this one like this, lambda expression that checks for even number&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt; isEven = i =&amp;gt; (i&amp;amp;1) == 0&lt;br&gt;&lt;/pre&gt;so from the Func definition in this case, it takes an integer parameter and returns bool result&lt;br&gt;&lt;br&gt;Also C# introduces Expression trees, that you can build a new expression and compile it and use it in runtime &lt;br&gt;so we can rewrite the Add function using the expression trees and it will look like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;ParameterExpression p0 = Expression.Parameter(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt;), &lt;span class="str"&gt;"x"&lt;/span&gt;);&lt;br&gt;ParameterExpression p1 = Expression.Parameter(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt;), &lt;span class="str"&gt;"y"&lt;/span&gt;);&lt;br&gt;&lt;br&gt;Expression&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&amp;gt; addExpr= Expression.Lambda&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&amp;gt;(&lt;br&gt;                       Expression.Add(p0, p1), &lt;span class="kwrd"&gt;new&lt;/span&gt; ParameterExpression[]{p0, p1});&lt;br&gt;Console.WriteLine(addExpr.Compile()(1,2));&lt;/pre&gt;If you used Lisp before you'll be familiar with this code, because you first put the operation then put the parameters so a simple addition will looke like this&lt;br&gt;+ x y&lt;br&gt;and that what you get if you printed out the addExpr.Body &lt;br&gt;Add(x, y)&lt;br&gt;If you noticed the expression tree we built for simple addition, you will find it relatively long, but the good news that the compiler can do this for me, all what I need to do is assigning the Lambda expression to the Expression&amp;lt;&amp;gt; object like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;Expression&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&amp;gt; lambdaAdd = (i, j) =&amp;gt; i + j;&lt;/pre&gt;and this will give the same result as writing the long epxression by hand.&lt;br&gt;All these stuff are the backbone of LINQ project and the great enhancements, like using sql-like syntax on collections like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;var list = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();&lt;br&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt;(var i =0; i&amp;lt;100; i++)&lt;br&gt;   list.Add(i);&lt;br&gt;var q = list.Select(i=&amp;gt;i).Where(i=&amp;gt; i&amp;gt;10 &amp;amp;&amp;amp; i&amp;lt;20);&lt;br&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt;(var i &lt;span class="kwrd"&gt;in&lt;/span&gt; q)&lt;br&gt;   Console.WriteLine(i);&lt;/pre&gt;in this code we can get the numbers between 10 &amp;amp; 20 in the list that contains numbers from 0 ~ 99, and in this code we are using the Lambda expressions in the Sequence extension methods.&lt;br&gt;also the same query&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;pre class="csharpcode"&gt;var q = list.Select(i=&amp;gt;i).Where(i=&amp;gt; i&amp;gt;10 &amp;amp;&amp;amp; i&amp;lt;20);&lt;/pre&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;can be replaced with&lt;br&gt;&lt;pre class="csharpcode"&gt;var q = from i &lt;span class="kwrd"&gt;in&lt;/span&gt; list &lt;span class="kwrd"&gt;where&lt;/span&gt; i &amp;gt; 10 &amp;amp; i &amp;lt;20 select i;&lt;/pre&gt;and this how LINQ was built in the first place, it is all matter of expressions&lt;br&gt;&lt;br&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/06/12/143.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/06/12/143.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/06/12/143.aspx" alt="kick it on DotNetKicks.com" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/06/12/143.aspx" border="0"&gt;&lt;/a&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666746" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="C#" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/C_2300_/" /><category term="LINQ" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/LINQ/" /></entry><entry><title>How to increase application scalability using Plugins</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/bashmohandes/archive/2006/05/17/how-to-increase-application-scalability-using-plugins.aspx" /><link rel="enclosure" type="application/octet-stream" length="155741" href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-08-66-67-50/CLR_5F00_Hosting.zip" /><id>http://blogs.msdn.com/b/bashmohandes/archive/2006/05/17/how-to-increase-application-scalability-using-plugins.aspx</id><published>2006-05-17T11:20:00Z</published><updated>2006-05-17T11:20:00Z</updated><content type="html">This time I will talk about how to implement a plugin module that loads and runs plugins in your application.&lt;br&gt;&lt;span style="font-weight: bold;"&gt;but first why do we need such thing?&lt;/span&gt;&lt;br&gt;In so many cases, you need to provide a way that enables someone else to write a piece of code that can be loaded in your application in runtime and runs in the same context of your application without the need to stop the base application and change your code and redeploy.&lt;br&gt;These cases regularily happen when you software that it is very hard to shutdown every time you want to extend its functionality (e.g.Windows Services..)&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;Things you should put in mind before implementing such system&lt;br&gt;&lt;/span&gt;&lt;ol&gt;&lt;li&gt;Plugin should be easy to implement,&lt;br&gt;This can be done by providing enough documentation, and providing a flexible model for implementing plugins&lt;/li&gt;&lt;li&gt;The system must be able to &lt;br&gt;&lt;/li&gt;&lt;ol&gt;&lt;li&gt;Load plugins during runtime&lt;/li&gt;&lt;li&gt;Unload unused (or stopped plugins)&lt;/li&gt;&lt;li&gt;Detect plugin crashes and unload crashed plugins without crashing the whole system&lt;/li&gt;&lt;li&gt;Run multiple plugins at the same time&lt;/li&gt;&lt;li&gt;Detect new plugins and run them.&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;Plugins shouldn't be locked to make it easier to update the plugins without closing the application&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;So lets discuss every point in more details&lt;br&gt;&lt;br&gt;&lt;span style="font-weight: bold;"&gt;1- Plugin should be easy to implement&lt;br&gt;&lt;/span&gt;You should decide how developers are going to implement plugins in your system, and how you can specify mandatory specifications that are logical, acceptable and also easy to be done by the developers&lt;br&gt;There are many approaches to do so&lt;br&gt;&lt;ol&gt;&lt;li&gt;Implementing Specific Intrfaces&lt;/li&gt;&lt;li&gt;Using Attributes &amp;amp; Reflection&lt;br&gt;&lt;/li&gt;&lt;li&gt;Using XML configuration files and Reflection&lt;/li&gt;&lt;/ol&gt;The most common used technique is the first one, that the system developer (The one develops the main system) will provide an inteface for the plugin class like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;interface&lt;/span&gt; Pluggable&lt;br&gt;{&lt;br&gt;     &lt;span class="kwrd"&gt;string&lt;/span&gt; PluginTitle{get;}&lt;br&gt;     &lt;span class="kwrd"&gt;void&lt;/span&gt; Init();&lt;br&gt;     &lt;span class="kwrd"&gt;void&lt;/span&gt; Start();&lt;br&gt;}&lt;/pre&gt;and every plugin will implement the interface&lt;br&gt;&lt;br&gt;&lt;b&gt;What's good about this&lt;br&gt;&lt;/b&gt;&lt;ol&gt;&lt;li&gt;Some how it is simple for the plugin developer&lt;/li&gt;&lt;li&gt; Makes the pluggable classes looks the same from the system point of view...&lt;/li&gt;&lt;li&gt;If you want to get a return value from the methods, this is the only way to inforce the method signature&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-weight: bold;"&gt;What's bad about this&lt;br&gt;&lt;/span&gt;&lt;ol&gt;&lt;li&gt;Interfaces are not that flexible, because you have to implement functions even that you may not use&lt;/li&gt;&lt;/ol&gt;Using Attributes is more flexible because you can specify some attrbitues like &lt;span style="font-style: italic;"&gt;Pluggable&lt;/span&gt; for classes and &lt;span style="font-style: italic;"&gt;Runnable&lt;/span&gt; for functions like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; PluginModule&lt;br&gt;{&lt;br&gt;    [AttributeUsage(AttributeTargets.Class)]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; PluggableAttribute : Attribute&lt;br&gt;    {&lt;br&gt;    }&lt;br&gt;&lt;br&gt;    [AttributeUsage(AttributeTargets.Method)]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; RunnableAttribute : Attribute&lt;br&gt;    {&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;and then you just need to add the suitable attribute before the declaration of the class or function &lt;br&gt;like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; TestPlugin&lt;br&gt;{&lt;br&gt;    [Pluggable]&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TestPlug &lt;br&gt;    {&lt;br&gt;        [Runnable]&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SayHello()&lt;br&gt;        {&lt;br&gt;            Console.WriteLine(&lt;span class="str"&gt;"First Plugin"&lt;/span&gt;);&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;I prefer this way... for these reasons&lt;br&gt;&lt;ol&gt;&lt;li&gt;It is very much cleaner, you don't need to implement a certain interface&lt;/li&gt;&lt;li&gt;You can have as much runnable functions as you want in the same class&lt;/li&gt;&lt;/ol&gt;The third wy to define a plugin is using config files, that you write the plugin class name and every method in every class in a configuration files, then use reflection to load and run these functions&lt;br&gt;the bad things about this technique&lt;br&gt;&lt;ol&gt;&lt;li&gt;The programmer should write a config file for every plugin,&lt;/li&gt;&lt;li&gt;Spelling mistakes in configuration files will make some bugs like function and modules not found&lt;/li&gt;&lt;/ol&gt;&lt;b&gt;2- Loading plugin in runtime&lt;br&gt;&lt;/b&gt;Now we get to the important part, How are we going to load the plugins...&lt;br&gt;we have two ways for this&lt;br&gt;&lt;ol&gt;&lt;li&gt;Loading the plugin in the same appdomain of the main application&lt;/li&gt;&lt;li&gt;Loading the plugin in a separate appdomain&lt;/li&gt;&lt;/ol&gt;So, what is the difference between the two ways.&lt;br&gt;Ofcource the first one is simple you will load the assembly (dll, or exe) plugin using either Assembly.Load() or AppDomain.CurrentDomain.Load() and once the assembly is loaded you can get all the Types (classes) defined in it and execute them,&lt;br&gt;But, you will have some drawbacks like&lt;br&gt;&lt;ol&gt;&lt;li&gt;You &lt;b&gt;can't Unload&lt;/b&gt; assemblies from the domain, without shutting down the whole application, because neither Assembly class nor AppDomain class has a function UnloadAssembly, and this has a very good reason that maybe there are other loaded assemblies depend on this Assembly and this will make a very big problem.&lt;br&gt;&lt;/li&gt;&lt;li&gt;You &lt;b&gt;can't write&lt;/b&gt; separate App.config (*.dll.config, *.exe.config) file for each plugin and load with the assembly&lt;/li&gt;&lt;li&gt;In cases of fatal errors and crashes, it is very possible that the whole application will crash.&lt;/li&gt;&lt;li&gt;You &lt;b&gt;can't limit&lt;/b&gt; the security level of the plugins lower that the level of your application&lt;/li&gt;&lt;li&gt;Dll files will be locked so you can't overrite the files unless you shutdown the whole application&lt;br&gt;&lt;/li&gt;&lt;/ol&gt;You can still use this technique if you don't care about these problems...&lt;br&gt;&lt;br&gt;But what about Loading in a different domain...&lt;br&gt;Well, it is the best way to do it, because all the above problems are solved in this technique, but it is more complicated and will involve some extra work in Remoting, because this is the only way I found to istantiate and execute an object in different domain..&lt;br&gt;&lt;br&gt;First you need to create a new domain and setup this domain&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; AppDomain CreateAppDomain(&lt;span class="kwrd"&gt;string&lt;/span&gt; domainName, &lt;span class="kwrd"&gt;string&lt;/span&gt; fileName, &lt;span class="kwrd"&gt;string&lt;/span&gt; configFileName)&lt;br&gt;        {&lt;br&gt;            AppDomainSetup setup = &lt;span class="kwrd"&gt;new&lt;/span&gt; AppDomainSetup();&lt;br&gt;            setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;&lt;br&gt;            setup.ApplicationName = Path.GetFileName(fileName);&lt;br&gt;            setup.ShadowCopyDirectories = Path.GetDirectoryName(fileName);&lt;br&gt;            setup.CachePath = AppDomain.CurrentDomain.BaseDirectory;&lt;br&gt;            setup.PrivateBinPath = Path.GetDirectoryName(fileName);&lt;br&gt;            setup.ShadowCopyFiles = &lt;span class="str"&gt;"true"&lt;/span&gt;;&lt;br&gt;            setup.ConfigurationFile = configFileName;&lt;br&gt;            AppDomain domain = AppDomain.CreateDomain(domainName, AppDomain.CurrentDomain.Evidence, setup);&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; domain;&lt;br&gt;        }&lt;/pre&gt;As you see from this small function, first it creates an AppDomainSetup object that will store all the configuration&lt;br&gt;then it sets the ApplicationBase directory for the new appdomain as same as the main application and this helps to reduce the number of external dll's needed by the plugins (Dependencies) because if the main application uses them so they can share them.&lt;br&gt;and sets an application name, here we set the application name as same as the dll file name.&lt;br&gt;then we Shadow copy the files and directories and this makes the files free to be removed or replaced during runtime (the file locking problem)&lt;br&gt;then we set the config file(*.dll.config, *.exe.config) name (if any)&lt;br&gt;then we create the appdomain using the setup information&amp;nbsp; and using the same security eveidance of the base application (This can be changed to limit the security level if needed)&lt;br&gt;&lt;br&gt;We are now ready to load the plugin, next we are going to reflect the plugin and get all the Pluggable classes and for every Pluggable class get all Runnable functions&lt;br&gt;First this module will get all the pluggable classes from the assembly&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;&lt;/span&gt;&lt;span class="rem"&gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; Type[] GetModules(&lt;span class="kwrd"&gt;string&lt;/span&gt; filename, AppDomain domain)&lt;br&gt;        {&lt;br&gt;            Assembly assembly = domain.Load(filename);&lt;br&gt;            List&amp;lt;Type&amp;gt; plugins = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Type&amp;gt;();&lt;br&gt;            Type[] types = assembly.GetTypes();&lt;br&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Type type &lt;span class="kwrd"&gt;in&lt;/span&gt; types)&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (type.GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(PluggableAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;).Length &amp;gt; 0)&lt;br&gt;                {&lt;br&gt;                        plugins.Add(type);&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; plugins.ToArray();&lt;br&gt;        }&lt;/pre&gt;Then we need the module that gets all the Runnable functions from the Pluggable types and run them&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RunTypes(Type[] types)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Type type &lt;span class="kwrd"&gt;in&lt;/span&gt; types)&lt;br&gt;            {&lt;br&gt;                Object obj = type.InvokeMember(&lt;span class="kwrd"&gt;null&lt;/span&gt;, BindingFlags.CreateInstance, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;br&gt;                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (MethodInfo method &lt;span class="kwrd"&gt;in&lt;/span&gt; type.GetMethods())&lt;br&gt;                {&lt;br&gt;                    &lt;span class="rem"&gt;//instanciating object from the type specified&lt;/span&gt;&lt;br&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (method.GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(RunnableAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;).Length &amp;gt; 0)&lt;br&gt;                    {&lt;br&gt;                        &lt;span class="rem"&gt;//running the runnable function&lt;/span&gt;&lt;br&gt;                        method.Invoke(obj, &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;br&gt;                    }&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;        }&lt;/pre&gt;so now we have everything we need to create a plugin manager class that does these things&lt;br&gt;&lt;ol&gt;&lt;li&gt;Load the Dll&lt;/li&gt;&lt;li&gt;Reflect all the pluggable types&lt;/li&gt;&lt;li&gt;Reflect all the Runnable methods&lt;/li&gt;&lt;li&gt;Instantiating objects from Runnable classes&lt;/li&gt;&lt;li&gt;Run the methods&lt;/li&gt;&lt;/ol&gt;But, Are we finished ???&lt;br&gt;No, we still have something missing, we didn't create the class that will be responsible of creating the plugin manager class in separate domain&amp;nbsp; !!!!&lt;br&gt;Yes, it sounds strange but let's discuss this...&lt;br&gt;We said that using remoting is the only way (I found) to load dll's in a separate domain, which means that we need a MarshalByRefObject class that handle the plugin, so first we need to put all the methods we made in one class the inherits from MarshalByRefObject, so we can instantiate object from it using remoting...&lt;br&gt;and this how the PluginManager class will look like&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; PluginManager : MarshalByRefObject&lt;br&gt;{&lt;br&gt;     &lt;span class="kwrd"&gt;private&lt;/span&gt; Type[] GetModules(&lt;span class="kwrd"&gt;string&lt;/span&gt; filename, AppDomain domain)&lt;br&gt;        {&lt;br&gt;            Assembly assembly = domain.Load(filename);&lt;br&gt;            List&amp;lt;Type&amp;gt; plugins = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Type&amp;gt;();&lt;br&gt;            Type[] types = assembly.GetTypes();&lt;br&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Type type &lt;span class="kwrd"&gt;in&lt;/span&gt; types)&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (type.GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(PluggableAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;).Length &amp;gt; 0)&lt;br&gt;                {&lt;br&gt;                        plugins.Add(type);&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; plugins.ToArray();&lt;br&gt;        }&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RunTypes(Type[] types)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Type type &lt;span class="kwrd"&gt;in&lt;/span&gt; types)&lt;br&gt;            {&lt;br&gt;                Object obj = type.InvokeMember(&lt;span class="kwrd"&gt;null&lt;/span&gt;, BindingFlags.CreateInstance, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;br&gt;                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (MethodInfo method &lt;span class="kwrd"&gt;in&lt;/span&gt; type.GetMethods())&lt;br&gt;                {&lt;br&gt;                    &lt;span class="rem"&gt;//instanciating object from the type specified&lt;/span&gt;&lt;br&gt;                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (method.GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(RunnableAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;).Length &amp;gt; 0)&lt;br&gt;                    {&lt;br&gt;                        &lt;span class="rem"&gt;//running the runnable function&lt;/span&gt;&lt;br&gt;                        method.Invoke(obj, &lt;span class="kwrd"&gt;null&lt;/span&gt;);&lt;br&gt;                    }&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RunMethods(string fileName, AppDomain domain)&lt;br&gt;        {&lt;br&gt;            RunTypes(&lt;span class="kwrd"&gt;this&lt;/span&gt;.GetModules(filename, domain));&lt;br&gt;        }&lt;br&gt;}&lt;/pre&gt;&lt;br&gt;then we create another class (let's call it PluginLoader) which is responsible of creating a plugin manager object using remoting, so the code will be something like this&lt;br&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; PluginLoader&lt;br&gt;{&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Run(&lt;span class="kwrd"&gt;string&lt;/span&gt; filename, AppDomain domain)&lt;br&gt;        {&lt;br&gt;                &lt;span class="rem"&gt;//Creating an object of PluginManager using remoting&lt;/span&gt;&lt;br&gt;                PluginManager plugin = appdomain.CreateInstanceAndUnwrap(AssemblyName.GetAssemblyName(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,&lt;br&gt;                &lt;span class="str"&gt;"PluginModule.dll"&lt;/span&gt;)).FullName, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(PluginManager).FullName) &lt;span class="kwrd"&gt;as&lt;/span&gt; PluginManager;&lt;br&gt;                domain.AssemblyResolve += &lt;span class="kwrd"&gt;new&lt;/span&gt; ResolveEventHandler(Domain_AssemblyResolve);&lt;br&gt;                plugin.RunMethods(fileName, domain);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;static&lt;/span&gt; Assembly Domain_AssemblyResolve(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, ResolveEventArgs args)&lt;br&gt;        {&lt;br&gt;            AppDomain domain = sender &lt;span class="kwrd"&gt;as&lt;/span&gt; AppDomain;&lt;br&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; pluginFolder = domain.RelativeSearchPath;&lt;br&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; path = Path.Combine(pluginFolder, args.Name.Split(&lt;span class="str"&gt;','&lt;/span&gt;)[0] + &lt;span class="str"&gt;".dll"&lt;/span&gt;);&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; domain.Load(AssemblyName.GetAssemblyName(path));&lt;br&gt;        }&lt;br&gt;}&lt;/pre&gt;so as you see the PluginLoader class has one public static method called Run, that takes the filename and the target appdomain, and it creates an object of type PluginManager in the appdomain and runs the functions inside its appdomain...&lt;br&gt;final thing, sometime the plugins dll's have some dependencies, and this is what the AssemblyResolve event does, so we added&amp;nbsp; an event handler that takes care of this, becausewhen a dll needs a dependency dll, the system will first look in the GAC, then look inside the Application Bin, and if both of the actions failed, it will fire this event to the programmer to provide the missing dll and that what we do,&lt;br&gt;&lt;br&gt;Finally, I hope that you find what you were looking for in this post, and if you need more help you can contact me and I'll be glad to help you.&lt;br&gt;Regards&lt;br&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/05/17/72.aspx" mce_href="http://www.dotnetkicks.com/kick/?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/05/17/72.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/05/17/72.aspx" mce_src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://spellcoder.com/blogs/bashmohandes/archive/2006/05/17/72.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;&lt;br&gt;&lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;Updated, Sample solution is attached&lt;/span&gt;&lt;br&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8666750" width="1" height="1"&gt;</content><author><name>mohammed hossam</name><uri>http://blogs.msdn.com/mohammed-hossam/ProfileUrlRedirect.ashx</uri></author><category term="C#" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/C_2300_/" /><category term="Architecture" scheme="http://blogs.msdn.com/b/bashmohandes/archive/tags/Architecture/" /></entry></feed>
