<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://weblogs.asp.net/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">Dan Wahlin&amp;#39;s WebLog</title><subtitle type="html">ASP.NET, AJAX, Silverlight, XML, and Web Services Exploration</subtitle><id>http://weblogs.asp.net/dwahlin/atom.aspx</id><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/default.aspx" /><link rel="self" type="application/atom+xml" href="http://weblogs.asp.net/dwahlin/atom.aspx" /><generator uri="http://communityserver.org" version="3.0.20510.895">Community Server</generator><updated>2008-05-09T17:30:02Z</updated><entry><title>Pros and Cons of the Sprint Instinct Phone</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/06/26/pros-and-cons-of-the-sprint-instinct-phone.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/06/26/pros-and-cons-of-the-sprint-instinct-phone.aspx</id><published>2008-06-26T20:03:00Z</published><updated>2008-06-26T20:03:00Z</updated><content type="html">&lt;P mce_keep="true"&gt;There’s been a lot of hype over Apple’s new &lt;A href="http://www.apple.com/iphone/" target=_blank mce_href="http://www.apple.com/iphone/"&gt;iPhone 3G&lt;/A&gt; coming out on July 11th as well as Sprint’s recently released &lt;A href="http://www.instinctthephone.com/?id12=UHP_Masthead_062008_instinctthephone" target=_blank mce_href="http://www.instinctthephone.com/?id12=UHP_Masthead_062008_instinctthephone"&gt;Instinct&lt;/A&gt; phone.&amp;nbsp; I was originally going to switch over to AT&amp;amp;T and get the iPhone but it meant switching my wife &lt;A href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/samsung_sprint_instinct_4.jpg" mce_href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/samsung_sprint_instinct_4.jpg"&gt;&lt;IMG title=samsung_sprint_instinct style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=346 alt=samsung_sprint_instinct src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/samsung_sprint_instinct_thumb_1.jpg" width=267 align=right border=0 mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/samsung_sprint_instinct_thumb_1.jpg"&gt;&lt;/A&gt; over as well since we need to be able to call each other without using plan minutes.&amp;nbsp; After evaluating the cost of switching carriers we decided it wasn’t worth it since we’d have to pay $400 to get out of our Sprint contracts and my wife recently bought the PPC-6800 Windows Mobile phone which wasn’t cheap.&amp;nbsp; We’ve been very happy with Sprint’s network in our area as well.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/sprint-instinct_2.jpg" mce_href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/sprint-instinct_2.jpg"&gt;&lt;IMG title=sprint-instinct style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=180 alt=sprint-instinct src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/sprint-instinct_thumb.jpg" width=240 align=left border=0 mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/sprint-instinct_thumb.jpg"&gt;&lt;/A&gt;Before getting the Instinct I had a PPC-6700 so I had to choose between going away from a Windows Mobile phone to a totally different type of touch screen phone that wasn’t based on Windows.&amp;nbsp; With a Windows Mobile phone you have full control over just about anything you want which is nice if you’re a power user.&amp;nbsp; But, the flexibility does come at a price.&amp;nbsp; I also had the problem of not being able to answer calls on occasion, having to reboot almost daily, poor battery life, plus a few others.&amp;nbsp; Truth be told, I really liked my Windows Mobile phone overall and would buy another one. But, after thinking things through more I came to the conclusion that I mainly used my PPC-6700 for calls, text messaging and the Web and that all of the other bells and whistles were rarely used.&amp;nbsp; I decided to give the Instinct a try since I really liked the touch screen when I tried out the demo version at the Sprint store and liked some of the features it had such as built-in GPS and streaming TV/radio support.&lt;/P&gt;
&lt;P&gt;Here’s what I really like about the Sprint Instinct:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Visual Voice Mail&lt;/STRONG&gt; – I’ve always hated skipping through message after message to get to the one I wanted to listen to.&amp;nbsp; Visual voice mail lets me see my messages just like emails, rewind and fast-forward messages just by sliding my finger on the screen, and deleting messages that I know I don’t need to listen to quickly and easily.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;GPS Navigation –&lt;/STRONG&gt; The Instinct has great GPS navigation capabilities.&amp;nbsp; 2-D and 3-D views are available, voice navigation (which includes announcing street names), directions, etc.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Nice Form Factor&lt;/STRONG&gt; – The Instinct fits into my hands much better than the PPC-6700 I had before and is really light…yet feels solid.&amp;nbsp; I suspect those with a Motorola Q or similar models won’t notice that much of a difference, but coming from a “brick” it’s really nice.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Great Touch Screen&lt;/STRONG&gt; – The touch screen on the Instinct is really, really nice.&amp;nbsp; It’s much better than I was expecting and provides “haptic” feedback.&amp;nbsp; Basically you get a little vibration each time you click something successfully on the screen.&amp;nbsp; Very nice!&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Fast Download Speeds&lt;/STRONG&gt; – From what I’ve heard, Sprint’s EV-DO Rev A network hasn’t officially been turned on yet (last I heard that would happen in July sometime) but the download speeds have been really good.&amp;nbsp; Good enough that I can stream music or TV from home using &lt;A href="http://www.orb.com/" target=_blank mce_href="http://www.orb.com"&gt;Orb&lt;/A&gt; quite easily (if you’re going to use Orb with Instinct &lt;A href="http://www.instinct-samsung.com/index.php/topic,680.0.html" target=_blank mce_href="http://www.instinct-samsung.com/index.php/topic,680.0.html"&gt;check out this post&lt;/A&gt;).&amp;nbsp; &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;POP/IMAP Email&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;Access&lt;/STRONG&gt; – Some of the early reviews I saw said that you could only integrate with Web-based email accounts like Hotmail or GMail.&amp;nbsp; That’s not true at all.&amp;nbsp; I’m able to successfully access POP or IMAP email accounts easily and get nice notifications when an email arrives.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Speech to Action &lt;/STRONG&gt;– Need to find a gas station or restaurant that’s close to where you are?&amp;nbsp; Want to call or text someone? The Instinct has integrated “speech to action” features that integrate with Live Search, the phone, text messaging, etc.&amp;nbsp; Say the business name you want and instantly get access to directions, maps, etc. (assuming it can find the place of course).&amp;nbsp; The voice recognition doesn’t require training and has worked well for me so far.&amp;nbsp; It can be trained for additional accuracy too through the settings dialog.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Traffic&lt;/STRONG&gt; – I carpool to downtown Phoenix now so I’m not as worried about traffic as I used to be, but the Instinct’s GPS features also allow traffic information to be viewed including accidents, average freeway speeds, etc.&amp;nbsp; Haven’t used that feature a ton but did try it out twice and it seemed fairly accurate.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Fast Access to News/Sports/Weather&lt;/STRONG&gt; – The Instinct provides nice news and weather viewers to get information about all kinds of things.&amp;nbsp; Radar maps are also available for the weather.&lt;A href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/samsung-instinct0_2.jpg" mce_href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/samsung-instinct0_2.jpg"&gt;&lt;IMG title=samsung-instinct0 style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=362 alt=samsung-instinct0 src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/samsung-instinct0_thumb.jpg" width=190 align=right border=0 mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/samsung-instinct0_thumb.jpg"&gt;&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Solid Bluetooth Support&lt;/STRONG&gt; – My PPC-6700 had Bluetooth support but I had to turn it off and on each time I got in my truck so that it would properly sync.&amp;nbsp; The Instinct’s Bluetooth support is much, much better.&amp;nbsp; It syncs perfectly every time with my system and can also be used with stereo Bluetooth headphones (which I don’t have…so I don’t know how well that feature works).&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;TV/Radio&lt;/STRONG&gt; -&amp;nbsp; I don’t watch TV much, but the Instinct makes it easy to watch a wide variety of TV shows on the device and provides many radio stations as well.&amp;nbsp; The quality of the streamed music has been great even while driving.&amp;nbsp; I listened to a station while driving for about 30 minutes last night with only a few hiccups.&amp;nbsp; As mentioned earlier, I use &lt;A href="http://www.orb.com/" target=_blank mce_href="http://www.orb.com"&gt;Orb&lt;/A&gt; to stream TV or music from my home PC to my Instinct as well…I highly recommend Orb.&amp;nbsp; All of this should get even better once the EV-DO Rev A network hits the airwaves.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Java Based&lt;/STRONG&gt; – Because the Instinct uses Java behind the scenes a lot of &lt;A href="http://www.instinct-samsung.com/index.php?action=search2" target=_blank mce_href="http://www.instinct-samsung.com/index.php?action=search2"&gt;custom apps and games&lt;/A&gt; can be run on it.&amp;nbsp; There are precious few applications out there right now for the Instinct (although I have found some games that work fine).&amp;nbsp; Sprint is running a &lt;A href="http://developer.sprint.com/instinct/" target=_blank mce_href="http://developer.sprint.com/instinct/"&gt;developer contest&lt;/A&gt; so I suspect we’ll see a flood of apps coming out soon.&amp;nbsp; I’m a &lt;A href="http://msdn.microsoft.com/" target=_blank mce_href="http://msdn.microsoft.com"&gt;Microsoft .NET developer&lt;/A&gt; but since there are a ton of mobile Java applications out there I’m guessing many will be ported to the Instinct.&amp;nbsp; Time to brush up on my Java some.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;SD Card&lt;/STRONG&gt; – Music and other items can be stored on an SD card (up to 8gig).&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Battery Life&lt;/STRONG&gt; – For people that don’t have Windows Mobile phones this probably won’t be a big deal.&amp;nbsp; My PPC-6700 had horrible battery life though so it’s nice to have a phone that lasts a long time even when watching TV or streaming music.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Here’s what I don’t love about the phone:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;STRONG&gt;Internet Browser&lt;/STRONG&gt; – The Internet browser built-into the Instinct works fine for many sites and provides a way to zoom in and out and easily scroll down to different parts of a site.&amp;nbsp; However, it’s nothing compared to the &lt;A href="http://www.operamini.com/" target=_blank mce_href="http://www.operamini.com/"&gt;Opera Mini&lt;/A&gt; browser.&amp;nbsp; Unfortunately, the Opera Mini browser doesn’t currently work on the Instinct.&amp;nbsp; I suspect it will in the future given all of the interest in the device but we’ll have to wait and see.&amp;nbsp; The built-in browser can only be viewed in landscape mode which is annoying at times as well.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Load Issue (minor issue)&lt;/STRONG&gt; – The phone normally boots up really fast when I turn it all the way off.&amp;nbsp; However, there have been 2 times where the load screen sat there for 5+ minutes.&amp;nbsp; After some time it loads fine, but it’s annoying when it has the temporary hang.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;Ring tones&lt;/STRONG&gt; – I always use custom MP3 ring tones and although the Instinct includes some nice ones, there’s no &lt;EM&gt;built-in way&lt;/EM&gt; to add your own custom ring tones.&amp;nbsp; However, you can go to &lt;A href="http://www.myxer.com/" mce_href="http://www.myxer.com"&gt;http://www.myxer.com&lt;/A&gt; and take care of that quite easily.&amp;nbsp; Myxer provides a simple way to upload a music file (or wallpaper), adjust which parts you want to be your ring tone and then download it on your phone.&amp;nbsp; Read more about making custom ring tones &lt;A href="http://www.instinct-samsung.com/index.php/topic,407.0.html" target=_blank mce_href="http://www.instinct-samsung.com/index.php/topic,407.0.html"&gt;here&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;No Voice Recording&lt;/STRONG&gt; – I like to &lt;A href="http://weblogs.asp.net/dwahlin/archive/2008/04/27/silverlight-the-song.aspx" target=_blank mce_href="http://weblogs.asp.net/dwahlin/archive/2008/04/27/silverlight-the-song.aspx"&gt;write and record music&lt;/A&gt; in my spare time and frequently used a program on my PPC-6700 to record song ideas I had so that I didn’t forget them.&amp;nbsp; I haven’t found a way to do voice recording on the Instinct yet although it certainly has the technology in place.&amp;nbsp; Time to write an application that can do that I guess.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;TV/Radio Doesn’t Stream Sometimes&lt;/STRONG&gt; – I mentioned earlier that I really like the TV and radio support built-into the Instinct.&amp;nbsp; On a few occasions I would try to watch a TV show or stream a radio station and get nothing.&amp;nbsp; I suspect it was a network issue at the time or something along those lines.&amp;nbsp; The TV/radio features seem to work great overall though.&lt;/LI&gt;
&lt;LI&gt;&lt;STRONG&gt;No Themes/Skins&lt;/STRONG&gt; – The Instinct only comes with 1 theme which can’t be changed at this point.&amp;nbsp; I’m surprised they didn’t offer several themes/skins.&amp;nbsp; If someone wants a more iPhone looking interface then that should certainly be possible (I do like the overall interface of the iPhone much better….seems cleaner).&amp;nbsp; I’m hoping that Sprint or a 3rd party company will release different themes that can be used on the phone.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;A href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/Sprint_1_2.jpg" mce_href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/Sprint_1_2.jpg"&gt;&lt;IMG title=Sprint_1 style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=144 alt=Sprint_1 src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/Sprint_1_thumb.jpg" width=240 align=left border=0 mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/SprintInstinctProsandCons_9D36/Sprint_1_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;I have 30 days to try out the Instinct and if I don’t end up liking it I’ll turn it in for a PPC-6800.&amp;nbsp; However, at this point I’m really happy with it and although there are a few annoyances (what product doesn’t have them though?) I’m planning on keeping it at this point.&amp;nbsp; For a first version device they did an amazing job and I think Sprint has a winner on their hands.&amp;nbsp; It’s no iPhone killer in my opinion having played with some friends’ iPhones in the past, but once they make a better browser available it’ll definitely blur the lines between the two devices.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG title=Twitter height=60 alt=Twitter src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/PushingDatatoaSilverlightClientwithaWCFD_89D4/Twitter_5.jpg" width=219 align=left border=0 mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/PushingDatatoaSilverlightClientwithaWCFD_89D4/Twitter_5.jpg"&gt;&amp;nbsp; Already on Twitter and interested in getting live updates about blog posts and other information?&amp;nbsp; Subscribe to my Twitter feed at &lt;A href="http://www.twitter.com/DanWahlin" mce_href="http://www.twitter.com/DanWahlin"&gt;http://www.twitter.com/DanWahlin&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6324160" width="1" height="1"&gt;</content><author><name>dwahlin</name><uri>http://weblogs.asp.net/members/dwahlin.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/dwahlin/archive/tags/.NET/default.aspx" /><category term="Phone" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Phone/default.aspx" /><category term="Java" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Java/default.aspx" /><category term="Instinct" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Instinct/default.aspx" /></entry><entry><title>Pushing Data to a Silverlight Client with a WCF Duplex Service – Part II</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/06/19/pushing-data-to-a-silverlight-client-with-a-wcf-duplex-service-part-ii.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/06/19/pushing-data-to-a-silverlight-client-with-a-wcf-duplex-service-part-ii.aspx</id><published>2008-06-19T21:34:21Z</published><updated>2008-06-19T21:34:21Z</updated><content type="html">&lt;p&gt;&lt;/p&gt;  &lt;p&gt;In &lt;a href="http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx" target="_blank"&gt;Part 1&lt;/a&gt; of this series on pushing data to a Silverlight client with a WCF polling duplex service I demonstrated how service contracts and operations can be defined on the server.&amp;#160; WCF has built-in support for duplex communication (two-way communication between a service and a client) but does require a reference to System.ServiceModel.PollingDuplex.dll to make it work with Silverlight.&amp;#160; This assembly is provided in the Silverlight SDK and is currently in “evaluation” mode (the Silverlight go-live license doesn’t apply to it).&amp;#160; With the polling duplex model the Silverlight client does poll the service to check if any messages are queued so it’s not as “pure” as the sockets option available in Silverlight when it comes to pushing data from a server to a client.&amp;#160; However, it offers much greater flexibility when compared to sockets since it isn’t limited to a specific port range and works over HTTP.&amp;#160; &lt;/p&gt;  &lt;p&gt;Let’s take a look at how a Silverlight client can send and receive messages from a polling duplex WCF service and what types of messages are sent between the two.&lt;/p&gt;  &lt;h2&gt;Understanding Polling Duplex Messages&lt;/h2&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;A polling duplex service communicates with a Silverlight client using WCF &lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.aspx" target="_blank"&gt;Message&lt;/a&gt; types.&amp;#160; This provides complete control over the data sent between the client and the service and allows communication between the two to be loosely coupled.&amp;#160; The downside of this is that messages must be manually serialized/deserialized by the client and service since the WSDL type information uses the &lt;strong&gt;xs:any&lt;/strong&gt; element.&amp;#160; Here’s what the service’s WSDL types section looks like (notice the inclusion of the xs:any element) when a service uses the Message type as a parameter for an operation:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:schema &lt;/span&gt;&lt;span style="color: red"&gt;elementFormDefault&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;qualified&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;targetNamespace&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/Message&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;xmlns:xs&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://www.w3.org/2001/XMLSchema&lt;/span&gt;&amp;quot; 
  &lt;span style="color: red"&gt;xmlns:tns&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://schemas.microsoft.com/Message&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:complexType &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;MessageBody&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:sequence&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/span&gt;&lt;strong&gt;&lt;span style="color: #a31515"&gt;xs:any &lt;/span&gt;&lt;span style="color: red"&gt;minOccurs&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;maxOccurs&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;unbounded&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;namespace&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;##any&lt;/span&gt;&amp;quot;&lt;/strong&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;/&amp;gt;&lt;/strong&gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:sequence&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:complexType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:schema&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;An example of using the WCF Message type in a WCF service is shown next.&amp;#160; Details about this code were covered in &lt;a href="http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx" target="_blank"&gt;Part I&lt;/a&gt; of this series.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel.Channels;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Threading;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;WCFPushService
{
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;GameStreamService &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;IGameStreamService
    &lt;/span&gt;{
        &lt;span style="color: #2b91af"&gt;IGameStreamClient &lt;/span&gt;_Client;
        &lt;span style="color: #2b91af"&gt;Game &lt;/span&gt;_Game = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
        &lt;span style="color: #2b91af"&gt;Timer &lt;/span&gt;_Timer = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
        &lt;span style="color: #2b91af"&gt;Random &lt;/span&gt;_Random = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Random&lt;/span&gt;();

        &lt;span style="color: blue"&gt;public &lt;/span&gt;GameStreamService()
        {
            _Game = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Game&lt;/span&gt;();
        }

        &lt;span style="color: blue"&gt;public void &lt;/span&gt;GetGameData(&lt;span style="color: #2b91af"&gt;Message &lt;/span&gt;receivedMessage)
        {

            &lt;span style="color: green"&gt;//Get client callback channel
            &lt;/span&gt;_Client = &lt;span style="color: #2b91af"&gt;OperationContext&lt;/span&gt;.Current.GetCallbackChannel&amp;lt;&lt;span style="color: #2b91af"&gt;IGameStreamClient&lt;/span&gt;&amp;gt;();

            SendData(_Game.GetTeamData());
            &lt;span style="color: green"&gt;//Start timer which when fired sends updated score information to client
            &lt;/span&gt;_Timer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Timer&lt;/span&gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TimerCallback&lt;/span&gt;(_Timer_Elapsed), &lt;span style="color: blue"&gt;null&lt;/span&gt;, 5000, &lt;span style="color: #2b91af"&gt;Timeout&lt;/span&gt;.Infinite);
        }

        &lt;span style="color: blue"&gt;private void &lt;/span&gt;_Timer_Elapsed(&lt;span style="color: blue"&gt;object &lt;/span&gt;data)
        {
            SendData(_Game.GetScoreData());
            &lt;span style="color: blue"&gt;int &lt;/span&gt;interval = _Random.Next(3000, 7000);
            _Timer.Change(interval, &lt;span style="color: #2b91af"&gt;Timeout&lt;/span&gt;.Infinite);
        }

        &lt;span style="color: blue"&gt;private void &lt;/span&gt;SendData(&lt;span style="color: blue"&gt;object &lt;/span&gt;data)
        {
            &lt;span style="color: #2b91af"&gt;Message &lt;/span&gt;gameDataMsg = &lt;span style="color: #2b91af"&gt;Message&lt;/span&gt;.CreateMessage(
                &lt;span style="color: #2b91af"&gt;MessageVersion&lt;/span&gt;.Soap11,
                &lt;span style="color: #a31515"&gt;&amp;quot;Silverlight/IGameStreamService/ReceiveGameData&amp;quot;&lt;/span&gt;, data);

            &lt;span style="color: green"&gt;//Send data to the client
            &lt;/span&gt;_Client.ReceiveGameData(gameDataMsg);
        }
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h2&gt;
  &lt;br /&gt;Creating a Silverlight Duplex Polling Receiver Class&lt;/h2&gt;

&lt;p&gt;Calling and receiving data in Silverlight requires a fair amount of code to be written.&amp;#160; Before showing the code to interact with a polling duplex service it’s important to understand the general steps involved.&amp;#160; Here’s what you need to do to send and receive data in a Silverlight client:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference Assemblies and Namespaces&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Reference System.ServiceModel.dll and System.ServiceModel.PollingDuplex.dll in your Silverlight project.&amp;#160; Additional details on where to find the System.ServiceModel.PollingDuplex.dll assembly used by Silverlight can be &lt;a href="http://msdn.microsoft.com/en-us/library/cc645028(VS.95).aspx" target="_blank"&gt;found here&lt;/a&gt;.&lt;/li&gt;

  &lt;li&gt;Import the System.ServiceModel and System.ServiceModel.Channels namespaces.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Create a Factory Object&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Create a PollingDuplexHttpBinding object instance and set the PollTimeout and InactivityTimeout properties (both were discussed in &lt;a href="http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx" target="_blank"&gt;Part 1&lt;/a&gt;).&lt;/li&gt;

  &lt;li&gt;Use the PollingDuplexHttpBinding object to build a channel factory.&lt;/li&gt;

  &lt;li&gt;Open the channel factory and define an asynchronous callback method that is called when the open completes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Create a Channel Object&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Use the factory class to create a channel that points to the service’s HTTP endpoint.&lt;/li&gt;

  &lt;li&gt;Open the channel and define an asynchronous callback method that is called when the open completes.&lt;/li&gt;

  &lt;li&gt;Define a callback method that is called when the channel closes.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Send/Receive Messages&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Create a Message object and send it asynchronously to the service using the channel object.&amp;#160; Define an asynchronous callback method that is called when the send completes.&lt;/li&gt;

  &lt;li&gt;Start a message receive loop to listen for messages “pushed” from the service and define a callback method that is called when a message is received.&lt;/li&gt;

  &lt;li&gt;Process data pushed by the server and dispatch it to the Silverlight user interface for display.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that you’ve seen the fundamental steps, let’s take a look at the code that makes this process work.&amp;#160; The following code shows a class named PushDataReceiver that encapsulates the factory and channel classes and handles all of the asynchronous operations that occur.&amp;#160; The class allows an object of type IProcessor to be passed into it along with a service URL, service action and initial data to send to the service (if any).&amp;#160; The IProcessor object represents the actual Silverlight Page class used to update data on the user interface in this case.&amp;#160; As data is received the Page class’s ProcessData() method will be called.&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Net;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel.Channels;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Threading;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.IO;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Xml.Serialization;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;SilverlightPushClient
{
    &lt;span style="color: blue"&gt;public interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IProcessor
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;void &lt;/span&gt;ProcessData(&lt;span style="color: blue"&gt;object &lt;/span&gt;receivedData);
    }

    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PushDataReceiver
    &lt;/span&gt;{
        &lt;span style="color: #2b91af"&gt;SynchronizationContext &lt;/span&gt;_UiThread = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
        &lt;span style="color: blue"&gt;public &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IProcessor &lt;/span&gt;Client { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;public string &lt;/span&gt;ServiceUrl { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;public string &lt;/span&gt;Action { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }
        &lt;span style="color: blue"&gt;public string &lt;/span&gt;ActionData { &lt;span style="color: blue"&gt;get&lt;/span&gt;; &lt;span style="color: blue"&gt;set&lt;/span&gt;; }

        &lt;span style="color: blue"&gt;public &lt;/span&gt;PushDataReceiver(&lt;span style="color: #2b91af"&gt;IProcessor &lt;/span&gt;client, &lt;span style="color: blue"&gt;string &lt;/span&gt;url, &lt;span style="color: blue"&gt;string &lt;/span&gt;action, &lt;span style="color: blue"&gt;string &lt;/span&gt;actionData)
        {
            Client = client;
            ServiceUrl = url;
            Action = action;
            ActionData = actionData;
            _UiThread = &lt;span style="color: #2b91af"&gt;SynchronizationContext&lt;/span&gt;.Current;
        }

        &lt;span style="color: blue"&gt;public void &lt;/span&gt;Start()
        {
            &lt;span style="color: green"&gt;// Instantiate the binding and set the time-outs
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PollingDuplexHttpBinding &lt;/span&gt;binding = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PollingDuplexHttpBinding&lt;/span&gt;()
            {
                PollTimeout = &lt;span style="color: #2b91af"&gt;TimeSpan&lt;/span&gt;.FromSeconds(10),
                InactivityTimeout = &lt;span style="color: #2b91af"&gt;TimeSpan&lt;/span&gt;.FromMinutes(1)
            };

            &lt;span style="color: green"&gt;// Instantiate and open channel factory from binding
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel&lt;/span&gt;&amp;gt; factory =
                binding.BuildChannelFactory&amp;lt;&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel&lt;/span&gt;&amp;gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;BindingParameterCollection&lt;/span&gt;());

            &lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;factoryOpenResult =
                factory.BeginOpen(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;AsyncCallback&lt;/span&gt;(OnOpenCompleteFactory), factory);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(factoryOpenResult.CompletedSynchronously)
            {
                CompleteOpenFactory(factoryOpenResult);
            }
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;OnOpenCompleteFactory(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(result.CompletedSynchronously)
                &lt;span style="color: blue"&gt;return&lt;/span&gt;;
            &lt;span style="color: blue"&gt;else
                &lt;/span&gt;CompleteOpenFactory(result);
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;CompleteOpenFactory(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: #2b91af"&gt;IChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel&lt;/span&gt;&amp;gt; factory =
                (&lt;span style="color: #2b91af"&gt;IChannelFactory&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel&lt;/span&gt;&amp;gt;)result.AsyncState;

            factory.EndOpen(result);

            &lt;span style="color: green"&gt;// The factory is now open. Create and open a channel from the channel factory.
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel &lt;/span&gt;channel =
                factory.CreateChannel(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;EndpointAddress&lt;/span&gt;(ServiceUrl));

            &lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;channelOpenResult =
                channel.BeginOpen(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;AsyncCallback&lt;/span&gt;(OnOpenCompleteChannel), channel);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(channelOpenResult.CompletedSynchronously)
            {
                CompleteOpenChannel(channelOpenResult);
            }
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;OnOpenCompleteChannel(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(result.CompletedSynchronously)
                &lt;span style="color: blue"&gt;return&lt;/span&gt;;
            &lt;span style="color: blue"&gt;else
                &lt;/span&gt;CompleteOpenChannel(result);
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;CompleteOpenChannel(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: #2b91af"&gt;IDuplexSessionChannel &lt;/span&gt;channel = (&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel&lt;/span&gt;)result.AsyncState;

            channel.EndOpen(result);

            &lt;span style="color: green"&gt;// Channel is now open. Send message
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Message &lt;/span&gt;message =
                &lt;span style="color: #2b91af"&gt;Message&lt;/span&gt;.CreateMessage(channel.GetProperty&amp;lt;&lt;span style="color: #2b91af"&gt;MessageVersion&lt;/span&gt;&amp;gt;(),
                 Action , ActionData);
            &lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;resultChannel =
                channel.BeginSend(message, &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;AsyncCallback&lt;/span&gt;(OnSend), channel);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(resultChannel.CompletedSynchronously)
            {
                CompleteOnSend(resultChannel);
            }

            &lt;span style="color: green"&gt;//Start listening for callbacks from the service
            &lt;/span&gt;ReceiveLoop(channel);
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;OnSend(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(result.CompletedSynchronously)
                &lt;span style="color: blue"&gt;return&lt;/span&gt;;
            &lt;span style="color: blue"&gt;else
                &lt;/span&gt;CompleteOnSend(result);
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;CompleteOnSend(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: #2b91af"&gt;IDuplexSessionChannel &lt;/span&gt;channel = (&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel&lt;/span&gt;)result.AsyncState;
            channel.EndSend(result);
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;ReceiveLoop(&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel &lt;/span&gt;channel)
        {
            &lt;span style="color: green"&gt;// Start listening for callbacks.
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result = channel.BeginReceive(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;AsyncCallback&lt;/span&gt;(OnReceiveComplete), channel);
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(result.CompletedSynchronously) CompleteReceive(result);
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;OnReceiveComplete(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(result.CompletedSynchronously)
                &lt;span style="color: blue"&gt;return&lt;/span&gt;;
            &lt;span style="color: blue"&gt;else
                &lt;/span&gt;CompleteReceive(result);
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;CompleteReceive(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: green"&gt;//A callback was received so process data
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel &lt;/span&gt;channel = (&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel&lt;/span&gt;)result.AsyncState;

            &lt;span style="color: blue"&gt;try
            &lt;/span&gt;{
                &lt;span style="color: #2b91af"&gt;Message &lt;/span&gt;receivedMessage = channel.EndReceive(result);

                &lt;span style="color: green"&gt;// Show the service response in the UI.
                &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(receivedMessage != &lt;span style="color: blue"&gt;null&lt;/span&gt;)
                {
                    &lt;span style="color: blue"&gt;string &lt;/span&gt;text = receivedMessage.GetBody&amp;lt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;();
                    _UiThread.Post(Client.ProcessData, text);
                }

                ReceiveLoop(channel);
            }
            &lt;span style="color: blue"&gt;catch &lt;/span&gt;(&lt;span style="color: #2b91af"&gt;CommunicationObjectFaultedException &lt;/span&gt;exp)
            {
                _UiThread.Post(&lt;span style="color: blue"&gt;delegate&lt;/span&gt;(&lt;span style="color: blue"&gt;object &lt;/span&gt;msg) { System.Windows.Browser.&lt;span style="color: #2b91af"&gt;HtmlPage&lt;/span&gt;.Window.Alert(msg.ToString()); }, exp.Message);
            }
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;OnCloseChannel(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(result.CompletedSynchronously)
                &lt;span style="color: blue"&gt;return&lt;/span&gt;;
            &lt;span style="color: blue"&gt;else
                &lt;/span&gt;CompleteCloseChannel(result);
        }

        &lt;span style="color: blue"&gt;void &lt;/span&gt;CompleteCloseChannel(&lt;span style="color: #2b91af"&gt;IAsyncResult &lt;/span&gt;result)
        {
            &lt;span style="color: #2b91af"&gt;IDuplexSessionChannel &lt;/span&gt;channel = (&lt;span style="color: #2b91af"&gt;IDuplexSessionChannel&lt;/span&gt;)result.AsyncState;
            channel.EndClose(result);
        }
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;When the PushDataReceiver class’s Start() method is called by Silverlight it creates a channel factory instance which is used to create a channel instance.&amp;#160; The CompleteOpenChannel() callback method shown previously then sends an initial message to the service endpoint and encapsulates the data to be sent in a WCF Message object.&amp;#160; The message data is then sent along with the proper service action to call on the server.&amp;#160; After the initial message is sent a receive loop is started (see the ReceiveLoop() method) which listens for any messages sent from the server to the client and processes them accordingly.&amp;#160; Once a message is received the CompleteReceive() method is called and the message data is routed back to the Silverlight Page class.&lt;/p&gt;

&lt;h2&gt;Processing Data Using the XmlSerializer Class&lt;/h2&gt;

&lt;p&gt;The PushDataReceiver class shown earlier dispatches data received from the server back to the Silverlight Page class for processing.&amp;#160; Data sent from the server is in XML format and multiple techniques can be used to process it in Silverlight ranging from the XmlReader class to LINQ to XML functionality to the XmlSerializer class.&amp;#160; I chose to use the XmlSerializer class to process the data since it provides a simple way to map XML data to CLR types with a minimal amount of code.&amp;#160; Although you can create the CLR classes that XML data maps to by hand, I chose to create an XSD schema and use .NET’s &lt;a href="http://msdn.microsoft.com/en-us/library/x6c1kb0s(VS.80).aspx" target="_blank"&gt;xsd.exe&lt;/a&gt; tool to generate code from the schema for me.&amp;#160; The xsd.exe tool provides a simple way to generate C# or VB.NET code and ensures that the XML data will be successfully mapped to the appropriate CLR type’s properties.&amp;#160; An example of using the tool is shown next:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;xsd.exe /c /namespace:SomeNamespace Teams.xsd&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The /c switch tells the tool to generate classes (as opposed to strongly-typed DataSets) while the /namespace switch allows you to control what namespace is added into the auto-generated code.&amp;#160; Other switches are available which you can read more about &lt;a href="http://msdn.microsoft.com/en-us/library/x6c1kb0s(VS.80).aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One of the XSD schemas used to generate C# code with xsd.exe is shown next:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #a31515"&gt;xml &lt;/span&gt;&lt;span style="color: red"&gt;version&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;1.0&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;encoding&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;utf-16&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;?&amp;gt;
&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:schema &lt;/span&gt;&lt;span style="color: red"&gt;attributeFormDefault&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;unqualified&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;elementFormDefault&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;qualified&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;xmlns:xs&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;http://www.w3.org/2001/XMLSchema&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:element &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Teams&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:complexType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:sequence&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:element &lt;/span&gt;&lt;span style="color: red"&gt;maxOccurs&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;unbounded&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Team&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:complexType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:sequence&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
              &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:element &lt;/span&gt;&lt;span style="color: red"&gt;maxOccurs&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;unbounded&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Player&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;gt;
                &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:complexType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
                  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:attribute &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;ID&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;xs:string&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;use&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;required&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
                  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:attribute &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Name&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;xs:string&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;use&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;required&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
                &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:complexType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
              &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:element&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:sequence&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:attribute &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;Name&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;xs:string&lt;/span&gt;&amp;quot; &lt;span style="color: red"&gt;use&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;required&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
          &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:complexType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:element&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:sequence&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:complexType&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:element&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;xs:schema&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;Note: If you use the xsd.exe tool to generate classes that will be used in a Silverlight client you’ll have to remove a few lines that don’t compile from the auto-generated code.&amp;#160; The xsd.exe tool generates code designed to run on the full version of the .NET framework but with a few minor modifications you can also use the code with Silverlight.&amp;#160; Simply remove the namespaces and attributes that the compiler says are invalid from the auto-generated code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once data is received by the Silverlight client from the WCF polling duplex service it’s processed by a method named ProcessData() (the method called by the PushDataReceiver class) in the sample application.&amp;#160; ProcessData() uses the XmlSerializer class to deserialize XML data into custom Teams and ScoreData objects (the Teams and ScoreData classes were generated from XSD schemas using the xsd.exe tool mentioned earlier).&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;ProcessData(&lt;span style="color: blue"&gt;object &lt;/span&gt;receivedData)
{
    &lt;span style="color: #2b91af"&gt;StringReader &lt;/span&gt;sr = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
    &lt;span style="color: blue"&gt;try
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;string &lt;/span&gt;data = (&lt;span style="color: blue"&gt;string&lt;/span&gt;)receivedData;
        sr = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StringReader&lt;/span&gt;(data);
        &lt;span style="color: green"&gt;//Get initial team data
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(_Teams == &lt;span style="color: blue"&gt;null &lt;/span&gt;&amp;amp;&amp;amp; data.Contains(&lt;span style="color: #a31515"&gt;&amp;quot;Teams&amp;quot;&lt;/span&gt;))
        {
            &lt;span style="color: #2b91af"&gt;XmlSerializer &lt;/span&gt;xs = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlSerializer&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;Teams&lt;/span&gt;));
            _Teams = (&lt;span style="color: #2b91af"&gt;Teams&lt;/span&gt;)xs.Deserialize(sr);
            UpdateBoard();
        }

        &lt;span style="color: green"&gt;//Get updated score data
        &lt;/span&gt;&lt;span style="color: blue"&gt;if &lt;/span&gt;(data.Contains(&lt;span style="color: #a31515"&gt;&amp;quot;ScoreData&amp;quot;&lt;/span&gt;))
        {
            &lt;span style="color: #2b91af"&gt;XmlSerializer &lt;/span&gt;xs = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;XmlSerializer&lt;/span&gt;(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;ScoreData&lt;/span&gt;));
            &lt;span style="color: #2b91af"&gt;ScoreData &lt;/span&gt;scoreData = (&lt;span style="color: #2b91af"&gt;ScoreData&lt;/span&gt;)xs.Deserialize(sr);
            &lt;span style="color: green"&gt;//ScoreDataHandler handler = new ScoreDataHandler(UpdateScoreData);
            //this.Dispatcher.BeginInvoke(handler, new object[] { scoreData });
            &lt;/span&gt;UpdateScoreData(scoreData);
        }
    }
    &lt;span style="color: blue"&gt;catch &lt;/span&gt;{ }
    &lt;span style="color: blue"&gt;finally
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;if &lt;/span&gt;(sr != &lt;span style="color: blue"&gt;null&lt;/span&gt;) sr.Close();
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;As team and score data is pushed from the server to the client it’s updated on the Silverlight interface as shown next:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/UsingSilverlightandSocketstoStreamScores_148D3/SilverlightSockets_thumb_1.jpg" /&gt; &lt;/p&gt;

&lt;p&gt;The complete code for the application including the WCF duplex polling service and the Silverlight client can be &lt;a href="http://www.xmlforasp.net/CodeBank/Download/Blog/Silverlight2/SilverlightWCFPushService.zip"&gt;downloaded here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.twitter.com/DanWahlin"&gt;&lt;img title="Twitter" height="60" alt="Twitter" src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/PushingDatatoaSilverlightClientwithaWCFD_89D4/Twitter_5.jpg" width="219" align="left" border="0" /&gt;&lt;/a&gt;

  &lt;br /&gt;Already on Twitter and interested in getting live updates about blog posts and other information?&amp;#160; Subscribe to my Twitter feed at &lt;a href="http://www.twitter.com/DanWahlin"&gt;http://www.twitter.com/DanWahlin&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6297362" width="1" height="1"&gt;</content><author><name>dwahlin</name><uri>http://weblogs.asp.net/members/dwahlin.aspx</uri></author><category term="XML" scheme="http://weblogs.asp.net/dwahlin/archive/tags/XML/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/dwahlin/archive/tags/.NET/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/dwahlin/archive/tags/C_2300_/default.aspx" /><category term="WCF" scheme="http://weblogs.asp.net/dwahlin/archive/tags/WCF/default.aspx" /><category term="Silverlight" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Silverlight/default.aspx" /></entry><entry><title>Pushing Data to a Silverlight Client with a WCF Duplex Service - Part I</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/06/16/pushing-data-to-a-silverlight-client-with-wcf-duplex-service-part-i.aspx</id><published>2008-06-16T23:31:00Z</published><updated>2008-06-16T23:31:00Z</updated><content type="html">&lt;p&gt;Silverlight provides several different ways to access data stored in remote locations.&amp;#160; Data can be pulled from Web Services and RESTful services and even pushed from servers down to clients using sockets (see my previous articles on sockets &lt;a href="http://weblogs.asp.net/dwahlin/archive/2008/04/10/pushing-data-to-a-silverlight-client-with-sockets-part-i.aspx" target="_blank" mce_href="http://weblogs.asp.net/dwahlin/archive/2008/04/10/pushing-data-to-a-silverlight-client-with-sockets-part-i.aspx"&gt;here&lt;/a&gt;, &lt;a href="http://weblogs.asp.net/dwahlin/archive/2008/04/13/pushing-data-to-a-silverlight-client-with-sockets-part-ii.aspx" target="_blank" mce_href="http://weblogs.asp.net/dwahlin/archive/2008/04/13/pushing-data-to-a-silverlight-client-with-sockets-part-ii.aspx"&gt;here&lt;/a&gt; and &lt;a href="http://weblogs.asp.net/dwahlin/archive/2008/06/08/creating-a-silverlight-2-client-access-policy-socket-server.aspx" target="_blank" mce_href="http://weblogs.asp.net/dwahlin/archive/2008/06/08/creating-a-silverlight-2-client-access-policy-socket-server.aspx"&gt;here&lt;/a&gt;).&amp;#160; Silverlight 2 Beta 2 introduces another way to push data from a server to a client using Windows Communication Foundation (WCF) and HTTP.&amp;#160; WCF's support for duplex service contracts makes this possible and opens up unique opportunities for pumping data to Silverlight clients.&amp;#160; In this first part of a two part series I'll demonstrate how a WCF push service can be created and cover the steps to get a sample service up and running.&amp;#160; The second article will focus on the client and show how to communicate with a WCF duplex service and listen for data that's sent.&lt;/p&gt;  &lt;p&gt;Many of the WCF services out there follow the simple request-response mechanism to exchange data which works well for many applications.&amp;#160; However, in addition to standard HTTP bindings, WCF also supports several others including a polling duplex binding made specifically for Silverlight which allows a service to push data down to a client as the data changes.&amp;#160; This type of binding isn't as &amp;quot;pure&amp;quot; as the push model available with sockets since the Silverlight client does poll the server to check for any queued messages, but it provides an efficient way to push data to a client without being restricted to a specific port range.&amp;#160; Once a communication channel is opened messages can be sent in either direction.&amp;#160; The Silverlight SDK states the following about how communication works between a Silverlight client and a duplex service:&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;em&gt;&amp;quot;The Silverlight client periodically polls the service on the network layer, and checks for any new messages that the service wants to send on the callback channel. The service queues all messages sent on the client callback channel and delivers them to the client when the client polls the service.&amp;quot;&lt;/em&gt;&lt;/p&gt;  &lt;h2&gt;Creating Contracts&lt;/h2&gt;  &lt;p&gt;When creating a WCF duplex service for Silverlight, the server creates a standard interface with operations.&amp;#160; However, because the server must communicate with the client it also defines a client callback interface.&amp;#160; An example of defining a server interface named IGameStreamService that includes a single service operation is shown next:&lt;/p&gt;  &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;ServiceContract&lt;/span&gt;(Namespace = &lt;span style="color: #a31515"&gt;&amp;quot;Silverlight&amp;quot;&lt;/span&gt;, CallbackContract = &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IGameStreamClient&lt;/span&gt;))]
&lt;span style="color: blue"&gt;public interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IGameStreamService
&lt;/span&gt;{
    [&lt;span style="color: #2b91af"&gt;OperationContract&lt;/span&gt;(IsOneWay = &lt;span style="color: blue"&gt;true&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;void &lt;/span&gt;GetGameData(&lt;span style="color: #2b91af"&gt;Message &lt;/span&gt;receivedMessage);
}&lt;/pre&gt;

&lt;p&gt;
  &lt;br /&gt;This interface is a little different from the standard WCF interfaces you may have seen or created.&amp;#160; First, it includes a CallbackContract property that points to the client interface.&amp;#160; Second, the GetGameData() operation is defined as a one way operation.&amp;#160; Client calls are not immediately returned as a result of setting IsOneWay to true and are pushed to the client instead.&amp;#160; The IGameStreamClient interface assigned to the CallbackContract is shown next.&amp;#160; It allows a message to be sent back to the client by calling the ReceiveGameData() method.&lt;/p&gt;

&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;ServiceContract&lt;/span&gt;]
&lt;span style="color: blue"&gt;public interface &lt;/span&gt;&lt;span style="color: #2b91af"&gt;IGameStreamClient
&lt;/span&gt;{
    [&lt;span style="color: #2b91af"&gt;OperationContract&lt;/span&gt;(IsOneWay = &lt;span style="color: blue"&gt;true&lt;/span&gt;)]
    &lt;span style="color: blue"&gt;void &lt;/span&gt;ReceiveGameData(&lt;span style="color: #2b91af"&gt;Message &lt;/span&gt;returnMessage);
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;h2&gt;Creating the Service&lt;/h2&gt;

&lt;p&gt;Once the server and client contracts are defined a service class can be created that implements the IGameStreamService interface.&amp;#160; The following code creates a service that simulates a basketball game (similar to the one I demonstrated for using Sockets with Silverlight) and sends game updates to a Silverlight client on a timed basis.&amp;#160; &lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel.Channels;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.Threading;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;WCFPushService
{
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;GameStreamService &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;IGameStreamService
    &lt;/span&gt;{
        &lt;span style="color: #2b91af"&gt;IGameStreamClient &lt;/span&gt;_Client;
        &lt;span style="color: #2b91af"&gt;Game &lt;/span&gt;_Game = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
        &lt;span style="color: #2b91af"&gt;Timer &lt;/span&gt;_Timer = &lt;span style="color: blue"&gt;null&lt;/span&gt;;
        &lt;span style="color: #2b91af"&gt;Random &lt;/span&gt;_Random = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Random&lt;/span&gt;();

        &lt;span style="color: blue"&gt;public &lt;/span&gt;GameStreamService()
        {
            _Game = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Game&lt;/span&gt;();
        }

        &lt;span style="color: blue"&gt;public void &lt;/span&gt;GetGameData(&lt;span style="color: #2b91af"&gt;Message &lt;/span&gt;receivedMessage)
        {

            &lt;span style="color: green"&gt;//Get client callback channel
            &lt;/span&gt;_Client = &lt;span style="color: #2b91af"&gt;OperationContext&lt;/span&gt;.Current.GetCallbackChannel&amp;lt;&lt;span style="color: #2b91af"&gt;IGameStreamClient&lt;/span&gt;&amp;gt;();

            SendData(_Game.GetTeamData());
            &lt;span style="color: green"&gt;//Start timer which when fired sends updated score information to client
            &lt;/span&gt;_Timer = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Timer&lt;/span&gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TimerCallback&lt;/span&gt;(_Timer_Elapsed), &lt;span style="color: blue"&gt;null&lt;/span&gt;, 5000, &lt;span style="color: #2b91af"&gt;Timeout&lt;/span&gt;.Infinite);
        }

        &lt;span style="color: blue"&gt;private void &lt;/span&gt;_Timer_Elapsed(&lt;span style="color: blue"&gt;object &lt;/span&gt;data)
        {
            SendData(_Game.GetScoreData());
            &lt;span style="color: blue"&gt;int &lt;/span&gt;interval = _Random.Next(3000, 7000);
            _Timer.Change(interval, &lt;span style="color: #2b91af"&gt;Timeout&lt;/span&gt;.Infinite);
        }

        &lt;span style="color: blue"&gt;private void &lt;/span&gt;SendData(&lt;span style="color: blue"&gt;object &lt;/span&gt;data)
        {
            &lt;span style="color: #2b91af"&gt;Message &lt;/span&gt;gameDataMsg = &lt;span style="color: #2b91af"&gt;Message&lt;/span&gt;.CreateMessage(
                &lt;span style="color: #2b91af"&gt;MessageVersion&lt;/span&gt;.Soap11,
                &lt;span style="color: #a31515"&gt;&amp;quot;Silverlight/IGameStreamService/ReceiveGameData&amp;quot;&lt;/span&gt;, data);

            &lt;span style="color: green"&gt;//Send data to the client
            &lt;/span&gt;_Client.ReceiveGameData(gameDataMsg);
        }
    }
}&lt;/pre&gt;

&lt;p&gt;
  &lt;br /&gt;The service first creates an instance of a Game class in the constructor which handles simulating a basketball game and creating new data that can be sent to the client.&amp;#160; Once the client calls the service's GetGameData() operation (a one-way operation), access to the client's callback interface is retrieved by going through the OperationContext object and calling the GetCallbackChannel() method.&amp;#160; The teams involved in the game are then created on the server and pushed to the client by calling the SendData() method.&amp;#160; This method calls the Game object's GetTeamData() method.&amp;#160; Although not shown here (but included in the sample code), the GetTeamData() method generates an XML message and returns it as a string.&amp;#160; The SendData() method then creates a WCF Message object, defines that SOAP 1.1 will be used (required for this type of communication) and defines the proper action to be used to send the XML data to the client.&amp;#160; The client's ReceiveGameData() operation is then called and the message is ultimately sent to the client.&amp;#160; &lt;/p&gt;

&lt;p&gt;Once the client receives the team data the server will start sending simulated score data on a random basis.&amp;#160; When the Timer object created in the initial call to GetGameData() fires the _Timer_Elapsed() method is called which gets updated score information and pushes it to the Silverlight client by calling the SendData() method.&lt;/p&gt;

&lt;h2&gt;Creating the Service Factory&lt;/h2&gt;

&lt;p&gt;Once the service class is created a service factory can be created along with a service host.&amp;#160; The factory is responsible for creating the appropriate host while the host defines the service endpoint.&amp;#160; An example of creating service factory and host classes is shown next:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;using &lt;/span&gt;System;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel.Activation;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel.Channels;
&lt;span style="color: blue"&gt;using &lt;/span&gt;System.ServiceModel.Configuration;

&lt;span style="color: blue"&gt;namespace &lt;/span&gt;WCFPushService
{
    &lt;span style="color: blue"&gt;public class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PollingDuplexServiceHostFactory &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;ServiceHostFactoryBase
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;public override &lt;/span&gt;&lt;span style="color: #2b91af"&gt;ServiceHostBase &lt;/span&gt;CreateServiceHost(&lt;span style="color: blue"&gt;string &lt;/span&gt;constructorString,
            &lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;[] baseAddresses)
        {
            &lt;span style="color: blue"&gt;return new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PollingDuplexServiceHost&lt;/span&gt;(baseAddresses);
        }
    }

    &lt;span style="color: blue"&gt;class &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PollingDuplexServiceHost &lt;/span&gt;: &lt;span style="color: #2b91af"&gt;ServiceHost
    &lt;/span&gt;{
        &lt;span style="color: blue"&gt;public &lt;/span&gt;PollingDuplexServiceHost(&lt;span style="color: blue"&gt;params &lt;/span&gt;System.&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;[] addresses)
        {
            &lt;span style="color: blue"&gt;base&lt;/span&gt;.InitializeDescription(&lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;GameStreamService&lt;/span&gt;), &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;UriSchemeKeyedCollection&lt;/span&gt;(addresses));
        }

        &lt;span style="color: blue"&gt;protected override void &lt;/span&gt;InitializeRuntime()
        {
            &lt;span style="color: green"&gt;// Define the binding and set time-outs
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PollingDuplexBindingElement &lt;/span&gt;bindingElement = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;PollingDuplexBindingElement&lt;/span&gt;()
            {
                PollTimeout = &lt;span style="color: #2b91af"&gt;TimeSpan&lt;/span&gt;.FromSeconds(10),
                InactivityTimeout = &lt;span style="color: #2b91af"&gt;TimeSpan&lt;/span&gt;.FromMinutes(1)
            };

            &lt;span style="color: green"&gt;// Add an endpoint for the given service contract
            &lt;/span&gt;&lt;span style="color: blue"&gt;this&lt;/span&gt;.AddServiceEndpoint(
                &lt;span style="color: blue"&gt;typeof&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;IGameStreamService&lt;/span&gt;),
                &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;CustomBinding&lt;/span&gt;(
                    bindingElement,
                    &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TextMessageEncodingBindingElement&lt;/span&gt;(
                        &lt;span style="color: #2b91af"&gt;MessageVersion&lt;/span&gt;.Soap11,
                        System.Text.&lt;span style="color: #2b91af"&gt;Encoding&lt;/span&gt;.UTF8),
                    &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpTransportBindingElement&lt;/span&gt;()),
                    &lt;span style="color: #a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;);

            &lt;span style="color: blue"&gt;base&lt;/span&gt;.InitializeRuntime();
        }
    }
}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;
  &lt;br /&gt;This code was pulled directly from the &lt;a href="http://msdn.microsoft.com/en-us/library/cc645027(VS.95).aspx" target="_blank" mce_href="http://msdn.microsoft.com/en-us/library/cc645027(VS.95).aspx"&gt;Silverlight SDK example&lt;/a&gt; which provides a great starting point for creating WCF/Silverlight polling duplex services.&amp;#160; The service factory class (PollingDuplexServiceHostFactory) creates a new instance of the service host class (PollingDuplexServiceHost) within the CreateServiceHost() method.&amp;#160; The service host class then overrides the InitializeRuntime() method and creates a PollingDuplexBindingElement instance which defines the client's polling and inactivity timeouts.&amp;#160; The Silverlight SDK states the following about the PollingDuplexBindingElement class's PollTimeout and InactivityTimeout properties:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&amp;quot;The PollTimeout property determines the length of time (in milliseconds) that the service holds a poll from the client before returning. The InactivityTimeout property determines the length of time (in milliseconds) that can elapse without any message exchange with the client before the service closes its session.&amp;quot;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The PollingDuplexBindingElement class is located in an assembly named System.ServiceModel.PollingDuplex.dll which is part of the Silverlight SDK.&amp;#160; You'll need to reference the assembly in your WCF project as well as the System.ServiceModel.Channels namespace to use the PollingDuplexBindingElement class.&amp;#160; Once the binding element is created a call is made to the host object's AddServiceEndPoint() method which references the PollingDuplexBindingElement object and the server's IGameStreamService interface to create a custom binding that uses HTTP under the covers for message exchange.&lt;/p&gt;

&lt;p&gt;Once the factory and service classes are created the factory can be referenced in the service's .svc file in the following manner:&lt;/p&gt;

&lt;pre class="code"&gt;&amp;lt;%@ ServiceHost Language=&amp;quot;C#&amp;quot; Factory=&amp;quot;WCFPushService.PollingDuplexServiceHostFactory&amp;quot; %&amp;gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;
  &lt;br /&gt;Looking through all of the code you can see that there's definitely some initial setup work required to get a Silverlight callable WCF duplex service created.&amp;#160; Since the client does have to poll the service to check for queued messages you may wonder what the benefit is over writing a manual polling Silverlight client that calls a WCF service.&amp;#160; Microsoft's &lt;a href="http://weblogs.asp.net/scottgu" target="_blank" mce_href="http://weblogs.asp.net/scottgu"&gt;Scott Guthrie&lt;/a&gt; was kind enough to provide additional details on that subject.&amp;#160; Here's what he had to say:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&amp;quot;The duplex support does use polling in the background to implement notifications – although the way it does it is different than manual polling. It initiates a network request, and then the request is effectively “put to sleep” waiting for the server to respond (it doesn’t come back immediately). The server then keeps the connection open but not active until it has something to send back (or the connection times out after 90 seconds – at which point the duplex client will connect again and wait). This way you are avoiding hitting the server repeatedly – but still get an immediate response when there is data to send.&amp;quot;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When the client polls in the background it sends the following message to the server:&lt;/p&gt;

&lt;pre class="code"&gt;&amp;lt;s:Envelope xmlns:s=&lt;span style="color: #a31515"&gt;&amp;quot;http://schemas.xmlsoap.org/soap/envelope/&amp;quot;&lt;/span&gt;&amp;gt;
    &amp;lt;s:Body&amp;gt;
        &amp;lt;wsmc:MakeConnection xmlns:wsmc=&lt;span style="color: #a31515"&gt;&amp;quot;http://docs.oasis-open.org/ws-rx/wsmc/200702&amp;quot;&lt;/span&gt;&amp;gt;
            &amp;lt;wsmc:Address&amp;gt;
                http:&lt;span style="color: green"&gt;//docs.oasis-open.org/ws-rx/wsmc/200702/anoynmous?id=7f64eefe-9328-4168-8175-1d4b82bef9c3
            &lt;/span&gt;&amp;lt;/wsmc:Address&amp;gt;
        &amp;lt;/wsmc:MakeConnection&amp;gt;
    &amp;lt;/s:Body&amp;gt;
&amp;lt;/s:Envelope&amp;gt;&lt;/pre&gt;

&lt;p&gt;
  &lt;br /&gt;In the next article I'll demonstrate how to call a WCF polling duplex service and listen for data in a Silverlight 2 application.&amp;#160; An example of the Silverlight interface that will be discussed is shown next:&lt;/p&gt;

&lt;p&gt;&lt;img height="453" src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/UsingSilverlightandSocketstoStreamScores_148D3/SilverlightSockets_thumb_1.jpg" width="532" mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/UsingSilverlightandSocketstoStreamScores_148D3/SilverlightSockets_thumb_1.jpg" /&gt; &lt;/p&gt;

&lt;p&gt;In the meantime, you can download the Silverlight 2 Beta 2 sample application including the WCF service and Silverlight client &lt;a class="" href="http://www.xmlforasp.net/CodeBank/Download/Blog/Silverlight2/SilverlightWCFPushService.zip" mce_href="http://www.xmlforasp.net/CodeBank/Download/Blog/Silverlight2/SilverlightWCFPushService.zip"&gt;here&lt;/a&gt;. 

  &lt;br /&gt;

  &lt;br /&gt;

  &lt;br /&gt;

  &lt;br /&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.twitter.com/DanWahlin" target="_blank"&gt;&lt;img title="Twitter" style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="60" alt="Twitter" src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/PushingDatatoaSilverlightClientwithaWCFD_89D4/Twitter_5.jpg" width="219" align="left" border="0" /&gt;&lt;/a&gt; 

  &lt;br /&gt;Interested in getting live updates about blog posts and other information?&amp;#160; Subscribe to my Twitter feed at &lt;a href="http://www.twitter.com/DanWahlin" mce_href="http://www.twitter.com/DanWahlin"&gt;http://www.twitter.com/DanWahlin&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6284094" width="1" height="1"&gt;</content><author><name>dwahlin</name><uri>http://weblogs.asp.net/members/dwahlin.aspx</uri></author></entry><entry><title>Creating a Silverlight 2 Client Access Policy Socket Server</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/06/08/creating-a-silverlight-2-client-access-policy-socket-server.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/06/08/creating-a-silverlight-2-client-access-policy-socket-server.aspx</id><published>2008-06-09T06:57:00Z</published><updated>2008-06-09T06:57:00Z</updated><content type="html">&lt;P&gt;Silverlight 2 provides built-in support for sockets which allows servers to push data to Silverlight clients.&amp;nbsp; By using this feature clients can avoid polling the server on a timed basis to ensure that clients are kept up-to-date.&amp;nbsp; If you're new to the socket features built-into Silverlight 2 you'll want to read my previous posts to get additional details about how data can be pushed from a server to a client:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://weblogs.asp.net/dwahlin/archive/2008/04/10/pushing-data-to-a-silverlight-client-with-sockets-part-i.aspx" target=_blank mce_href="http://weblogs.asp.net/dwahlin/archive/2008/04/10/pushing-data-to-a-silverlight-client-with-sockets-part-i.aspx"&gt;Pushing Data to a Silverlight Client with Sockets: Part I&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://weblogs.asp.net/dwahlin/archive/2008/04/13/pushing-data-to-a-silverlight-client-with-sockets-part-ii.aspx" target=_blank mce_href="http://weblogs.asp.net/dwahlin/archive/2008/04/13/pushing-data-to-a-silverlight-client-with-sockets-part-ii.aspx"&gt;Pushing Data to a Silverlight Client with Sockets: Part II&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Silverlight 2 Beta 2 (and beyond) checks for a client access policy before accessing sockets located on host domain or cross-domain servers.&amp;nbsp; An example of a client access policy for sockets is shown next:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;?&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;xml &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;version&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;1.0&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;encoding &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;utf-8&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;?&amp;gt;
&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;access-policy&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
  &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;cross-domain-access&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;policy&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;allow-from&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;domain &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;uri&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;*&lt;/SPAN&gt;" &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
      &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;allow-from&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
      &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;grant-to&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
        &amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;socket-resource &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;port&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;4530&lt;/SPAN&gt;" &lt;SPAN style="COLOR: red"&gt;protocol&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;=&lt;/SPAN&gt;"&lt;SPAN style="COLOR: blue"&gt;tcp&lt;/SPAN&gt;" &lt;SPAN style="COLOR: blue"&gt;/&amp;gt;
      &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;grant-to&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;policy&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
  &amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;cross-domain-access&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;
&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;access-policy&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;This XML code allows Silverlight to access a TCP socket on port 4530.&amp;nbsp; A range of ports can be specified in the &lt;EM&gt;port&lt;/EM&gt; attribute if needed (ex: 4530-4532).&amp;nbsp; Before Silverlight tries to call a server with a socket, it makes a call to the target server on port 943 to check the client access policy and see if the server allows socket connections.&amp;nbsp; This helps minimize various types of hacker attacks.&amp;nbsp; If a client access policy is available on the server and the policy allows access to the port the client is trying to call, processing of the socket code continues and Silverlight tries to connect.&amp;nbsp; If not, the client will be unable to connect due to access being denied by Silverlight.&lt;/P&gt;
&lt;P&gt;An example of creating a client access policy socket server that Silverlight can connect to on port 943 is shown next:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Collections.Generic;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Text;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Net;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Net.Sockets;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.IO;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Threading;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Reflection;
&lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;System.Configuration;

&lt;SPAN style="COLOR: blue"&gt;namespace &lt;/SPAN&gt;PolicySocketServices
{
    &lt;SPAN style="COLOR: blue"&gt;class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;PolicySocketServer
    &lt;/SPAN&gt;{
        &lt;SPAN style="COLOR: #2b91af"&gt;TcpListener &lt;/SPAN&gt;_Listener = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;
        &lt;SPAN style="COLOR: #2b91af"&gt;TcpClient &lt;/SPAN&gt;_Client = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;
        &lt;SPAN style="COLOR: blue"&gt;static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ManualResetEvent &lt;/SPAN&gt;_TcpClientConnected = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ManualResetEvent&lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;false&lt;/SPAN&gt;);
        &lt;SPAN style="COLOR: blue"&gt;const string &lt;/SPAN&gt;_PolicyRequestString = &lt;SPAN style="COLOR: #a31515"&gt;"&amp;lt;policy-file-request/&amp;gt;"&lt;/SPAN&gt;;
        &lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;_ReceivedLength = 0;
        &lt;SPAN style="COLOR: blue"&gt;byte&lt;/SPAN&gt;[] _Policy = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;
        &lt;SPAN style="COLOR: blue"&gt;byte&lt;/SPAN&gt;[] _ReceiveBuffer = &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;;

        &lt;SPAN style="COLOR: blue"&gt;private void &lt;/SPAN&gt;InitializeData()
        {
            &lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;policyFile = &lt;SPAN style="COLOR: #2b91af"&gt;ConfigurationManager&lt;/SPAN&gt;.AppSettings[&lt;SPAN style="COLOR: #a31515"&gt;"PolicyFilePath"&lt;/SPAN&gt;];
            &lt;SPAN style="COLOR: blue"&gt;using &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;FileStream &lt;/SPAN&gt;fs = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;FileStream&lt;/SPAN&gt;(policyFile, &lt;SPAN style="COLOR: #2b91af"&gt;FileMode&lt;/SPAN&gt;.Open))
            {
                _Policy = &lt;SPAN style="COLOR: blue"&gt;new byte&lt;/SPAN&gt;[fs.Length];
                fs.Read(_Policy, 0, _Policy.Length);
            }
            _ReceiveBuffer = &lt;SPAN style="COLOR: blue"&gt;new byte&lt;/SPAN&gt;[_PolicyRequestString.Length];
        }

        &lt;SPAN style="COLOR: blue"&gt;public void &lt;/SPAN&gt;StartSocketServer()
        {
            InitializeData();

            &lt;SPAN style="COLOR: blue"&gt;try
            &lt;/SPAN&gt;{
                &lt;SPAN style="COLOR: green"&gt;//Using TcpListener which is a wrapper around a Socket
                //Allowed port is 943 for Silverlight sockets policy data
                &lt;/SPAN&gt;_Listener = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;TcpListener&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;IPAddress&lt;/SPAN&gt;.Any, 943);
                _Listener.Start();
                &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Policy server listening..."&lt;/SPAN&gt;);
                &lt;SPAN style="COLOR: blue"&gt;while &lt;/SPAN&gt;(&lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;)
                {
                    _TcpClientConnected.Reset();
                    &lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;.WriteLine(&lt;SPAN style="COLOR: #a31515"&gt;"Waiting for client connection..."&lt;/SPAN&gt;);
                    _Listener.BeginAcceptTcpClient(&lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;AsyncCallback&lt;/SPAN&gt;(OnBeginAccept), &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;);
                    _TcpClientConnected.WaitOne(); &lt;SPAN style="COLOR: green"&gt;//Block until client connects
                &lt;/SPAN&gt;}
            }
            &lt;SPAN style="COLOR: blue"&gt;catch &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;Exception &lt;/SPAN&gt;exp)
            {
                LogError(exp);
            }
        }

        &lt;SPAN style="COLOR: blue"&gt;private void &lt;/SPAN&gt;OnBeginAccept(&lt;SPAN style="COLOR: #2b91af"&gt;IAsyncResult &lt;/SPAN&gt;ar)
        {
            _Client = _Listener.EndAcceptTcpClient(ar);
            _Client.Client.BeginReceive(_ReceiveBuffer, 0, _PolicyRequestString.Length, &lt;SPAN style="COLOR: #2b91af"&gt;SocketFlags&lt;/SPAN&gt;.None,
                &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;AsyncCallback&lt;/SPAN&gt;(OnReceiveComplete), &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;);
        }

        &lt;SPAN style="COLOR: blue"&gt;private void &lt;/SPAN&gt;OnReceiveComplete(&lt;SPAN style="COLOR: #2b91af"&gt;IAsyncResult &lt;/SPAN&gt;ar)
        {
            &lt;SPAN style="COLOR: blue"&gt;try
            &lt;/SPAN&gt;{
                _ReceivedLength += _Client.Client.EndReceive(ar);
                &lt;SPAN style="COLOR: green"&gt;//See if there's more data that we need to grab
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(_ReceivedLength &amp;lt; _PolicyRequestString.Length)
                {
                    &lt;SPAN style="COLOR: green"&gt;//Need to grab more data so receive remaining data
                    &lt;/SPAN&gt;_Client.Client.BeginReceive(_ReceiveBuffer, _ReceivedLength, 
                        _PolicyRequestString.Length - _ReceivedLength,
                        &lt;SPAN style="COLOR: #2b91af"&gt;SocketFlags&lt;/SPAN&gt;.None, &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;AsyncCallback&lt;/SPAN&gt;(OnReceiveComplete), &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;);
                    &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;;
                }

                &lt;SPAN style="COLOR: green"&gt;//Check that &amp;lt;policy-file-request/&amp;gt; was sent from client
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;request = System.Text.&lt;SPAN style="COLOR: #2b91af"&gt;Encoding&lt;/SPAN&gt;.UTF8.GetString(_ReceiveBuffer, 0, _ReceivedLength);
                &lt;SPAN style="COLOR: blue"&gt;if &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;StringComparer&lt;/SPAN&gt;.InvariantCultureIgnoreCase.Compare(request, _PolicyRequestString) != 0)
                {
                    &lt;SPAN style="COLOR: green"&gt;//Data received isn't valid so close
                    &lt;/SPAN&gt;_Client.Client.Close();
                    &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt;;
                }
                &lt;SPAN style="COLOR: green"&gt;//Valid request received....send policy data
                &lt;/SPAN&gt;_Client.Client.BeginSend(_Policy, 0, _Policy.Length, &lt;SPAN style="COLOR: #2b91af"&gt;SocketFlags&lt;/SPAN&gt;.None, 
                    &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;AsyncCallback&lt;/SPAN&gt;(OnSendComplete), &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;);
            }
            &lt;SPAN style="COLOR: blue"&gt;catch &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;Exception &lt;/SPAN&gt;exp)
            {
                _Client.Client.Close();
                LogError(exp);
            }
            _ReceivedLength = 0;
            _TcpClientConnected.Set(); &lt;SPAN style="COLOR: green"&gt;//Allow waiting thread to proceed
        &lt;/SPAN&gt;}

        &lt;SPAN style="COLOR: blue"&gt;private void &lt;/SPAN&gt;OnSendComplete(&lt;SPAN style="COLOR: #2b91af"&gt;IAsyncResult &lt;/SPAN&gt;ar)
        {
            &lt;SPAN style="COLOR: blue"&gt;try
            &lt;/SPAN&gt;{
                _Client.Client.EndSendFile(ar);
            }
            &lt;SPAN style="COLOR: blue"&gt;catch &lt;/SPAN&gt;(&lt;SPAN style="COLOR: #2b91af"&gt;Exception &lt;/SPAN&gt;exp)
            {
                LogError(exp);
            }
            &lt;SPAN style="COLOR: blue"&gt;finally            
            &lt;/SPAN&gt;{
                &lt;SPAN style="COLOR: green"&gt;//Close client socket
                &lt;/SPAN&gt;_Client.Client.Close();
            } 
        }

        &lt;SPAN style="COLOR: blue"&gt;private void &lt;/SPAN&gt;LogError(&lt;SPAN style="COLOR: #2b91af"&gt;Exception &lt;/SPAN&gt;exp)
        {
            &lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;appFullPath = &lt;SPAN style="COLOR: #2b91af"&gt;Assembly&lt;/SPAN&gt;.GetCallingAssembly().Location;
            &lt;SPAN style="COLOR: blue"&gt;string &lt;/SPAN&gt;logPath = appFullPath.Substring(0, appFullPath.LastIndexOf(&lt;SPAN style="COLOR: #a31515"&gt;"\\"&lt;/SPAN&gt;)) + &lt;SPAN style="COLOR: #a31515"&gt;".log"&lt;/SPAN&gt;;
            &lt;SPAN style="COLOR: #2b91af"&gt;StreamWriter &lt;/SPAN&gt;writer = &lt;SPAN style="COLOR: blue"&gt;new &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StreamWriter&lt;/SPAN&gt;(logPath, &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;);
            &lt;SPAN style="COLOR: blue"&gt;try
            &lt;/SPAN&gt;{
                writer.WriteLine(logPath,
                    &lt;SPAN style="COLOR: #2b91af"&gt;String&lt;/SPAN&gt;.Format(&lt;SPAN style="COLOR: #a31515"&gt;"Error in PolicySocketServer: "
                    &lt;/SPAN&gt;+ &lt;SPAN style="COLOR: #a31515"&gt;"{0} \r\n StackTrace: {1}"&lt;/SPAN&gt;, exp.Message, exp.StackTrace));
            }
            &lt;SPAN style="COLOR: blue"&gt;catch &lt;/SPAN&gt;{ }
            &lt;SPAN style="COLOR: blue"&gt;finally
            &lt;/SPAN&gt;{
                writer.Close();
            }
        }
    }
}&lt;BR&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;Looking through the code you'll see that it uses the TcpListener class to listen for incoming client connections.&amp;nbsp; Once a client connects the code checks the request for the following value:&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #a31515"&gt;&amp;lt;policy-file-request/&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;Silverlight automatically sends this text to the policy file socket once it connects.&amp;nbsp; If the request contains the proper value the code writes the contents of the client access policy back to the client stream (see the OnReceiveComplete() method).&amp;nbsp; Once the policy file is received, Silverlight parses it, checks that it allows access to the desired port, and then accepts or rejects the socket call that the application is trying to make.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;An example of the Silverlight GameStream socket application I created to demonstrate the fundamentals of using sockets is shown next.&amp;nbsp; The code for the application can be &lt;A href="http://www.xmlforasp.net/CodeBank/Download/Blog/Silverlight2/SilverlightSockets.zip" target=_blank mce_href="http://www.xmlforasp.net/CodeBank/Download/Blog/Silverlight2/SilverlightSockets.zip"&gt;downloaded here&lt;/A&gt;.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/UsingSilverlightandSocketstoStreamScores_148D3/SilverlightSockets_thumb_1.jpg" mce_src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/UsingSilverlightandSocketstoStreamScores_148D3/SilverlightSockets_thumb_1.jpg"&gt;&lt;/P&gt;
&lt;P&gt;If you're brand new to Silverlight 2 and are interested in getting started with it check out the following video tutorials:&lt;/P&gt;
&lt;H3&gt;Silverlight 2.0 Video Tutorials&lt;/H3&gt;
&lt;P&gt;
&lt;TABLE class="" cellSpacing=4 cellPadding=2 width=608 border=0&gt;
&lt;TBODY&gt;
&lt;TR class=even&gt;
&lt;TD class="" vAlign=top width=414&gt;&lt;STRONG&gt;Part 1: Creating "Hello World" with Silverlight 2 and VS 2008&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=89&gt;&lt;A href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-1-creating-quot-hello-world-quot-with-silverlight-2-and-vs-2008.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-1-creating-quot-hello-world-quot-with-silverlight-2-and-vs-2008.aspx"&gt;Tutorial&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=99&gt;&lt;A href="http://www.smartwebcontrols.com/video" target=_blank mce_href="http://www.smartwebcontrols.com/video"&gt;Video Tutorial&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR class=odd&gt;
&lt;TD class="" vAlign=top width=414&gt;&lt;STRONG&gt;Part 2: Using Layout Management&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=89&gt;&lt;A href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-2-using-layout-management.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-2-using-layout-management.aspx"&gt;Tutorial&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=101&gt;&lt;A href="http://www.smartwebcontrols.com/video" target=_blank mce_href="http://www.smartwebcontrols.com/video"&gt;Video Tutorial&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR class=even&gt;
&lt;TD class="" vAlign=top width=414&gt;&lt;STRONG&gt;Part 3: Using Networking to Retrieve Data and Populate a DataGrid&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=89&gt;&lt;A href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-3-using-networking-to-retrieve-data-and-populate-a-datagrid.aspx"&gt;Tutorial&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=103&gt;&lt;A href="http://www.smartwebcontrols.com/video" target=_blank mce_href="http://www.smartwebcontrols.com/video"&gt;Video Tutorial&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR class=odd&gt;
&lt;TD class="" vAlign=top width=414&gt;&lt;STRONG&gt;Part 4: Using Style Elements to Better Encapsulate Look and Feel&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=89&gt;&lt;A href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-4-using-style-elements-to-better-encapsulate-look-and-feel.aspx"&gt;Tutorial&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=104&gt;&lt;A href="http://www.smartwebcontrols.com/video" target=_blank mce_href="http://www.smartwebcontrols.com/video"&gt;Video Tutorial&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR class=even&gt;
&lt;TD class="" vAlign=top width=414&gt;&lt;STRONG&gt;Part 5: Using the ListBox and DataBinding to Display List Data&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=89&gt;&lt;A href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-5-using-the-listbox-and-databinding-to-display-list-data.aspx"&gt;Tutorial&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=105&gt;&lt;A href="http://www.smartwebcontrols.com/video" target=_blank mce_href="http://www.smartwebcontrols.com/video"&gt;Video Tutorial&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR class=odd&gt;
&lt;TD class="" vAlign=top width=414&gt;&lt;STRONG&gt;Part 6: Using User Controls to Implement Master/Details Scenarios&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=89&gt;&lt;A href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-6-using-user-controls-to-implement-master-detail-scenarios.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-6-using-user-controls-to-implement-master-detail-scenarios.aspx"&gt;Tutorial&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=106&gt;&lt;A href="http://www.smartwebcontrols.com/video" target=_blank mce_href="http://www.smartwebcontrols.com/video"&gt;Video Tutorial&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR class=even&gt;
&lt;TD class="" vAlign=top width=414&gt;&lt;STRONG&gt;Part 7: Using Templates to Customize Control Look and Feel&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=89&gt;&lt;A href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-7-using-control-templates-to-customize-a-control-s-look-and-feel.aspx"&gt;Tutorial&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=107&gt;&lt;A href="http://www.smartwebcontrols.com/video" target=_blank mce_href="http://www.smartwebcontrols.com/video"&gt;Video Tutorial&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR class=odd&gt;
&lt;TD class="" vAlign=top width=414&gt;&lt;STRONG&gt;Part 8: Creating a Digg Desktop Version of our Application using WPF&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=89&gt;&lt;A href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-8-creating-a-digg-desktop-application-using-wpf.aspx" target=_blank mce_href="http://weblogs.asp.net/scottgu/pages/silverlight-tutorial-part-8-creating-a-digg-desktop-application-using-wpf.aspx"&gt;Tutorial&lt;/A&gt;&lt;/TD&gt;
&lt;TD class="" vAlign=top width=108&gt;&lt;A href="http://www.smartwebcontrols.com/video" target=_blank mce_href="http://www.smartwebcontrols.com/video"&gt;Video Tutorial&lt;/A&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6260434" width="1" height="1"&gt;</content><author><name>dwahlin</name><uri>http://weblogs.asp.net/members/dwahlin.aspx</uri></author><category term="XML" scheme="http://weblogs.asp.net/dwahlin/archive/tags/XML/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/dwahlin/archive/tags/.NET/default.aspx" /><category term="Silverlight" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Silverlight/default.aspx" /><category term="Sockets" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Sockets/default.aspx" /></entry><entry><title>New Features in Silverlight 2 Beta 2</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/06/04/new-features-in-silverlight-2-beta-2.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/06/04/new-features-in-silverlight-2-beta-2.aspx</id><published>2008-06-04T18:03:00Z</published><updated>2008-06-04T18:03:00Z</updated><content type="html">&lt;p&gt;Bill Gates and S. Somasegar announced several new features at TechEd for Silverlight Beta 2 that are great additions to the existing functionality.&amp;#160; Here's a list of the highlights in Beta 2:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;UI Framework:&lt;/strong&gt; Beta 2 includes improvements in animation support, error handling and reporting, automation and accessibility support, keyboard input support, and general performance. This release also provides more compatibility between Silverlight and WPF. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Rich Controls:&lt;/strong&gt; Beta 2 includes a new templating model called Visual State Manager that allows for easier templating for controls. Other features include the introduction of a TabControl, text wrapping and scrollbars for TextBox.&amp;#160; DataGrid additions include Autosize, Reorder, Sort, performance increases and more. Most controls are now in the runtime instead of packaged with the application. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Networking Support:&lt;/strong&gt; Beta 2 includes improved Cross Domain support and security enhancements, upload support for WebClient, and duplex communications (&amp;#8220;push&amp;#8221; from server to Silverlight client). &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Rich Base Class Library:&lt;/strong&gt; Beta 2 includes improved threading abilities, LINQ-to-JSON, ADO.NET Data Services support, better support for SOAP and other improvements to make networking and data handling easier. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Deep Zoom:&lt;/strong&gt; Beta 2 introduces a new XML-based file format for Deep Zoom image tiles as well as a new MultiScaleTileSource that enables existing tile databases to utilize Deep Zoom. Better, event driven notification for zoom/pan state is another improvement in Silverlight 2 Beta 2. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Check out Scott Guthrie's blog for a complete list of features and additional details:&amp;#160; &lt;a title="http://weblogs.asp.net/scottgu/archive/2008/06/06/silverlight-2-beta2-released.aspx" href="http://weblogs.asp.net/scottgu/archive/2008/06/06/silverlight-2-beta2-released.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2008/06/06/silverlight-2-beta2-released.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I'll be posting more about the new features soon....stay tuned!&amp;#160; In the meantime, here's where you can get Silverlight 2 Beta 2:&amp;#160; &lt;a title="http://silverlight.net/GetStarted/" href="http://silverlight.net/GetStarted/"&gt;http://silverlight.net/GetStarted/&lt;/a&gt;&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6245525" width="1" height="1"&gt;</content><author><name>dwahlin</name><uri>http://weblogs.asp.net/members/dwahlin.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/dwahlin/archive/tags/.NET/default.aspx" /><category term="Silverlight" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Silverlight/default.aspx" /></entry><entry><title>My Latest Silverlight Articles</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/05/29/my-latest-silverlight-articles.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/05/29/my-latest-silverlight-articles.aspx</id><published>2008-05-30T00:00:00Z</published><updated>2008-05-30T00:00:00Z</updated><content type="html">&lt;P&gt;Over the past few months I've been writing articles for the &lt;A href="http://www.ftponline.com/" target=_blank mce_href="http://www.ftponline.com/"&gt;&lt;U&gt;&lt;FONT style="COLOR: #0066cc" color=#0066cc&gt;.NET Insight&lt;/FONT&gt;&lt;/U&gt;&lt;/A&gt; insight newsletter covering various ASP.NET AJAX concepts.&amp;nbsp; You can &lt;A href="http://weblogs.asp.net/dwahlin/archive/2007/09/18/latest-asp-net-ajax-articles.aspx" target=_blank mce_href="http://weblogs.asp.net/dwahlin/archive/2007/09/18/latest-asp-net-ajax-articles.aspx"&gt;&lt;U&gt;&lt;FONT style="COLOR: #0066cc" color=#0066cc&gt;read those article here&lt;/FONT&gt;&lt;/U&gt;&lt;/A&gt;.&amp;nbsp; I've wrapped up that series and have started writing about Silverlight 1.0.&amp;nbsp; Each week (or so) a new article will be published and I'll update them here so check back.&amp;nbsp; The articles are designed to be focused and concise and get straight to the topic without a lot of fluff.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://www.ftponline.com/channels/net/2007_10/dwahlin/" target=_blank mce_href="http://www.ftponline.com/channels/net/2007_10/dwahlin/"&gt;&lt;FONT style="COLOR: #0066cc" color=#0066cc&gt;&lt;U&gt;Getting Started with Silverlight&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://www.ftponline.com/channels/net/2007_10/dwahlin2/" target=_blank mce_href="http://www.ftponline.com/channels/net/2007_10/dwahlin2/"&gt;&lt;FONT style="COLOR: #0066cc" color=#0066cc&gt;&lt;U&gt;Using Microsoft's Silverlight Control in a Web Site&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://www.ftponline.com/channels/net/2007_10/dwahlin3/" target=_blank mce_href="http://www.ftponline.com/channels/net/2007_10/dwahlin3/"&gt;&lt;FONT style="COLOR: #0066cc" color=#0066cc&gt;&lt;U&gt;Understanding Silverlight's createObject and createObjectEx Methods&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2374" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2374"&gt;&lt;FONT style="COLOR: #800080" color=#800080&gt;&lt;U&gt;Silverlight XAML Primer 1: Exploring Canvases&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2402" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2402"&gt;&lt;FONT style="COLOR: #800080" color=#800080&gt;&lt;U&gt;Silverlight XAML Primer 2: Rectangles, Ellipses, Lines and Text&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2409" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2409"&gt;&lt;U&gt;&lt;FONT style="COLOR: #800080" color=#800080&gt;Silverlight XAML Primer 3: Working with Image Brushes&lt;/FONT&gt;&lt;/U&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2417" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2417"&gt;&lt;U&gt;&lt;FONT style="COLOR: #0066cc" color=#0066cc&gt;Silverlight XAML Primer 4: Working with Linear Gradients&lt;/FONT&gt;&lt;/U&gt;&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2449" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2449"&gt;&lt;U&gt;&lt;FONT style="COLOR: #800080" color=#800080&gt;Silverlight XAML Primer 5: Working with Radial Gradients&lt;/FONT&gt;&lt;/U&gt;&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2455" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2455"&gt;&lt;FONT style="COLOR: #800080" color=#800080&gt;&lt;U&gt;Silverlight XAML Primer 6: Using Inline XAML with Silverlight&lt;/U&gt;&lt;/FONT&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2474" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2474"&gt;&lt;U&gt;&lt;FONT style="COLOR: #800080" color=#800080&gt;Silverlight XAML Primer 7: Embedding Media into Silverlight&lt;/FONT&gt;&lt;/U&gt;&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2488" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2488"&gt;Silverlight XAML Primer 8: Working with XAML Events&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2514" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2514"&gt;Silverlight XAML Primer 9: Using the Silverlight Downloader Object&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://www.ddj.com/windows/206901111?cid=RSSfeed_DDJ_All" target=_blank mce_href="http://www.ddj.com/windows/206901111?cid=RSSfeed_DDJ_All"&gt;Working with Events in Silverlight&lt;/A&gt; &lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2527" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2527"&gt;Silverlight XAML Primer 10: Creating a Silverlight Downloader Progress Bar&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2530" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2530"&gt;Silverlight XAML Primer 11: Getting Started with Animations&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2546" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2546"&gt;Introducing Silverlight 2.0&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2556" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2556"&gt;Silverlight XAML Primer 12: Using Linear Keyframe Animations&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2572" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2572"&gt;Silverlight XAML Primer 13: Starting and Stopping Animations&lt;/A&gt; &lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2605" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2605"&gt;Silverlight XAML Primer 14:&amp;nbsp;Using Color Animations&lt;/A&gt; &lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://www.ddj.com/windows/207402928?cid=RSSfeed_DDJ_All" target=_blank mce_href="http://www.ddj.com/windows/207402928?cid=RSSfeed_DDJ_All"&gt;Socket Support in Silverlight 2: Part I&lt;/A&gt; &lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://www.ddj.com/windows/207602773?cid=RSSfeed_DDJ_All" target=_blank mce_href="http://www.ddj.com/windows/207602773?cid=RSSfeed_DDJ_All"&gt;Socket Support in Silverlight 2: Part II&lt;/A&gt; &lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2619" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2619"&gt;Silverlight XAML Primer 15: Enhancing TextBlock with Runs and LineBreaks&lt;/A&gt;&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2644" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2644"&gt;Creating Your First Silverlight 2 Application&lt;/A&gt; (New!)&lt;/DIV&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;DIV&gt;&lt;A class="" href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2669" target=_blank mce_href="http://visualstudiomagazine.com/columns/article.aspx?editorialsid=2669"&gt;Getting Started with Silverlight 2 Controls&lt;/A&gt; (New!)&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;A video of a talk I gave on integrating Silverlight with ASP.NET AJAX and Web Services can be &lt;A class="" href="http://weblogs.asp.net/dwahlin/archive/2008/01/20/new-video-integrating-silverlight-and-asp-net-ajax.aspx" target=_blank mce_href="http://weblogs.asp.net/dwahlin/archive/2008/01/20/new-video-integrating-silverlight-and-asp-net-ajax.aspx"&gt;viewed here&lt;/A&gt; for those who are interested.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;If you're interested in learning more about Silverlight 2.0 you can view &lt;A class="" href="http://weblogs.asp.net/dwahlin/archive/2008/03/07/silverlight-2-0-video-tutorials.aspx" target=_blank mce_href="http://weblogs.asp.net/dwahlin/archive/2008/03/07/silverlight-2-0-video-tutorials.aspx"&gt;8 video tutorials that I put together here&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=4346912" width="1" height="1"&gt;</content><author><name>dwahlin</name><uri>http://weblogs.asp.net/members/dwahlin.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/dwahlin/archive/tags/.NET/default.aspx" /><category term="Silverlight" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Silverlight/default.aspx" /></entry><entry><title>Desert Code Camp Is This Saturday (May 31st)</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/05/29/desert-code-camp-is-this-saturday-may-31st.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/05/29/desert-code-camp-is-this-saturday-may-31st.aspx</id><published>2008-05-29T21:10:21Z</published><updated>2008-05-29T21:10:21Z</updated><content type="html">&lt;p&gt;&lt;img src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/UsingSilverlightandSocketstoStreamScores_148D3/image_2.png" /&gt;&lt;/p&gt;  &lt;p&gt;Arizona's &lt;a href="http://www.desertcodecamp.com" target="_blank"&gt;Desert Code Camp&lt;/a&gt; is this Saturday (May 31st) at the University of Advanced Computing building.&amp;#160; Here's the address:&lt;/p&gt;  &lt;p&gt;University of Advancing Technology    &lt;br /&gt;2625 W. Baseline Road (&lt;a href="http://www.desertcodecamp.com/map.aspx"&gt;map&lt;/a&gt;)     &lt;br /&gt;Tempe, Arizona 85283&lt;/p&gt;  &lt;p&gt;It looks like there are a lot of great talks scheduled covering everything from iPhone development to game development to line of business applications.&amp;#160; &lt;/p&gt;  &lt;p&gt;I'll be giving a talk titled &lt;strong&gt;Integrating Data Into Silverlight 2 Applications&lt;/strong&gt; (&lt;a href="http://www.xmlforasp.net/codebank/Download/Blog/Silverlight2DataIntegration.zip"&gt;slides and code here&lt;/a&gt;) on behalf of &lt;a href="http://www.interfacett.com" target="_blank"&gt;Interface Technical Training&lt;/a&gt; which is scheduled to start at 11:20 AM and run for about an hour.&amp;#160; I'll cover several different things in the talk such as:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Cross-domain policy files &lt;/li&gt;    &lt;li&gt;Calling WCF and ASMX Services with Silverlight 2 &lt;/li&gt;    &lt;li&gt;Getting data from RESTful services &lt;/li&gt;    &lt;li&gt;Data streaming options &lt;/li&gt;    &lt;li&gt;Binding data to controls &lt;/li&gt;    &lt;li&gt;Socket support in Silverlight 2 (an example of the sample socket application is shown next) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;img height="438" src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/UsingSilverlightandSocketstoStreamScores_148D3/SilverlightSockets_4.jpg" width="516" /&gt;&lt;/p&gt;  &lt;p&gt;Swing on by if you have some time Saturday.&amp;#160; Desert Code Camp is completely free so it's a great way to learn about different topics if you or your company is on a tight budget.&amp;#160; &lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6230400" width="1" height="1"&gt;</content><author><name>dwahlin</name><uri>http://weblogs.asp.net/members/dwahlin.aspx</uri></author><category term="Web Services" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Web+Services/default.aspx" /><category term=".NET" scheme="http://weblogs.asp.net/dwahlin/archive/tags/.NET/default.aspx" /><category term="C#" scheme="http://weblogs.asp.net/dwahlin/archive/tags/C_2300_/default.aspx" /><category term="WCF" scheme="http://weblogs.asp.net/dwahlin/archive/tags/WCF/default.aspx" /><category term="Silverlight" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Silverlight/default.aspx" /><category term="LINQ" scheme="http://weblogs.asp.net/dwahlin/archive/tags/LINQ/default.aspx" /><category term="Sockets" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Sockets/default.aspx" /></entry><entry><title>A Software Developer Trying to Get In Shape with the Wii Fit??</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/05/28/a-software-developer-trying-to-get-in-shape-with-the-wii-fit.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/05/28/a-software-developer-trying-to-get-in-shape-with-the-wii-fit.aspx</id><published>2008-05-28T23:56:34Z</published><updated>2008-05-28T23:56:34Z</updated><content type="html">&lt;p&gt;&lt;em&gt;We interrupt this tech blog for a quick (and pointless) message about trying to get in shape....&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.nintendo.com/wiifit/launch/" target="_blank"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="63" alt="image" src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/GettingInShapewiththeWiiFit_E810/image_3.png" width="170" align="right" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Back in high school and college I played a lot of sports so it was pretty easy to stay in shape without really trying much.&amp;#160; Those years have definitely passed.&amp;#160; Now that I'm getting older and sit staring at the computer hour upon hour (I'll bet my fingers are in good shape from typing so much though!) writing .NET programs it's not so easy so I've recently starting using my &lt;a href="http://totalgym.com/" target="_blank"&gt;Total Gym&lt;/a&gt; machine and running more.&amp;#160; &lt;/p&gt;  &lt;p&gt;My family recently bought the new &lt;a href="http://www.nintendo.com/wiifit/launch/" target="_blank"&gt;Wii Fit&lt;/a&gt; since it sounded like a fun way to play some games while burning a calorie or two.&amp;#160; It's actually been very fun (my wife and kids love it and compete a lot) and we've enjoyed some of the yoga, strength and aerobic exercises in addition to the built-in games.&amp;#160; I always thought yoga looked like a waste of time but now I realize how out of shape and inflexible I really am and that yoga is actually much, much harder than it looks.&amp;#160; I'm only on the beginner levels on Wii Fit and already groaning about it stretching me too much. Even with the groaning, I really like the Wii Fit although it's no substitute for my Total Gym and running exercises from what I've seen so far.&lt;/p&gt;  &lt;p&gt;Moving on....I ordered a rechargeable battery with my Wii Fit which came separate in the mail from Amazon.com a few days back.&amp;#160; Keep in mind that the whole purpose of Wii Fit is to get you in better shape and make you more flexible.&amp;#160; However, here's the coupon that I received along with the Wii Fit battery in the packaging:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/GettingInShapewiththeWiiFit_E810/WiiFiitCoupon_2.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="280" alt="WiiFiitCoupon" src="http://weblogs.asp.net/blogs/dwahlin/WindowsLiveWriter/GettingInShapewiththeWiiFit_E810/WiiFiitCoupon_thumb.jpg" width="255" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I don't know about you, but I'm thinking someone's not coordinating the marketing effort too well!&amp;#160; I doubt that the fried chicken sandwich, fries and Coke (maybe it's diet) are going to help with my Wii Fitness plan (although the sandwich isn't quite as bad as I thought for the &lt;a href="http://app.mcdonalds.com/bagamcmeal?process=item&amp;amp;itemID=5969" target="_blank"&gt;fat content&lt;/a&gt;).&amp;#160; Back to more Wii Fit yoga, strength and aerobics exercises so I can prepare for my southern style chicken sandwich with fries and a non-diet Coke! :-)&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=6227374" width="1" height="1"&gt;</content><author><name>dwahlin</name><uri>http://weblogs.asp.net/members/dwahlin.aspx</uri></author><category term=".NET" scheme="http://weblogs.asp.net/dwahlin/archive/tags/.NET/default.aspx" /><category term="Wii" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Wii/default.aspx" /><category term="Fitness" scheme="http://weblogs.asp.net/dwahlin/archive/tags/Fitness/default.aspx" /></entry><entry><title>Why Unit Tests Matter and How They Will Actually Save You Time</title><link rel="alternate" type="text/html" href="http://weblogs.asp.net/dwahlin/archive/2008/05/27/why-unit-tests-matter-and-how-they-will-actually-save-you-time.aspx" /><id>http://weblogs.asp.net/dwahlin/archive/2008/05/27/why-unit-tests-matter-and-how-they-will-actually-save-you-time.aspx</id><published>2008-05-27T21:27:16Z</published><updated>2008-05-27T21:27:16Z</updated><content type="html">&lt;p&gt;&lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;:&amp;#160; The point of the post is to explain why unit tests can actually save you time in the long run even if you or your boss don't currently use or believe in them.&amp;#160; It's not my goal to go into some silly religious discussion about why unit tests should or should not be used in a project.&amp;#160; There are plenty of forums out there for arguing over various technical concepts and methodologies if you have the time to waste.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Many different philosophies have been proposed that offer solutions for writing quality code.&amp;#160; As a result, two people will generally give two different answers if you question them about the best way to write quality code.&amp;#160; Regardless of your views on writing quality code, testing has to fit into the picture at some point.&amp;#160; We could argue over exactly where testing fits into a project but I don't think anyone would argue that testing can be skipped (and if you're one of those people you can save yourself some time and stop reading now :-)).&lt;/p&gt;  &lt;p&gt;I've never been one of those &amp;quot;letter of the law&amp;quot; people when it comes to just about anything and that applies to concepts like testing code as well.&amp;#160; I believe balance has to be reached regardless of what you're doing.&amp;#160; There is such a thing as going &amp;quot;overboard&amp;quot; when it comes to software development, studying for a test at school, training for sports or many other things.&amp;#160; However, everyone's definition of &amp;quot;overboard&amp;quot; differs and I respect that so I'll move on to the heart of the matter which is unit testing and how it can benefit your projects even if you don't agree with the &amp;quot;letter of the law&amp;quot; people out there.&lt;/p&gt;  &lt;p&gt;If you're new to unit testing, I'll sum up the general concept quickly:&amp;#160; &lt;em&gt;&lt;strong&gt;Write tests followed by code to satisfy those tests&lt;/strong&gt;&lt;/em&gt;.&amp;#160; That one statement doesn't do unit testing justice, but hopefully you get the basic idea.&amp;#160; Do I always write my tests first along with the application's general stub code?&amp;#160; Simple answer is &amp;quot;I try to&amp;quot;.&amp;#160; I try to follow best practices but in reality it doesn't always work out exactly how I want.&amp;#160; &lt;/p&gt;  &lt;p&gt;Regardless of your view on the overall process, unit tests can still provide significant benefits in my opinion even if you write them later in the development process.&amp;#160; The &amp;quot;letter of the law&amp;quot; people out there probably consider that to be completely wrong, but I try hard to keep in mind that everyone and every project has different skill levels, needs and constraints.&amp;#160; Whether you write your unit tests at the beginning, in the middle or even at the end of a project (pushing them off until the end is NOT recommended and your hand should be slapped with a ruler if you do that :-)), they can still provide you many benefits.&lt;/p&gt;  &lt;p&gt;There are numerous Websites dedicated to the topic of unit tests.&amp;#160; Wikipedia provides a nice overview &lt;a href="http://en.wikipedia.org/wiki/Unit_tests" target="_blank"&gt;here&lt;/a&gt;. A few of the benefits unit tests bring to the table include:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Forces more thorough consideration of an application's design &lt;/li&gt;    &lt;li&gt;Simplifies code integration &lt;/li&gt;    &lt;li&gt;Catches bugs more quickly in the development process &lt;/li&gt;    &lt;li&gt;Simplifies maintenance &lt;/li&gt;    &lt;li&gt;Provides visual test results &lt;/li&gt;    &lt;li&gt;Provides a testing history &lt;/li&gt;    &lt;li&gt;Makes you feel better about the stability of your application (assuming you have good code coverage)&lt;/li&gt;    &lt;li&gt;Many more.... &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For some people writing unit tests before writing application code (more than just stub code) is absolutely required for writing good software.&amp;#160; I agree with that stance overall since if you build testing into a project from the beginning then you should definitely have higher quality code in the end if you stick with it and ensure that you've achieved good code coverage with your tests.&amp;#160; However, I've also been on projects where writing all of the unit tests up front simply wasn't going to happen due to the time constraints (which are sometimes ridiculously out of touch with reality) placed on a project.&amp;#160; Regardless of your situation, unit tests can still help you in the short-term and long-term.&amp;#160; &lt;/p&gt;  &lt;p&gt;Here are a few reasons you should consider using them if you're not already.&amp;#160; I've found that they actually save time in the long run if you spend a little time up front.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;How many times have you written test harness code to test a particular feature?&lt;/strong&gt;&amp;#160; A lot of people whip up a quick console project (or multiple console projects) to do this type of thing.&amp;#160; By using unit tests you can save yourself the time of writing test harnesses since unit test frameworks do that for you plus have the ability to run the tests anytime and see their status (green light, red light) aggregated together in one nice report.&amp;#160; If you've never w