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

<channel>
	<title>Zleek Speak</title>
	<atom:link href="http://zleek.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://zleek.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Thu, 12 Nov 2009 03:55:03 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='zleek.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/1d02e291f135c5c8d52cfd2e5ac07e50?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Zleek Speak</title>
		<link>http://zleek.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://zleek.wordpress.com/osd.xml" title="Zleek Speak" />
		<item>
		<title>Zleek is 2nd Runner-Up in ComponentArt Silverlight Coding Competition</title>
		<link>http://zleek.wordpress.com/2009/11/12/zleek-is-2nd-runner-up-in-componentart-silverlight-coding-competition/</link>
		<comments>http://zleek.wordpress.com/2009/11/12/zleek-is-2nd-runner-up-in-componentart-silverlight-coding-competition/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 03:54:06 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[zleek]]></category>
		<category><![CDATA[componentart]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/2009/11/12/zleek-is-2nd-runner-up-in-componentart-silverlight-coding-competition/</guid>
		<description><![CDATA[Zleek placed 3rd in the ComponentArt Silverlight Coding Competition. Thank you to all who voted! 
The winner of the competition, PuzzleTouch, combined usage of almost all of the new Silverlight 3 features &#8211; including Multi-Touch, Out-Of-Browser, and Perspective3D &#8211; with a slick UI. I highly recommend checking it out.
       [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=64&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://zleek.com">Zleek</a> placed 3rd in the <a href="http://www.componentart.com/community/competition2009/">ComponentArt Silverlight Coding Competition</a>. Thank you to all who voted! </p>
<p>The <a href="http://www.puzzletouch.com/">winner of the competition</a>, <a href="http://www.puzzletouch.com/">PuzzleTouch</a>, combined usage of almost all of the new Silverlight 3 features &#8211; including Multi-Touch, Out-Of-Browser, and Perspective3D &#8211; with a slick UI. I highly recommend checking it out.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/64/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/64/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/64/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=64&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/11/12/zleek-is-2nd-runner-up-in-componentart-silverlight-coding-competition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>
	</item>
		<item>
		<title>Zleek 2.0 is here!</title>
		<link>http://zleek.wordpress.com/2009/09/23/zleek-2-0-is-here/</link>
		<comments>http://zleek.wordpress.com/2009/09/23/zleek-2-0-is-here/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 22:46:14 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[code walkthrough]]></category>
		<category><![CDATA[zleek]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[componentart]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/2009/09/23/zleek-2-0-is-here/</guid>
		<description><![CDATA[ 
Zleek 2.0 has released!
Check it out at http://zleek.com. 
Here are the new features:

Completely new design and flow – much easier to use.
Customizable albums (page color, border color, border sizes, etc)
Video support
Facebook integration (login and stream posts)

Those are the “new” features from the 1,000-foot level. In reality, the entire site was rewritten from scratch using [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=57&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://zleek.com"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="Zleek Logo" border="0" alt="Zleek Logo" src="http://zleek.files.wordpress.com/2009/09/zleek_large.jpg?w=240&#038;h=103" width="240" height="103" /></a> </p>
<h3>Zleek 2.0 has released!</h3>
<p><a href="http://zleek.com">Check it out at http://zleek.com.</a> </p>
<p>Here are the new features:</p>
<ul>
<li>Completely new design and flow – much easier to use.</li>
<li>Customizable albums (page color, border color, border sizes, etc)</li>
<li>Video support</li>
<li>Facebook integration (login and stream posts)</li>
</ul>
<p>Those are the “new” features from the 1,000-foot level. In reality, <strong>the entire site was rewritten from scratch</strong> using new technologies and optimized workflows.</p>
<p>Here is the breakdown of what it’s using:</p>
<ul>
<li><a href="http://www.asp.net/mvc/">ASP.NET MVC 1.0</a></li>
<li><a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24644">WCF REST Starter Kit Preview 2</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb399572.aspx">ADO.NET Entity Framework</a></li>
<li><a href="http://www.silverlight.net/">Silverlight 3</a></li>
<li><a href="http://jquery.com/">JQuery 1.3</a></li>
</ul>
<p><strong>Check it out today!</strong></p>
<h3>ComponentArt Silverlight Competition</h3>
<p>Please <strong>vote for us</strong> in the <a href="http://www.componentart.com/community/competition2009/details.aspx?id=1100">ComponentArt Summer Silverlight Coding Competition</a>!</p>
<h3>Agnition.Utils Code Drop</h3>
<p>Due to the release, there is a new drop of the <a href="http://www.stevecommisso.com/Bragosphere/posts/Agnition.Utils.zip">Agnition.Utils library</a> containing our final production code. <a href="http://www.stevecommisso.com/Bragosphere/posts/Agnition.Utils.zip"><strong>Get it now!</strong></a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=57&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/09/23/zleek-2-0-is-here/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>

		<media:content url="http://zleek.files.wordpress.com/2009/09/zleek_large.jpg" medium="image">
			<media:title type="html">Zleek Logo</media:title>
		</media:content>
	</item>
		<item>
		<title>Fish Eye Menu Control</title>
		<link>http://zleek.wordpress.com/2009/05/12/fish-eye-menu-control/</link>
		<comments>http://zleek.wordpress.com/2009/05/12/fish-eye-menu-control/#comments</comments>
		<pubDate>Tue, 12 May 2009 22:33:18 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[code walkthrough]]></category>
		<category><![CDATA[zleek]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/2009/05/12/fish-eye-menu-control/</guid>
		<description><![CDATA[For the new version of Zleek, I wanted to create an intuitive page menu for the bottom of the albums. I wanted to go with an OS X – style menu.
Here is what I came up with.
You can add any FrameworkElement as a menu item, so primitive shapes up to User Controls are all fine.
This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=53&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For the new version of <a href="http://www.zleek.com">Zleek</a>, I wanted to create an intuitive page menu for the bottom of the albums. I wanted to go with an OS X – style menu.</p>
<p><a href="http://www.stevecommisso.com/test/fisheye/">Here is what I came up with</a>.</p>
<p>You can add any <strong>FrameworkElement</strong> as a menu item, so primitive shapes up to User Controls are all fine.</p>
<p>This control is part of the <a href="http://www.stevecommisso.com/bragosphere/posts/Agnition.Utils.zip">Agnition.Utils library</a>, which has been updated.</p>
<p><a href="http://www.stevecommisso.com/bragosphere/posts/Agnition.Utils.zip">Get it here!</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/53/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/53/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/53/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=53&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/05/12/fish-eye-menu-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>
	</item>
		<item>
		<title>New Agnition.Utils Code Drop</title>
		<link>http://zleek.wordpress.com/2009/05/07/new-agnitionutils-code-drop/</link>
		<comments>http://zleek.wordpress.com/2009/05/07/new-agnitionutils-code-drop/#comments</comments>
		<pubDate>Thu, 07 May 2009 14:04:02 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[zleek]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/2009/05/07/new-agnitionutils-code-drop/</guid>
		<description><![CDATA[There is a new version of the Agnition.Utils libraries available containing some updates (mostly new functionality). In short, there has been a migration from some of the unpublished Zleek-specific code into the general base classes, most notable in the authentication pieces. There have also been a few bug fixes. 
If you&#8217;re using this library for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=49&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There is a new version of the <strong><a href="http://www.stevecommisso.com/bragosphere/posts/Agnition.Utils.zip">Agnition.Utils</a></strong> libraries available containing some updates (mostly new functionality). In short, there has been a migration from some of the unpublished <a href="http://www.zleek.com">Zleek</a>-specific code into the general base classes, most notable in the authentication pieces. There have also been a few bug fixes. </p>
<p>If you&#8217;re using this library for anything, I strongly suggest upgrading. <strong><a href="http://www.stevecommisso.com/bragosphere/posts/Agnition.Utils.zip">Get it here</a><strong>. </strong></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=49&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/05/07/new-agnitionutils-code-drop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>
	</item>
		<item>
		<title>JQuery, JSON, and the REST Starter Kit</title>
		<link>http://zleek.wordpress.com/2009/05/07/jquery-json-and-the-rest-starter-kit/</link>
		<comments>http://zleek.wordpress.com/2009/05/07/jquery-json-and-the-rest-starter-kit/#comments</comments>
		<pubDate>Thu, 07 May 2009 13:49:18 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[code walkthrough]]></category>
		<category><![CDATA[zleek]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/2009/05/07/jquery-json-and-the-rest-starter-kit/</guid>
		<description><![CDATA[The new version of Zleek will be retrieving all of its data from a RESTful WCF Service that serves up JSON data. It also makes heavy use of the JQuery 1.3 libraries with the JQuery JSON 1.3 plugin. Are they interoperable? 
If you&#8217;ve worked with the REST Starter Kit on the server and JQuery on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=48&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The new version of <a href="http://www.zleek.com">Zleek</a> will be retrieving all of its data from a <a href="http://msdn.microsoft.com/en-us/netframework/cc950529.aspx">RESTful WCF Service</a> that serves up <a href="http://www.json.org/">JSON</a> data. It also makes heavy use of the <a href="http://jquery.com/">JQuery 1.3 libraries</a> with the <a href="http://code.google.com/p/jquery-json/">JQuery JSON 1.3</a> plugin. Are they interoperable? </p>
<p>If you&#8217;ve worked with the REST Starter Kit on the server and JQuery on the client, you probably already know the answer: <strong><em><a href="http://www.sadtrombone.com">almost</a></em></strong>. </p>
<p>The problem lies in date serialization. Say you have the date <strong>5/6/2009</strong> and you want to pass it to your RESTful WCF service as JSON. Here is how JQuery serializes it: </p>
<p><span style="font-family:courier new;color:#009FEF;">&#8220;2009-06-05&#8243;</span></p>
<p>And here is how the MicrosoftAjax.js library serializes it: </p>
<p><span style="font-family:courier new;color:#009FEF;">&#8220;&#8221;\/Date(1246777200000)\/&#8221;"</span></p>
<p>Your WCF service will only be able to deserialize dates in the Microsoft format and will throw an exception otherwise. You will also have the same problem going the other way. If your WCF service returns a DateTime object, it will be deserialized by JQuery as a string. Luckily, due to the nature of JSON (de)serialization, both of these issues are easy problems to fix. </p>
<p>I only wish I had seen <a href="http://west-wind.com/weblog">Rick Strahl&#8217;s</a> <a href="http://west-wind.com/weblog/posts/324917.aspx">excellent</a> <a href="http://west-wind.com/WebLog/posts/398970.aspx">posts</a> from a year ago on this issue <em>prior</em> to tackling it. Apparently I&#8217;m Google-inept&#8230; </p>
<h3>Situation 1: Transmitting dates from a JQuery client to a WCF service</h3>
<p>For those of you new to JavaScript development, JavaScript is a dynamically typed language. Your prototype object can have a date property that you can change to a string or a number at any time without any issues. This property of JavaScript can be leveraged to fix our problem. </p>
<p>Prior to calling the JQuery library and issuing the request to the WCF service, you can change it to a string that will be serialized like the way MicrosoftAjax serializes dates. To get an output of: </p>
<p><span style="font-family:courier new;color:#009FEF;">&#8220;&#8221;\/Date(1246777200000)\/&#8221;"</span></p>
<p>We need an input of: </p>
<p><span style="font-family:courier new;color:#009FEF;">&#8220;/Date(1246777200000)/&#8221;</span></p>
<p>Here is a function you can use to do just that. It takes a JavaScript Date object and turns it into a string that JQuery will then serialize into the MicrosoftAjax date serialization format. </p>
<div id="codeSnippetWrapper" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;border:solid 1px silver;cursor:text;max-height:200px;overflow:auto;width:97.5%;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;padding:0;">
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> Agnition.Serialization.SerializeDate = <span style="color:#0000ff;">function</span>(date) {</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#008000;">///    JQuery cannot serialize a Date object so that .NET can read it, this fixes its attempt by calling</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#008000;">///    the MS AJAX serializer. JQuery will then serialize a string correctly.</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     <span style="color:#008000;">/// &lt;param name="date"&gt;The date to serialize&lt;/param&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     <span style="color:#008000;">/// &lt;returns&gt;A JSON serialized date formatted for .NET&lt;/returns&gt;</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>     <span style="color:#0000ff;">var</span> dateString = Sys.Serialization.JavaScriptSerializer.serialize(date);</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>     dateString = dateString.substring(2);</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>     dateString = dateString.substring(0, dateString.length - 3) + <span style="color:#006080;">"\/"</span>;</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>     <span style="color:#0000ff;">return</span> dateString;</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span> };</pre>
<p><!--CRLF--></div>
</div>
<p>Here is an example of it in use: </p>
<div id="codeSnippetWrapper" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;border:solid 1px silver;cursor:text;max-height:200px;overflow:auto;width:97.5%;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;padding:0;">
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> <span style="color:#0000ff;">this</span>.CreateBook = <span style="color:#0000ff;">function</span>(successCallback, errorCallback) {</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#008000;">/// &lt;summary&gt;Attempts to register the user&lt;/summary&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#008000;">/// &lt;param name="successCallback"&gt;The callback fired if the request is successful&lt;/param&gt;</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#008000;">/// &lt;param name="errorCallback"&gt;The callback fired if the request failed&lt;/param&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span> &nbsp;</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     <span style="color:#0000ff;">var</span> albumData = <span style="color:#0000ff;">this</span>.AlbumData;</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     <span style="color:#0000ff;">var</span> svcAddress = <span style="color:#0000ff;">this</span>.ServiceAddress;</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span> &nbsp;</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>     albumData.LastUpdated = Agnition.Serialization.SerializeDate(albumData.LastUpdated);</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>     <span style="color:#0000ff;">var</span> jsonRequest = <span style="color:#0000ff;">new</span> Agnition.Net.WebRequest();</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>     <span style="color:#0000ff;">var</span> url = svcAddress + <span style="color:#006080;">"/Album/new?includeMedia=false"</span>;</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>     jsonRequest.PutJson(url, albumData, successCallback, errorCallback, <span style="color:#0000ff;">null</span>);</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span> };</pre>
<p><!--CRLF--></div>
</div>
<h3>Situation 2: Receiving dates from a WCF service in a JQuery client</h3>
<p>This issue is basically the reverse of Situation 1. Your WCF service will serialize a DateTime object in the MicrosoftAjax format. JQuery will see this and deserialize it as a string. All we have to do is modify this string to put it back into the MicrosoftAjax format, and then use the MicrosoftAjax library to deserialize it. Here is what JQuery will deserialize the response as (notice it&#8217;s a string): </p>
<p><span style="font-family:courier new;color:#009FEF;">&#8220;/Date(1240902876467-0700)/&#8221;</span></p>
<p>Here is a function that will perform the translation for you: </p>
<div id="codeSnippetWrapper" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;border:solid 1px silver;cursor:text;max-height:200px;overflow:auto;width:97.5%;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;padding:0;">
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> Agnition.Serialization.FixJQueryDate = <span style="color:#0000ff;">function</span>(dateString) {</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#008000;">///    JQuery cannot deserialize the .NET dateTime object, so this fixes its attempt by reconstructing</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#008000;">///    the string and calling the MS AJAX deserializer.</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     <span style="color:#008000;">/// &lt;param name="dateString"&gt;The JQuery deserialized date string&lt;/param&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     <span style="color:#008000;">/// &lt;returns&gt;A JavaScript date object&lt;/returns&gt;</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>     dateString = dateString.substring(1);</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>     dateString = dateString.substring(0, dateString.indexOf(<span style="color:#006080;">"\/"</span>));</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span>     dateString = <span style="color:#006080;">"\"\\\/"</span> + dateString + <span style="color:#006080;">"\\\/\""</span>;</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span>     <span style="color:#0000ff;">var</span> date = Sys.Serialization.JavaScriptSerializer.deserialize(dateString);</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>     <span style="color:#0000ff;">return</span> date;</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span> };</pre>
<p><!--CRLF--></div>
</div>
<p>And here is an example of it in use: </p>
<div id="codeSnippetWrapper" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;border:solid 1px silver;cursor:text;max-height:200px;overflow:auto;width:97.5%;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;padding:0;">
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> $(document).ready(<span style="color:#0000ff;">function</span>() {</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#0000ff;">var</span> request = <span style="color:#0000ff;">new</span> Agnition.Zleek.Web.Service.PagedDataRequest(bookUrl, BOOK_PAGE_SIZE, BOOK_MAX_RECORDS);</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     request.GetPage(BOOK_CURRENT_PAGE,</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>             <span style="color:#0000ff;">function</span>(data, statusText) {</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>             <span style="color:#008000;">/* snip */</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>                 <span style="color:#0000ff;">for</span> (<span style="color:#0000ff;">var</span> i = 0; i &lt; numAlbums; i++) {</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>                     <span style="color:#0000ff;">var</span> album = data.Albums[i];</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>                     album.LastUpdated = Agnition.Serialization.FixJQueryDate(album.LastUpdated);</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span>             <span style="color:#008000;">/* snip */</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span> };</pre>
<p><!--CRLF--></div>
</div>
<p>Now, assuming all of the dates in our service are UTC dates, this function will perform the conversion from UTC to the browser&#8217;s local time, and then we can create a new method which fixes both the date serialization and performs the time conversion:</p>
<div id="codeSnippetWrapper" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;border:solid 1px silver;cursor:text;max-height:200px;overflow:auto;width:97.5%;margin:20px 0 10px;padding:4px;">
<div id="codeSnippet" style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;padding:0;">
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   1:</span> Agnition.ConvertUTCToLocalTime = <span style="color:#0000ff;">function</span>(date) {</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   2:</span>     <span style="color:#008000;">/// &lt;summary&gt;Converts a UTC date to local time&lt;/summary&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   3:</span>     <span style="color:#008000;">/// &lt;param name="date"&gt;The date object to convert&lt;/param&gt;</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   4:</span>     <span style="color:#008000;">/// &lt;returns&gt;The resulting local time&lt;/return&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   5:</span>     <span style="color:#0000ff;">var</span> utcTime = date.getTime();</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   6:</span>     <span style="color:#0000ff;">var</span> localOffset = date.getTimezoneOffset() * 60000; <span style="color:#008000;">// Get offset in milliseconds</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   7:</span>     <span style="color:#0000ff;">var</span> localTime = utcTime - localOffset;</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   8:</span>     <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> Date(localTime);</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">   9:</span> };</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  10:</span> &nbsp;</pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  11:</span> Agnition.Serialization.GetJQueryDateAsLocalTime = <span style="color:#0000ff;">function</span>(dateString) {</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  12:</span>     <span style="color:#008000;">/// &lt;summary&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  13:</span>     <span style="color:#008000;">///    JQuery cannot deserialize the .NET dateTime object, so this fixes its attempt by reconstructing</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  14:</span>     <span style="color:#008000;">///    the string and calling the MS AJAX deserializer. The resulting date is then converted to local</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  15:</span>     <span style="color:#008000;">///    time from UTC time.</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  16:</span>     <span style="color:#008000;">/// &lt;/summary&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  17:</span>     <span style="color:#008000;">/// &lt;param name="dateString"&gt;The JQuery deserialized date string&lt;/param&gt;</span></pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  18:</span>     <span style="color:#008000;">/// &lt;returns&gt;A JavaScript date object, converted from UTC to local time&lt;/returns&gt;</span></pre>
<p><!--CRLF-->
<pre style="font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;background-color:white;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  19:</span>     <span style="color:#0000ff;">return</span> Agnition.ConvertUTCToLocalTime(Agnition.Serialization.FixJQueryDate(dateString));</pre>
<p><!--CRLF-->
<pre style="background-color:#f4f4f4;font-family:'Courier New', Courier, Monospace;font-size:8pt;line-height:12pt;color:black;overflow:visible;width:100%;border-style:none;margin:0;padding:0;"><span style="color:#606060;">  20:</span> };</pre>
<p><!--CRLF--></div>
</div>
<h3>Caveat Emptor</h3>
<p>Because there is no <a href="http://www.nikhilk.net/DateSyntaxForJSON.aspx">standard date literal</a> in JavaScript, Microsoft AJAX and JQuery may change their respective JSON date serialization formats in the future. So if you&#8217;re using this solution (and hopefully created a single function to perform the translations), you may have to modify your translation code when using future releases of JQuery or MS AJAX. In fact, Microsoft has already <a href="http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx">changed their format</a> once before, and may do so again in the future.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=48&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/05/07/jquery-json-and-the-rest-starter-kit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>
	</item>
		<item>
		<title>MIX &#8216;09 Summary (so far&#8230;)</title>
		<link>http://zleek.wordpress.com/2009/03/20/mix-09-summary-so-far/</link>
		<comments>http://zleek.wordpress.com/2009/03/20/mix-09-summary-so-far/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 08:33:22 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[mix]]></category>
		<category><![CDATA[zleek]]></category>
		<category><![CDATA[blend]]></category>
		<category><![CDATA[ie8]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/?p=27</guid>
		<description><![CDATA[Wow. MIX &#8216;09 is over halfway over. First we have Silverlight 3 Beta with out-of-browser, hardware acceleration, multi-touch, RIA services, pixel shaders, H.264 support, a smaller runtime, and better rendering performance on Wednesday; accented by a great keynote about design by Bill Buxton and SketchFlow in Blend 3 (not to mention true support for Photoshop/Illustrator [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=27&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Wow. <a href="http://live.visitmix.com/">MIX &#8216;09</a> is over halfway over. First we have Silverlight 3 Beta with out-of-browser, hardware acceleration, multi-touch, RIA services, pixel shaders, H.264 support, a smaller runtime, and better rendering performance on Wednesday; accented by a great keynote about design by <a href="http://www.billbuxton.com/">Bill Buxton</a> and <a href="http://electricbeach.org/?p=145">SketchFlow in Blend 3</a> (not to mention true support for Photoshop/Illustrator import).</p>
<p>Then we have the launch of <a href="http://www.microsoft.com/ie8">IE8</a> with a <a href="http://live.visitmix.com/">hilarious introduction video</a> about the history of the web from the perspective of <a href="http://www.askaninja.com/">a ninja</a>.</p>
<p>And those were just the keynotes.</p>
<p>I met up with <a href="http://www.cynergysystems.com/blogs/page/rickbarraza">Rick Barraza</a> and played around with his mind-blowing  <a href="http://www.cynergysystems.com/blogs/page/rickbarraza?entry=microsoft_surface_physics_and_sxsw">Surface applications</a>. I watched <a href="http://www.betterthaneveryone.com/">Clint Rutkas</a> show off videos of his <a href="http://vimeo.com/3638857">bartender robot</a> (<span style="font-family:courier new, courier;">Bartender.PourDrinkByName(&#8220;Irish Car Bomb&#8221;);</span>) and <a href="http://vimeo.com/2013184">self-balancing skateboard</a>.</p>
<p>Then, there was the <a href="http://2009.visitmix.com/MIXtify/ShowOff.aspx">Show Off</a> competition. I thought I was doing pretty well for a while until someone showed off a WPF webcam application with 3D object detection and Rick came along with his two (as if one wasn&#8217;t hard enough to beat) videos &#8211; one of the aforementioned <a href="http://www.microsoft.com/surface">Surface</a> applications, and another where he used his Jedi powers demonstrating a WPF app that interfaced with a brain wave scanner for &#8220;thought control&#8221;. After those, I would be happy if I got a single vote for <a href="http://www.zleek.com/mix09/">my entry</a> which I guess is not bad for a single developer part-time with no budget.</p>
<p>Then, of course, there was getting to hang out with the smartest designers and developers on the planet.</p>
<p>Also, I&#8217;ve been <a href="http://zleektest.com/family/">making a fool out of myself</a> taking pictures around MIX with my sons&#8217; stuffed animals. Here&#8217;s <a href="http://weblogs.asp.net/scottgu/">scottgu</a> playing along.<br />
<div class="wp-caption aligncenter" style="width: 410px"><a href="http://zleektest.com/ZleekWebService/Album.svc/Media/974/c"><img alt="scottgu loves stuffed animals" src="http://zleektest.com/ZleekWebService/Album.svc/Media/974/c" title="scottgu loves stuffed animals" width="400" height="300" /></a><p class="wp-caption-text">scottgu loves stuffed animals</p></div><br />
And here&#8217;s <a href="http://www.billbuxton.com/">Bill Buxton</a>.<br />
<div class="wp-caption aligncenter" style="width: 410px"><a href="http://zleektest.com/ZleekWebService/Album.svc/Media/1008/c"><img alt="The design guru" src="http://zleektest.com/ZleekWebService/Album.svc/Media/1008/c" title="The design guru" width="400" height="300" /></a><p class="wp-caption-text">The design guru</p></div><br />
They loved it, so it&#8217;s worth it.</p>
<p>For my friends at <a href="http://www.aps.com/">APS</a>, I couldn&#8217;t resist this picture of <a href="http://neverindoubtnet.blogspot.com/">Ward Bell</a> and his Vegas jacket.<br />
<div class="wp-caption aligncenter" style="width: 410px"><a href="http://zleektest.com/ZleekWebService/Album.svc/Media/975/c"><img alt="Mr. Las Vegas" src="http://zleektest.com/ZleekWebService/Album.svc/Media/975/c" title="Mr. Las Vegas" width="400" height="300" /></a><p class="wp-caption-text">Mr. Las Vegas</p></div></p>
<p>Anyway, check out my <a href="http://zleektest.com/mix09/">MIX photo album</a> for some pictures of the event.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=27&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/03/20/mix-09-summary-so-far/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>

		<media:content url="http://zleektest.com/ZleekWebService/Album.svc/Media/974/c" medium="image">
			<media:title type="html">scottgu loves stuffed animals</media:title>
		</media:content>

		<media:content url="http://zleektest.com/ZleekWebService/Album.svc/Media/1008/c" medium="image">
			<media:title type="html">The design guru</media:title>
		</media:content>

		<media:content url="http://zleektest.com/ZleekWebService/Album.svc/Media/975/c" medium="image">
			<media:title type="html">Mr. Las Vegas</media:title>
		</media:content>
	</item>
		<item>
		<title>Restful Uploader and Extenders Update</title>
		<link>http://zleek.wordpress.com/2009/03/20/restful-uploader-and-extenders-update/</link>
		<comments>http://zleek.wordpress.com/2009/03/20/restful-uploader-and-extenders-update/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 07:54:00 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[zleek]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/?p=25</guid>
		<description><![CDATA[There have been some slight modifications made to both the RESTful Uploader and Silverlight Extenders libraries. In addition, I have combined them into a single solution.

Get it here!
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=25&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>There have been some slight modifications made to both the <a href="http://zleek.wordpress.com/2009/02/12/using-silverlight-and-wcf-to-create-a-restful-file-upload-utility/">RESTful Uploader</a> and <a href="http://bragosphere.blogspot.com/2008/12/silverlight-extenders-add.html">Silverlight Extenders</a> libraries. In addition, I have combined them into a single solution.</p>
<p>
<a href="http://www.stevecommisso.com/Bragosphere/Posts/SilverlightWcfRestfulUpload.zip">Get it here!</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=25&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/03/20/restful-uploader-and-extenders-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>
	</item>
		<item>
		<title>Zleek @ MIX</title>
		<link>http://zleek.wordpress.com/2009/03/18/zleek-mix/</link>
		<comments>http://zleek.wordpress.com/2009/03/18/zleek-mix/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 07:13:16 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[zleek]]></category>
		<category><![CDATA[mix]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/?p=23</guid>
		<description><![CDATA[If you&#8217;re at MIX, join in on the publicly editable Zleek album!
I will be adding pictures starting tomorrow morning.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=23&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you&#8217;re at MIX, join in on the <a href="http://www.zleektest.com/mix09">publicly editable Zleek album</a>!</p>
<p>I will be adding pictures starting tomorrow morning.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=23&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/03/18/zleek-mix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>
	</item>
		<item>
		<title>MIX 09 Show Off Entry</title>
		<link>http://zleek.wordpress.com/2009/03/10/mix-09-show-off-entry/</link>
		<comments>http://zleek.wordpress.com/2009/03/10/mix-09-show-off-entry/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 21:24:21 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[mix]]></category>
		<category><![CDATA[zleek]]></category>
		<category><![CDATA[entity framework]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[wcf]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/2009/03/10/mix-09-show-off-entry/</guid>
		<description><![CDATA[I put together a short video of the recent work I’ve done on Zleek for the MIX 09 Show Off competition.
Here is the video
Hopefully that will whet your appetite for the new changes coming to Zleek
Also, thank you to everyone who voted in the MIX 09 Smart Coding Challenge. I didn&#8217;t win a prize, but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=21&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I put together a short video of the recent work I’ve done on <a href="http://www.zleek.com">Zleek</a> for the <a href="http://2009.visitmix.com/">MIX 09</a> <a href="http://2009.visitmix.com/MIXtify/ShowOff.aspx">Show Off</a> competition.</p>
<p><a href="http://www.zleek.com/mix09">Here is the video</a></p>
<p>Hopefully that will whet your appetite for the new changes coming to <a href="http://www.zleek.com">Zleek</a></p>
<p>Also, thank you to everyone who voted in the <a href="http://2009.visitmix.com/MIXtify/TenKGallery.aspx">MIX 09 Smart Coding Challenge</a>. I didn&#8217;t win a prize, but it was still a lot of fun.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=21&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/03/10/mix-09-show-off-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>
	</item>
		<item>
		<title>Using Silverlight and WCF to create a RESTful File Upload Utility</title>
		<link>http://zleek.wordpress.com/2009/02/12/using-silverlight-and-wcf-to-create-a-restful-file-upload-utility/</link>
		<comments>http://zleek.wordpress.com/2009/02/12/using-silverlight-and-wcf-to-create-a-restful-file-upload-utility/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 13:52:54 +0000</pubDate>
		<dc:creator>zleek</dc:creator>
				<category><![CDATA[code walkthrough]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[wcf]]></category>
		<category><![CDATA[zleek]]></category>

		<guid isPermaLink="false">http://zleek.wordpress.com/?p=12</guid>
		<description><![CDATA[Overview
During the development of Zleek, I ran into some problems uploading files from Silverlight. I wanted a file upload utility that provided progress notification to the user. However, there is no built-in progress notification for the WebClient or HttpWebRequest classes! More specifically, the event exists but it currently does not provide enough resolution to be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=12&subd=zleek&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3>Overview</h3>
<p>During the development of <a href="http://www.zleek.com">Zleek</a>, I ran into some problems uploading files from <a href="http://www.silverlight.net">Silverlight</a>. I wanted a file upload utility that provided progress notification to the user. However, there is no built-in progress notification for the <strong>WebClient</strong> or <strong>HttpWebRequest</strong> classes! More specifically, the event exists but it currently does not provide enough resolution to be meaningful. It fires at only 100%, so it can only be used as a completion event. This is not good news if you want to provide file upload progress to users.</p>
<p>The second problem is that if you wanted to upload large files, you had to set your <a href="http://msdn.microsoft.com/en-us/library/ms731082.aspx">WCF Service</a>&#8217;s MaxMessageSize to whatever the maximum file size you are expecting &#8212; and if you&#8217;re expecting video files, it would have to be absurdly large.</p>
<p>The solution to both of these problems is to have the client break the files up into smaller chunks before sending them off to the server, which would then reassemble them in the correct order. This scenario is not overly complicated, but since it requires a good deal of busy work, I decided to put together a Silverlight library for the client and a WCF library for the service that allows you to quickly and easily build file upload functionality using Silverlight and WCF. This post explores how the libraries were built, and how to use them.</p>
<h3>REST Refresher</h3>
<p>First off, you should familiarize yourself with REST, WCF, and consuming WCF services from Silverlight by taking a look at <a href="http://www.robbagby.com">Rob Bagby</a>&#8217;s <a href="http://blogs.msdn.com/bags/archive/2008/11/10/rest-in-wcf-part-xi-tunneling-put-through-post.aspx">REST in WCF series</a> and my <a href="http://bragosphere.blogspot.com/2008/12/consuming-restful-web-services-in.html">earlier post on Silverlight/WCF communication</a>.</p>
<p>Here is a quick refresher:</p>
<p><strong>REST</strong> is part of a service architecture (ROA) that attempts to simplify services by limiting communication to <strong>URIs</strong>, <strong>HTTP Verbs</strong>, and <strong>HTTP Status Codes</strong>. There are no complicated SOAP envelopes that a client needs to create. It just needs to know the URI it wishes to connect to.</p>
<p><strong>URIs</strong> should be designed to be <strong><em>hackable</em></strong>, e.g. If sending a GET to <em>http://myhost/myservice.svc/Media/1</em> retrieves the media item with ID 1, the consumer of the service would be able to guess that a DELETE would delete the media with that ID, while a PUT would insert or update the media with that ID.</p>
<p><strong>Status Codes</strong> should be used effectively to report error conditions. Some common ones are:</p>
<ul>
<li><strong>404 (Not Found)</strong>, <em>example</em>: Returned for a GET/DELETE attempt if the specified ID does not exist</li>
<li><strong>400 (Bad Request)</strong>, <em>example</em>: One of the parameters is not valid</li>
<li><strong>403 (Forbidden)</strong>, <em>example</em>: Client is not authorized to perform the operation</li>
</ul>
<p><strong>eTag</strong> and <strong>Last Modified</strong> headers should be used effectively to permit caching of <strong>GET</strong> requests.</p>
<p>Use the <a href="http://go.microsoft.com/?linkid=9632200">WCF REST Starter Kit</a> to create the service.</p>
<h3>Client Library</h3>
<p>Let&#8217;s start with the client. The client is responsible for breaking the files to be uploaded into smaller chunks and sending them off to the server. The main client class is <strong>UploadUtility</strong> (located in <strong>Agnition.Silverlight.Utils/Net</strong>), which uses <strong>RestfulServiceWrapper</strong> (located in <strong>Agnition.Silverlight.Utils/ServiceModel</strong>) to make calls into a RESTful WCF service.</p>
<p><strong>UploadUtility.PerformUpload()</strong> takes a URI, URI format string, and a list of <strong>FileInfo</strong> objects. It creates a <strong>FileWrapper</strong> for each of these files, and splits them up into smaller &#8220;chunks&#8221; (<strong>FileChunk</strong>). These files are then queued up for upload.</p>
<p>After queueing up the files, the client starts a background process which continually checks to see how many &#8220;chunks&#8221; are currently being uploaded, and if it is under the <strong>MaxUploadCount</strong>, pulls the next file out of the queue. When the file is pulled out of the queue, the first &#8220;chunk&#8221; for the file is uploaded. When the upload completes, progress is reporting and if there is a next &#8220;chunk&#8221;, it starts the upload for that chunk.</p>
<p>Once the queue is empty, the entire upload process reports as complete.</p>
<p>The URI format string is responsible for telling the client how to perform variable substitution. This format string should <strong>at a minimum</strong> contain the following placeholders:</p>
<ul>
<li><strong>BaseUri</strong> &#8211; the service URI.</li>
<li><strong>FileName</strong> &#8211; the original file name of the file being uploaded.</li>
<li><strong>FileKey</strong> &#8211; a unique identifier for the file being uploaded.</li>
<li><strong>ChunkNumber</strong> &#8211; the sequence number for the current chunk being uploaded.</li>
<li><strong>TotalChunks</strong> &#8211; the total number of chunks that make up the file.</li>
</ul>
<p>The default format string is &#8220;<strong>{BaseUri}/{FileKey}/{TotalChunks}/{ChunkNumber}?Name={FileName}</strong>&#8220;, which is used to create the target URI when upload requests are issued. You can also specify custom parameters by inheriting from <strong>FileWrapper</strong> and overriding <strong>UploadUtility.CreateWrapper()</strong>, more on this later. FileName and all custom parameters will automatically be URL Encoded.</p>
<p><strong>Important:</strong><em>If a parameter (such as </em><strong>FileName</strong><em>) contains values that might include characters that must be URL encoded, they should be formatted as a query string parameter rather than as part of the main URI. Otherwise, the RESTful WCF service will not correctly map the request to the appropriate method.</em></p>
<p>The upload utility provides the following settings which can be used to tune the upload process:</p>
<ul>
<li><strong>MaxUploadCount</strong> controls the number of concurrent uploads that the client issues. Defaults to 1.</li>
<li><strong>MaxUploadSize</strong> controls the &#8220;chunk&#8221; size of the files. If a file size is greater than this setting, it will be split into two or more &#8220;chunks&#8221;. Defaults to 200KB.</li>
<li><strong>MaxFileSize</strong> is the maximum file size for any file being uploaded. If a file size is greater than this, it will not be uploaded. Defaults to 30MB.</li>
<li><strong>IsApproximatingProgress</strong> will increase the resolution of progress notification by using the detected transfer rate to report a calculated progress using the specified reporting interval. When a &#8220;chunk&#8221; completes upload, the calculated progress will be rest to the actual progress. A &#8220;speed test&#8221; will be performed prior to uploading the first &#8220;chunk&#8221; in order to seed the transfer rate.</li>
<li><strong>ProgressReportingFrequency</strong> sets the progress reporting interval when <strong>IsApproximatingProgress</strong> is <strong>true</strong>. Defaults to 20 msec.</li>
<li><strong>ProgressReportingMultiplier</strong> is a &#8220;fudge factor&#8221; multiplier to apply to any calculated progress reporting when <strong>IsApproximatingProgress</strong> is <strong>true</strong>. This should be between 0 and 1. Defaults to 1.</li>
<li><strong>SpeedTestMinimumSize</strong> sets the minimum size of the &#8220;speed test&#8221; to perform when <strong>IsApproximatingProgress</strong> is <strong>true</strong>. Defaults to 32KB</li>
<li><strong>SpeedTestMaximumSize</strong> sets the maximum size of the &#8220;speed test&#8221; to perform when <strong>IsApproximatingProgress</strong> is <strong>true</strong>. Defaults to 200KB.</li>
<li><strong>SpeedTestSizePercentage</strong> sets the size as a percentage of the total upload size of the &#8220;speed test&#8221; to perform when <strong>IsApproximatingProgress</strong> is <strong>true</strong>. Defaults to 5%.</li>
</ul>
<h3>Server Library</h3>
<p>The server logic is very straightforward. Its only job is to reassemble temporary &#8220;chunks&#8221; uploaded by a client into a complete file, and delete those chunks when the completed file is assembled or the upload is cancelled. It is the job of <strong>UploadHandler.cs</strong> (located in <strong>Agnition.Utils/ServiceModel</strong>) to perform these tasks. <strong>UploadServiceHostFactory</strong> is a subclass of <strong>RestServiceHostFactory</strong> that sets the <strong>MaxMessageSize</strong>. <strong>Important</strong>: <em>This should match the</em> <strong>MaxUploadSize</strong> <em>of the</em> <strong>UploadUtility</strong> <em>client!</em></p>
<p>Consuming services should create a <strong>singleton</strong> instance of <strong>UploadHandler</strong> and call <strong>UploadHandler.ProcessUpload()</strong> and <strong>UploadHandler.CancelUpload()</strong> to perform these processes.</p>
<h3>Putting It All Together</h3>
<p>We can use the client and server libraries to put together a file uploader for media files. Let&#8217;s start off by building the <strong>client</strong>.<br />
<a href="http://zleek.files.wordpress.com/2009/02/ui.jpg"><img style="display:block;float:none;margin-left:auto;margin-right:auto;border-width:0;" title="ui" src="http://zleek.files.wordpress.com/2009/02/ui-thumb.jpg?w=496&#038;h=312" border="0" alt="ui" width="496" height="312" /></a><br />
The UI is pretty straightforward. It contains an upload/cancel button, an overall progress display, and a file progress display. The individual file progress displays are seperated out into another user control that takes an instance of <strong>FileWrapper</strong> in order to display a preview.</p>
<p>To extend the libraries for media support, I created a few additional classes: <strong>MediaFileWrapper</strong>, which inherits from <strong>FileWrapper</strong> by providing a <strong>FileType</strong> custom parameter, and <strong>MediaUploadUtility</strong>, which inherits from <strong>UploadUtility</strong>. The source code for these are as follows:</p>
<p><strong>MediaFileWrapper.cs</strong></p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> MediaFileWrapper : FileWrapper</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">{</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">const</span> <span style="color:#0000ff;">string</span> IMAGE_TYPES = <span style="color:#006080;">"bmp;jpg;jpeg;gif;png;tif;tiff"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">const</span> <span style="color:#0000ff;">string</span> VIDEO_TYPES = <span style="color:#006080;">"avi;mpg;mpeg;wmv;asf;dvr-ms;m2v;ts;m2t;vob;mod;avs;mov;m4v;mp4;3gp;3g2;dv;mp2"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">const</span> <span style="color:#0000ff;">string</span> SILVERLIGHT_IMAGE_TYPES = <span style="color:#006080;">"jpg;jpeg;png"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">const</span> <span style="color:#0000ff;">string</span> SILVERLIGHT_VIDEO_TYPES = <span style="color:#006080;">"wmv"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> FileType Type {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        get { <span style="color:#0000ff;">return</span> _type; }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">bool</span> CanPreview {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        get { <span style="color:#0000ff;">return</span> _canPreview; }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> MediaFileWrapper(FileInfo file) : <span style="color:#0000ff;">base</span>(file) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        _type = DetermineType(file);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">this</span>.Parameters.Add(<span style="color:#0000ff;">new</span> KeyValuePair&lt;<span style="color:#0000ff;">string</span>, <span style="color:#0000ff;">string</span>&gt;(<span style="color:#006080;">"FileType"</span>, Type.ToString()));</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> FileType DetermineType(FileInfo file) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">string</span> extension = file.Name.Substring(File.Name.LastIndexOf(<span style="color:#006080;">'.'</span>) + 1).ToLower();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        List&lt;<span style="color:#0000ff;">string</span>&gt; imageExtensions = <span style="color:#0000ff;">new</span> List&lt;<span style="color:#0000ff;">string</span>&gt;(IMAGE_TYPES.Split(<span style="color:#006080;">';'</span>));</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        List&lt;<span style="color:#0000ff;">string</span>&gt; silverlightImageExtensions = <span style="color:#0000ff;">new</span> List&lt;<span style="color:#0000ff;">string</span>&gt;(SILVERLIGHT_IMAGE_TYPES.Split(<span style="color:#006080;">';'</span>));</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (imageExtensions.Contains(extension)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            _canPreview = silverlightImageExtensions.Contains(extension);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span> FileType.Image;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        List&lt;<span style="color:#0000ff;">string</span>&gt; videoExtensions = <span style="color:#0000ff;">new</span> List&lt;<span style="color:#0000ff;">string</span>&gt;(VIDEO_TYPES.Split(<span style="color:#006080;">';'</span>));</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        List&lt;<span style="color:#0000ff;">string</span>&gt; silverlightVideoExtensions = <span style="color:#0000ff;">new</span> List&lt;<span style="color:#0000ff;">string</span>&gt;(SILVERLIGHT_VIDEO_TYPES.Split(<span style="color:#006080;">';'</span>));</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (videoExtensions.Contains(extension)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            _canPreview = silverlightVideoExtensions.Contains(extension);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span> FileType.Video;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">return</span> FileType.Other;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> FileType _type;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">bool</span> _canPreview;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">}</pre>
<p><!--CRLF--></div>
</div>
<p><strong>MediaUploadUtility.cs</strong></p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> MediaUploadUtility : UploadUtility</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     <span style="color:#0000ff;">public</span> List&lt;MediaFileWrapper&gt; MediaFiles {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">         get {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">             <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>.Files.Cast&lt;MediaFileWrapper&gt;().ToList();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">         }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     <span style="color:#0000ff;">public</span> MediaUploadUtility() : <span style="color:#0000ff;">base</span>() { }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> FileWrapper CreateWrapper(FileInfo file) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">         <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">new</span> MediaFileWrapper(file);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> ValidateFile(FileWrapper file) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">         ValidateFileType((MediaFileWrapper) file);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">         <span style="color:#0000ff;">base</span>.ValidateFile(file);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">void</span> ValidateFileType(MediaFileWrapper file) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">         <span style="color:#0000ff;">if</span> (file.Type == FileType.Other) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">             <span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> Exception(<span style="color:#0000ff;">string</span>.Format(<span style="color:#006080;">"File '{0}' is an unsupported file format."</span>, file.File.Name));</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">         }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">     }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> }</pre>
<p><!--CRLF--></div>
</div>
<p>In the actual UI, the pertinent code is the <strong>UploadFiles()</strong> method, which calls the <strong>MediaUploadUtility</strong> to initiate the upload process, and the progress notification event handler <strong>Uploader_UploadProgressChanged()</strong>, which updates the progress notification for the overall upload progress and the progress for each individual file.</p>
<p><strong>FileUpload.xaml.cs</strong></p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> FileUpload : UserControl</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">{</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">protected</span> MediaUploadUtility Uploader {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        get { <span style="color:#0000ff;">return</span> _uploader; }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> FileUpload() {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        InitializeComponent();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        _uploader = <span style="color:#0000ff;">new</span> MediaUploadUtility();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        _uploader.UploadProgressChanged += <span style="color:#0000ff;">new</span> UploadProgressChangedHandler(Uploader_UploadProgressChanged);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        _uploader.UploadCompleted += <span style="color:#0000ff;">new</span> UploadCompletedHandler(Uploader_UploadCompleted);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        _uploader.UploadCancelled += <span style="color:#0000ff;">new</span> UploadCancelledHandler(Uploader_UploadCancelled);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        _uploader.IsApproximatingProgress = <span style="color:#0000ff;">true</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        _uploader.ProgressReportingMultiplier = 0.8;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        _uploader.MaxUploadCount = BrowserUtil.Name == BrowserName.Firefox ? 6 : 2;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> UploadFiles(IEnumerable&lt;FileInfo&gt; files) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// Start upload</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        Progress.Value = 0;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        ProgressText.Text = <span style="color:#006080;">"0.00%"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        Uploader.PerformUpload(files, <span style="color:#0000ff;">new</span> Uri(Configuration.UploadServiceAddress + <span style="color:#006080;">"/Media/Upload"</span>, UriKind.Absolute),</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#006080;">"{BaseUri}/{FileType}/{FileKey}/{ChunkNumber}/{TotalChunks}?Name={FileName}"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// Add files to preview window</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        FileProgressContainer.Children.Clear();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">foreach</span> (MediaFileWrapper file <span style="color:#0000ff;">in</span> Uploader.MediaFiles) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            FileProgressContainer.Children.Add(<span style="color:#0000ff;">new</span> FileProgressDisplay(file));</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> CancelUpload() {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (Uploader.IsWorking) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            UploadButton.Content = <span style="color:#006080;">"Cancelling..."</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            UploadButton.IsEnabled = <span style="color:#0000ff;">false</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            Uploader.Cancel(<span style="color:#0000ff;">new</span> Uri(Configuration.UploadServiceAddress + <span style="color:#006080;">"/Media/CancelUpload"</span>, UriKind.Absolute),</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                <span style="color:#006080;">"{BaseUri}/{FileKey}"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">string</span> CreateFileFilter() {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// Get image extensions</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">string</span> imageExtensions = <span style="color:#0000ff;">string</span>.Empty;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">string</span> ext <span style="color:#0000ff;">in</span> MediaFileWrapper.IMAGE_TYPES.Split(<span style="color:#006080;">';'</span>)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">if</span> (imageExtensions.Length &gt; 0) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                imageExtensions += <span style="color:#006080;">";"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            imageExtensions += <span style="color:#006080;">"*."</span> + ext;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// Get video extensions</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">string</span> videoExtensions = <span style="color:#0000ff;">string</span>.Empty;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">string</span> ext <span style="color:#0000ff;">in</span> MediaFileWrapper.VIDEO_TYPES.Split(<span style="color:#006080;">';'</span>)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">if</span> (videoExtensions.Length &gt; 0) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                videoExtensions += <span style="color:#006080;">";"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            videoExtensions += <span style="color:#006080;">"*."</span> + ext;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// Create filter string</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">string</span>.Format(<span style="color:#006080;">"ImageFiles|{0}|Movie Files|{1}|All Supported Media|{0};{1}"</span>,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">          imageExtensions, videoExtensions);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> UploadButton_Click(<span style="color:#0000ff;">object</span> sender, RoutedEventArgs e) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">switch</span> (UploadButton.Content.ToString()) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">case</span> <span style="color:#006080;">"Upload!"</span>:</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                OpenFileDialog uploadDialog = <span style="color:#0000ff;">new</span> OpenFileDialog();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                uploadDialog.Filter = CreateFileFilter();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                uploadDialog.FilterIndex = 3;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                uploadDialog.Multiselect = <span style="color:#0000ff;">true</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                <span style="color:#0000ff;">if</span> (uploadDialog.ShowDialog() == <span style="color:#0000ff;">true</span>) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                    UploadButton.Content = <span style="color:#006080;">"Cancel"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                    UploadAnimation.Begin();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                    UploadFiles(uploadDialog.Files);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                <span style="color:#0000ff;">break</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">case</span> <span style="color:#006080;">"Cancel"</span>:</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                CancelUpload();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                <span style="color:#0000ff;">break</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> Uploader_UploadCancelled(<span style="color:#0000ff;">object</span> sender, EventArgs e) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        Dispatcher.BeginInvoke(<span style="color:#0000ff;">delegate</span>() {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            ProgressText.Text = <span style="color:#006080;">"Cancelled"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            UploadButton.Content = <span style="color:#006080;">"Upload!"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            UploadButton.IsEnabled = <span style="color:#0000ff;">true</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            UploadCompleteAnimation.Begin();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        });</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> Uploader_UploadCompleted(<span style="color:#0000ff;">object</span> sender, EventArgs e) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        Dispatcher.BeginInvoke(<span style="color:#0000ff;">delegate</span>() {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            ProgressText.Text = <span style="color:#006080;">"Completed"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            UploadButton.Content = <span style="color:#006080;">"Upload!"</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            UploadButton.IsEnabled = <span style="color:#0000ff;">true</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            UploadCompleteAnimation.Begin();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        });</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">void</span> Uploader_UploadProgressChanged(<span style="color:#0000ff;">object</span> sender, UploadProgressEventArgs e) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        Dispatcher.BeginInvoke(<span style="color:#0000ff;">delegate</span>() {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            Progress.Value = e.TotalPercentComplete;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            ProgressText.Text = <span style="color:#0000ff;">string</span>.Format(<span style="color:#006080;">"{0:n2}%"</span>, e.TotalPercentComplete);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">foreach</span> (FileProgress fileProgress <span style="color:#0000ff;">in</span> e.FileProgress) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                <span style="color:#0000ff;">foreach</span> (FileProgressDisplay fileDisplay <span style="color:#0000ff;">in</span> FileProgressContainer.Children) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                    <span style="color:#0000ff;">if</span> (fileProgress.File.File == fileDisplay.UploadedFile.File) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                        fileDisplay.Progress = fileProgress.Progress;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                        fileDisplay.ProgressText = <span style="color:#0000ff;">string</span>.Format(<span style="color:#006080;">"{0:n0}%"</span>, fileProgress.Progress);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                        <span style="color:#0000ff;">break</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">                }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        });</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">readonly</span> MediaUploadUtility _uploader;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">}</pre>
<p><!--CRLF--></div>
</div>
<p>Easy, right? <strong>UploadUtility</strong> abstracted away all of the mess!</p>
<p>Now let&#8217;s build the <strong>service</strong>. I created the <strong>MediaUploadHandler</strong> class, which inherits from <strong>UploadHandler</strong>, to provide the correct upload paths and provide additional processing dependent on the file type.</p>
<p><strong>MediaUploadHandler.cs</strong></p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> MediaUploadHandler : UploadHandler</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">{</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">string</span> UploadPath {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        get { <span style="color:#0000ff;">return</span> AppDomain.CurrentDomain.BaseDirectory + <span style="color:#006080;">"/Uploads/"</span>; }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">string</span> TemporaryUploadPath {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        get { <span style="color:#0000ff;">return</span> UploadPath; }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> ProcessCompletedFile(<span style="color:#0000ff;">string</span> fileKey, <span style="color:#0000ff;">string</span> fileName, <span style="color:#0000ff;">string</span> outputFilePath, <span style="color:#0000ff;">object</span>[] additionalParameters) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        MediaType mediaType = (MediaType) additionalParameters[0];</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// TODO: Process images/videos differently based on media type</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">}</pre>
<p><!--CRLF--></div>
</div>
<p>Next, add a new service to your WCF project. Edit the XAML to specify the <strong>Agnition.Utils.ServiceModel.UploadServiceHostFactory</strong>, and then create three service methods: <strong>UploadChunk</strong>, <strong>CancelChunk</strong>, and <strong>SpeedTest</strong> as follows. Be sure to pay attention to the URI format strings!</p>
<p><strong>Upload.svc</strong></p>
<div id="codeSnippetWrapper">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="background-color:#ffff00;">&lt;%@ ServiceHost</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">  CodeBehind="Upload.svc.cs"</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">  Debug="true"</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">  Language="C#"</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">  Service="Agnition.Test.Web.Service.Upload"</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">  Factory="Agnition.Test.Web.Service.UploadServiceHostFactory"</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">%&gt;</pre>
<p><!--CRLF--></div>
</div>
<p><strong>Upload.svc.cs</strong></p>
<div id="codeSnippetWrapper" style="font-size:8pt;overflow:auto;width:97.5%;cursor:text;max-height:200px;line-height:12pt;">
<div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">[ServiceContract(Namespace = <span style="color:#006080;">"Agnition.Test.Web.Service.Upload"</span>)]</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Upload</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">{</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">static</span> MediaUploadHandler MediaUploadHandler {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        get {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span> _uploadHandler;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    [OperationContract]</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    [WebInvoke(Method = HttpVerbs.PUT,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    UriTemplate = <span style="color:#006080;">"Media/Upload"</span>,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    ResponseFormat = WebMessageFormat.Json,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    RequestFormat = WebMessageFormat.Json)]</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> SpeedTestResponse(Stream data) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">byte</span>[] binaryData = UploadHandler.ReadInputStream(data);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">return</span> <span style="color:#006080;">"Speed Test Complete. "</span> + binaryData.Length + <span style="color:#006080;">" bytes received."</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    [OperationContract]</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    [WebInvoke(Method = HttpVerbs.DELETE,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    UriTemplate = <span style="color:#006080;">"Media/CancelUpload/{fileKey}"</span>,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    ResponseFormat = WebMessageFormat.Json,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    RequestFormat = WebMessageFormat.Json)]</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> CancelUpload(<span style="color:#0000ff;">string</span> fileKey) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        fileKey = HttpUtility.UrlDecode(fileKey);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// Check input variables</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">string</span>.IsNullOrEmpty(fileKey)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid FileKey"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        MediaUploadHandler.CancelUpload(fileKey);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    [OperationContract]</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    [WebInvoke(Method = HttpVerbs.PUT,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    UriTemplate = <span style="color:#006080;">"Media/Upload/{fileType}/{fileKey}/{chunkNumber}/{totalChunks}?Name={fileName}"</span>,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    ResponseFormat = WebMessageFormat.Json,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    RequestFormat = WebMessageFormat.Json)]</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> UploadChunk(<span style="color:#0000ff;">string</span> fileKey, <span style="color:#0000ff;">string</span> fileName, <span style="color:#0000ff;">string</span> fileType, <span style="color:#0000ff;">string</span> chunkNumber, <span style="color:#0000ff;">string</span> totalChunks, Stream data) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// Check input variables</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">string</span>.IsNullOrEmpty(fileKey)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid FileKey"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">string</span>.IsNullOrEmpty(fileName)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid FileName"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">string</span>.IsNullOrEmpty(fileType)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid FileType"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">string</span>.IsNullOrEmpty(chunkNumber)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid ChunkNumber"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">string</span>.IsNullOrEmpty(totalChunks)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid TotalChunks"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> ((data == <span style="color:#0000ff;">null</span>) || (!data.CanRead)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid Data"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#008000;">// Parse input</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">int</span> iChunkNumber = 0;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">int</span> iTotalChunks = 0;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        FileType eFileType = FileType.Other;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (!<span style="color:#0000ff;">int</span>.TryParse(chunkNumber, <span style="color:#0000ff;">out</span> iChunkNumber)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid ChunkNumber"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (!<span style="color:#0000ff;">int</span>.TryParse(totalChunks, <span style="color:#0000ff;">out</span> iTotalChunks)) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid TotalChunks"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        fileName = HttpUtility.UrlDecode(fileName).Trim();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">if</span> (fileName.Length == 0) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid FileName"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">try</span> {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            fileType = HttpUtility.UrlDecode(fileType);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            eFileType = (FileType) Enum.Parse(<span style="color:#0000ff;">typeof</span>(FileType), fileType, <span style="color:#0000ff;">true</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">catch</span> {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnBadRequest(<span style="color:#006080;">"Invalid FileType"</span>);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#0000ff;">return</span>;</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">try</span> {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            <span style="color:#008000;">// Process the uplaoad</span></pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            MediaUploadHandler.ProcessUpload(fileKey, fileName, iChunkNumber, iTotalChunks, data, eFileType);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        <span style="color:#0000ff;">catch</span> (Exception ex) {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">            RestfulServiceHelper.ReturnServerError(ex.Message);</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">enum</span> FileType</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    {</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        Other = 0,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        Image = 1,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">        Video = 2,</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    }</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;"> </pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">    <span style="color:#0000ff;">private</span> <span style="color:#0000ff;">readonly</span> <span style="color:#0000ff;">static</span> MediaUploadHandler _uploadHandler = <span style="color:#0000ff;">new</span> MediaUploadHandler();</pre>
<p><!--CRLF--></p>
<pre style="font-size:8pt;overflow:visible;width:100%;color:black;line-height:12pt;">}</pre>
<p><!--CRLF--></div>
</div>
<p>That&#8217;s it! All you had to do was take care of parsing the input, and <strong>UploadHandler</strong> takes care of the rest.</p>
<h3>Source Code</h3>
<p>Get the <a href="http://www.stevecommisso.com/Bragosphere/Posts/SilverlightWcfRestfulUpload.zip">Source Code</a> for this article here. It also includes the <strong>Microsoft.ServiceModel.Web</strong> library from the <a href="http://go.microsoft.com/?linkid=9632200">WCF Rest Starter Kit</a>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/zleek.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/zleek.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/zleek.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/zleek.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/zleek.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/zleek.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/zleek.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/zleek.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/zleek.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/zleek.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=zleek.wordpress.com&blog=6494707&post=12&subd=zleek&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://zleek.wordpress.com/2009/02/12/using-silverlight-and-wcf-to-create-a-restful-file-upload-utility/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ad6740168414ea06d3d8ddc94d3514e0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">zleek</media:title>
		</media:content>

		<media:content url="http://zleek.files.wordpress.com/2009/02/ui-thumb.jpg" medium="image">
			<media:title type="html">ui</media:title>
		</media:content>
	</item>
	</channel>
</rss>