<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Henrik's Blog</title><link>http://blogs.msdn.com/b/henrikn/</link><description>Henrik works at Microsoft building software for the Web. You can also find me on twitter -- my twitter handle is @frystyk. </description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>ASP.NET Web API and HTTP Range Requests (Link)</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/11/23/asp-net-web-api-and-http-range-requests-link.aspx</link><pubDate>Fri, 23 Nov 2012 20:40:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10371204</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10371204</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/11/23/asp-net-web-api-and-http-range-requests-link.aspx#comments</comments><description>&lt;p&gt;Posted the blog &lt;a href="http://blogs.msdn.com/b/webdev/archive/2012/11/23/asp-net-web-api-and-http-byte-range-support.aspx"&gt;ASP.NET Web API and HTTP Byte Range Support&lt;/a&gt; on the &lt;a href="http://blogs.msdn.com/b/webdev/"&gt;.NET Web Development and Tools Blog&lt;/a&gt; explaining how to support HTTP Range requests with ASP.NET Web API.&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10371204" width="1" height="1"&gt;</description></item><item><title>An ASP.NET Open Source How-To Decoder Ring (Link)</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/09/19/an-asp-net-open-source-how-to-decoder-ring-link.aspx</link><pubDate>Wed, 19 Sep 2012 17:44:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10350913</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10350913</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/09/19/an-asp-net-open-source-how-to-decoder-ring-link.aspx#comments</comments><description>&lt;p&gt;Posted the blog &lt;a href="http://blogs.msdn.com/b/webdev/archive/2012/09/16/an-asp-net-open-source-how-to-decoder-ring.aspx" target="_blank"&gt;An ASP.NET Open Source How-To Decoder Ring&lt;/a&gt; on the &lt;a href="http://blogs.msdn.com/b/webdev/"&gt;.NET Web Development and Tools Blog&lt;/a&gt; explaining how to get started with ASP.NET and Open Source development by using the latest nightly drops, compiling it yourself, or creating pull requests.&lt;/p&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10350913" width="1" height="1"&gt;</description></item><item><title>Link to Getting Symbols and Source with ASP.NET Nightly NuGet Packages</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/08/30/link-to-getting-symbols-and-source-with-asp-net-nightly-nuget-packages.aspx</link><pubDate>Thu, 30 Aug 2012 22:31:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10345188</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10345188</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/08/30/link-to-getting-symbols-and-source-with-asp-net-nightly-nuget-packages.aspx#comments</comments><description>&lt;p&gt;Posted the blog &lt;a href="http://blogs.msdn.com/b/webdev/archive/2012/08/30/getting-symbols-and-source-with-asp-net-nightly-nuget-packages.aspx"&gt;Getting Symbols and Source with ASP.NET Nightly NuGet Packages&lt;/a&gt; on the &lt;a href="http://blogs.msdn.com/b/webdev/"&gt;.NET Web Development and Tools Blog&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10345188" width="1" height="1"&gt;</description></item><item><title>Link to List of ASP.NET Web API and HttpClient Samples</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/08/26/asp-net-web-api-and-httpclient-samples.aspx</link><pubDate>Sun, 26 Aug 2012 18:20:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10343653</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10343653</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/08/26/asp-net-web-api-and-httpclient-samples.aspx#comments</comments><description>&lt;p&gt;Posted the blog &lt;a href="http://blogs.msdn.com/b/webdev/archive/2012/08/26/asp-net-web-api-and-httpclient-samples.aspx"&gt;List of ASP.NET Web API and HttpClient Samples&lt;/a&gt; on the &lt;a href="http://blogs.msdn.com/b/webdev/"&gt;.NET Web Development and Tools Blog&lt;/a&gt;&lt;/p&gt; Have fun!&amp;#160; &lt;p&gt;Henrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10343653" width="1" height="1"&gt;</description></item><item><title>Getting Started With ASP.NET Web Stack Source on CodePlex</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/08/17/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx</link><pubDate>Fri, 17 Aug 2012 15:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292048</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10292048</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/08/17/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Updated instructions to target &lt;a href="http://www.microsoft.com/vstudio"&gt;Visual Studio 2012&lt;/a&gt;. While you can still use Visual Studio 2010 there are big advantages to using VS 2012.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Please also check out &lt;a href="http://aspnetwebstack.codeplex.com/wikipage?title=Building%20from%20Source"&gt;the documentation on Codeplex&lt;/a&gt; for how to build.&lt;/p&gt;  &lt;p&gt;As you probably know by now, ASP.NET MVC, Web Pages, Web API is now all open source (if you haven’t heard then please read &lt;a href="http://weblogs.asp.net/scottgu/archive/2012/03/27/asp-net-mvc-web-api-razor-and-open-source.aspx"&gt;ScottGu’s blog&lt;/a&gt;). What this means is that the source for all our runtime components is now available on &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;CodePlex&lt;/a&gt; for you to review and use as well as suggest changes to in the form of &lt;a href="http://aspnetwebstack.codeplex.com/workitem/list/basic"&gt;issues&lt;/a&gt; or &lt;a href="http://aspnetwebstack.codeplex.com/sourcecontrol/list/contributions?statusFilter=all&amp;amp;reviewerFilter=all"&gt;pull requests&lt;/a&gt;. You can also &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/list/changesets"&gt;track recent code submits&lt;/a&gt; and check that the code looks good.&lt;/p&gt;  &lt;p&gt;This blog will give you some hints and tricks for getting started working with the source code. Note you still have the &lt;a href="http://www.asp.net/web-api"&gt;official installers&lt;/a&gt; which contain the usual MSI with NuGet packages. In fact, if you don’t intend to work directly with the source, I would go with the installer because it provides tooling support for Visual Studio (project templates, etc.) which are not available in the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/list/changesets"&gt;CodePlex repository&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;If you want to live on the edge (as in without support) then you can also &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/06/01/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx"&gt;use the nightly NuGet packages&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Before getting started, you should take a quick look at &lt;a href="http://aspnetwebstack.codeplex.com/wikipage?title=Contributing"&gt;the ways in which you can contribute&lt;/a&gt;. It contains a lot of good information about how you can contribute, what the process is for contributing, and how contributions are evaluated. The more you familiarize yourself with the process, the less chance of getting disappointed later.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h1&gt;Prerequisites&lt;/h1&gt;  &lt;p&gt;Before getting the source you should setup your dev machine with the right tools to compile the source (obviously you shouldn’t be running anything critical on the dev machine). The prerequisites listed are not the only way of setting up your developer environment but the purpose here is to reduce the steps and improve the chance of getting off to a good start.&lt;/p&gt;  &lt;h4&gt;Visual Studio&lt;/h4&gt;  &lt;p&gt;You can use either a &lt;a href="http://www.microsoft.com/vstudio"&gt;Visual Studio 2012 full edition&lt;/a&gt; or &lt;a href="http://www.microsoft.com/visualstudio/11/en-us/downloads#express-web"&gt;Visual Studio Express 2012 for Web edition&lt;/a&gt; to open and compile the project solution.&amp;#160; &lt;/p&gt;  &lt;h4&gt;Git&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://git-scm.com/"&gt;Git&lt;/a&gt; is the version control system used to manage the source. If you are not already a Git expert then you should check out the &lt;a href="http://git-scm.com/"&gt;Git site for how to get started&lt;/a&gt;. Git is great to work with but if you are used to more traditional versioning control systems then it will take a little time to get “re-programmed”. Here are the steps for the Git tools that I use and recommend you install:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://msysgit.github.com/"&gt;Git for Windows&lt;/a&gt; (use one of the &lt;a href="http://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git"&gt;binary downloads&lt;/a&gt;). Using the default setup options should be fine – for reasons that will become clear later I don’t recommend using a Windows Command Prompt for issuing Git commands. &lt;/li&gt;    &lt;li&gt;&lt;a href="http://code.google.com/p/tortoisegit/"&gt;TortoiseGit&lt;/a&gt; (use one of the &lt;a href="http://code.google.com/p/tortoisegit/downloads/list"&gt;binary downloads&lt;/a&gt;) which integrates Git with Windows Explorer allowing you to see the state of your local repository clone in an graphical manner.&lt;/li&gt;    &lt;li&gt;&lt;a href="https://github.com/dahlbyk/posh-git"&gt;PowerShell Git extensions&lt;/a&gt;. Even if you are not a PowerShell user I recommend this for executing Git commands from the command line as it gives you critical clues as to what branch you are on and what state you are in. You can always use a regular shell for everything other than Git commands if you can’t find your way around PowerShell. The installation here is slightly more complicated but if you &lt;a href="https://github.com/dahlbyk/posh-git#readme"&gt;follow the readme&lt;/a&gt; then you should be fine.&lt;/li&gt; &lt;/ol&gt;  &lt;h4&gt;CodePlex&lt;/h4&gt;  &lt;p&gt;Make sure you have &lt;a href="https://aspnetwebstack.codeplex.com/site/register?associate=None&amp;amp;ProjectName=aspnetwebstack"&gt;a CodePlex account&lt;/a&gt; – you need it to participate in discussion forums, enter work items, and create projects. Once you have an account, I would encourage you to browse around the &lt;a href="http://aspnetwebstack.codeplex.com"&gt;CodePlex project&lt;/a&gt; – there’s a lot of good information. Also you can sign up for notifications or subscribe to RSS feeds for discussions, source code changes, and updates to issues.&lt;/p&gt;  &lt;h1&gt;Cloning the Repository&lt;/h1&gt;  &lt;p&gt;Ok, now that you have all the prerequisites it is time to get the source. We use PowerShell and then clone the repository like this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git clone &lt;/strong&gt;&lt;a href="https://git01.codeplex.com/aspnetwebstack.git"&gt;&lt;strong&gt;https://git01.codeplex.com/aspnetwebstack.git&lt;/strong&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The result of the command should look like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2055.Clone2_5F00_771F1E78.png"&gt;&lt;img title="Clone2" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Clone2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8132.Clone2_5F00_thumb_5F00_12C3AA6F.png" width="504" height="266" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To sync to the latest changes use the commands&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git checkout master&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;git pull --rebase origin&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;That will pull down all changes to the CodePlex repository and get your master branch up to date.&lt;/p&gt;  &lt;h1&gt;Skipping Strong Name Verification&lt;/h1&gt;  &lt;p&gt;By default the projects are &lt;a href="http://msdn.microsoft.com/en-us/library/9fas12zx.aspx"&gt;delay signed&lt;/a&gt; which means that they are not fully signed. Unless we explicitly turn off strong name verification for the compiled assemblies, building will cause a set of strong name verification failures. To only disable strong name verification for the WebStackRuntime assemblies, &lt;a href="http://aka.ms/skipsn"&gt;download the SkipStrongNames zip&lt;/a&gt; file and unzip it. Then run the command &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;.\SkipStrongNames.exe /e&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The result should look like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8080.sn_5F00_04EE2F18.png"&gt;&lt;img title="sn" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="sn" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/1121.sn_5F00_thumb_5F00_2BBC4558.png" width="504" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You can later run &lt;strong&gt;.\SkipStrongNames.exe /d&lt;/strong&gt; to re-enable strong name verification if/when you want to do so.&amp;#160; &lt;/p&gt;  &lt;h1&gt;Compiling from Command Line&lt;/h1&gt;  &lt;p&gt;To compile &lt;strong&gt;and&lt;/strong&gt; run unit tests as well as StyleCop and FxCop directly from the command line, simply run this from the aspnetwebstack folder:&amp;#160; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&amp;#160;&lt;strong&gt;.\build.cmd&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This is the authoritative way to build ASP.NET Web Stack. If the build is successful you should see &lt;strong&gt;BUILD SUCCESSFUL&lt;/strong&gt; when it has completed.&lt;/p&gt;  &lt;h1&gt;Compiling from Visual Studio&lt;/h1&gt;  &lt;p&gt;In Visual Studio Express you can &lt;strong&gt;build the source but not run the unit tests&lt;/strong&gt;. In full Visual Studio you can both compile and run unit tests – just install &lt;a href="http://visualstudiogallery.msdn.microsoft.com/463c5987-f82b-46c8-a97e-b1cde42b9099"&gt;xUnit.net runner for Visual Studio 2012&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;In either case, just open the solution &lt;strong&gt;Runtime.sln&lt;/strong&gt; and compile as normal. If you haven’t compiled from command line before then you need to enable NuGet Package Restore by opening the &lt;strong&gt;Tools/Options/Package Manager&lt;/strong&gt; menu and make sure Package Restore is enabled:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/5008.PackageRestore_5F00_2029BD75.png"&gt;&lt;img title="PackageRestore" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="PackageRestore" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6560.PackageRestore_5F00_thumb_5F00_46F7D3B5.png" width="504" height="294" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;That’s it – you are now free to move around the cabin!&lt;/p&gt;  &lt;p&gt;You may also want to check out the blog &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/10/using-forks-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;Contributing to ASP.NET Web Stack Source on CodePlex&lt;/a&gt; which explains how to setup and work with a fork.&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292048" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>ASP.NET Web API Released and a Preview of What’s Next</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/08/15/asp-net-web-api-released-and-a-preview-of-what-s-next.aspx</link><pubDate>Wed, 15 Aug 2012 20:54:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10340128</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>22</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10340128</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/08/15/asp-net-web-api-released-and-a-preview-of-what-s-next.aspx#comments</comments><description>&lt;p&gt;Today we announced the release of &lt;a href="http://blogs.msdn.com/b/webdev/archive/2012/08/15/visual-studio-2012-rtw.aspx"&gt;Visual Studio 2012 and .NET 4.5&lt;/a&gt; which of course includes &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt;. There is a ton of new features in VS 2012 and I highly recommend checking out the &lt;a href="http://www.asp.net/vnext/overview/videos"&gt;videos by Scott Hanselman&lt;/a&gt; demonstrating a broad set of features of VS 2012 and .NET 4.5.&lt;/p&gt;  &lt;p&gt;In addition to shipping as part of Visual Studio &lt;strong&gt;2012&lt;/strong&gt; you can also &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=30683"&gt;download Web API for Visual Studio &lt;strong&gt;2010&lt;/strong&gt;&lt;/a&gt; as a standalone installer and as always, you can find us in our &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;Open Source home on codeplex&lt;/a&gt; where you can see the source, contribute pull requests, and log issues. The official release (RTM) corresponds to &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/list/changesets?branch=v2-rtm"&gt;this branch in the source repository&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Further, you can find a bunch of &lt;a href="http://www.asp.net/web-api/samples"&gt;ASP.NET Web API and HttpClient samples&lt;/a&gt; demonstrating many of the features. The samples also &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/08/15/asp-net-web-api-sample-on-codeplex.aspx"&gt;live on codeplex&lt;/a&gt; so that you can &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/08/15/asp-net-web-api-sample-on-codeplex.aspx"&gt;download them and work with them&lt;/a&gt;. Here you will find samples for both VS 2010 and VS 2012 illustrating a variety of features of both ASP.NET Web API and HttpClient.&lt;/p&gt;  &lt;p&gt;In addition to all this we also today release &lt;strong&gt;four preview NuGet packages&lt;/strong&gt; which build on the ASP.NET Web API RTM bits but provide new features. The previews are explicitly marked as alpha releases as they are &lt;strong&gt;early&lt;/strong&gt; builds. The previews are continuously updated and you can get the &lt;strong&gt;latest builds from our nightly NuGet feed&lt;/strong&gt;, please see &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/06/01/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx" target="_blank"&gt;Using Nightly ASP.NET Web Stack NuGet Packages&lt;/a&gt; for details.&lt;/p&gt;  &lt;h2&gt;OData&lt;/h2&gt;  &lt;p&gt;The &lt;a href="http://nuget.org/packages/Microsoft.AspNet.WebApi.OData"&gt;Microsoft ASP.NET Web API OData&lt;/a&gt; package contains everything you need to create &lt;a href="http://odata.org"&gt;OData&lt;/a&gt; endpoints using ASP.NET Web API and to support OData query syntax for your Web APIs. It supersedes the early query support in ASP.NET Web API Beta with much better support for both querying as well as sending and receiving OData formatted payloads. For a detailed description of the OData support, please see the blog &lt;a href="http://blogs.msdn.com/b/alexj/archive/2012/08/15/odata-support-in-asp-net-web-api.aspx"&gt;OData support in ASP.NET Web API&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;There are two samples demonstrating how to use the OData package that both available in source as part of &lt;a href="http://www.asp.net/web-api/samples"&gt;ASP.NET Web API and HttpClient samples&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ODataQueryableSample&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This sample shows how to introduce OData queries in ASP.NET Web API using either the [Queryable] attribute or by using the ODataQueryOptions action parameter which allows the action to manually inspect the query before it is being executed. The sample illustrates queries using $orderby, $skip, $top, and $filter as well as any() and all().&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;ODataServiceSample&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This sample illustrates how to create an OData service consisting of four entities and three ApiControllers. The controllers provide various levels of functionality in terms of the OData functionality they expose. In addition the OData service exposes a $metadata document which allows the data to the consumed by WCF Data Service clients and other clients that accept the $metadata format.&lt;/p&gt;  &lt;p&gt;The data model contains three entities (Supplier, ProductFamily, and Product) connected in various ways and uses three sample controllers demonstrating various levels of exposing OData ranging from Query to Update and Delete.&lt;/p&gt;  &lt;p&gt;Furthermore, the ODataService exposes a Service Document (aka. $metadata document) that lists all the top-level entities so clients can discover them. This enables OData clients to discover and consume OData Services exposed through ASP.NET Web API.&lt;/p&gt;  &lt;h2&gt;Help Page&lt;/h2&gt;  &lt;p&gt;The &lt;a href="http://nuget.org/packages/Microsoft.AspNet.WebApi.HelpPage"&gt;Microsoft ASP.NET Web API Help Page&lt;/a&gt; package automatically generates help page content for Web APIs on your site. Visitors to your help page can use this content to learn how to call your web APIs. Everything generated by the help page is fully customizable using ASP.NET MVC and Razor. ASP.NET Web API Help Page is a great addition to any ASP.NET Web API project. &lt;/p&gt;  &lt;p&gt;For more information and a nice video walkthrough, please see the blog &lt;a href="http://blogs.msdn.com/b/yaohuang1/archive/2012/08/15/introducing-the-asp-net-web-api-help-page-preview.aspx"&gt;Introducing the ASP.NET Web API Help Page (Preview)&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;h2&gt;Tracing&lt;/h2&gt;  &lt;p&gt;The &lt;a href="http://nuget.org/packages/Microsoft.AspNet.WebApi.Tracing"&gt;Microsoft ASP.NET Web API Tracing&lt;/a&gt; package allows the ASP.NET Web API framework to trace to System.Diagnostics.Trace so that you can now get trace messages from the entire ASP.NET Web API message pipeline from when a request starts being processed to a response is generated.&lt;/p&gt;  &lt;p&gt;When installing this package in your project, it adds the following source file was added to your project:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;App_Start\TraceConfig.cs&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;To enable tracing in your application, simply add the following line of code to your startup code (for example in WebApiConfig.cs or Global.asax.cs in an MVC 4 project):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;TraceConfig.Register(config);&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;where 'config' is the HttpConfiguration instance for your application. When running your application you can now see trace output written toSystem.Diagnostics.Trace.&lt;/p&gt;  &lt;p&gt;For more information about tracing, please see the blog &lt;a href="http://blogs.msdn.com/b/roncain/archive/2012/08/16/asp-net-web-api-tracing-preview.aspx"&gt;ASP.NET Web API Tracing (Preview)&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;h2&gt;System.Net.Http.Formatting for Windows 8&lt;/h2&gt;  &lt;p&gt;The &lt;a href="http://nuget.org/packages/Microsoft.AspNet.WebApi.client"&gt;Microsoft ASP.NET Web API Client Libraries&lt;/a&gt; package adds support for formatting and content negotiation to System.Net.Http when writing Windows Store Apps. It includes support for JSON, XML, form URL encoded data, as well as MIME multipart. This package requires Visual Studio 2012 and Windows 8.&lt;/p&gt;  &lt;p&gt;We are looking forward to your feedback – both on RTM as well as these previews. &lt;/p&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10340128" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>ASP.NET Web API Samples on Codeplex</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/08/15/asp-net-web-api-sample-on-codeplex.aspx</link><pubDate>Wed, 15 Aug 2012 09:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10332082</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>15</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10332082</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/08/15/asp-net-web-api-sample-on-codeplex.aspx#comments</comments><description>&lt;p&gt;Here’s how to get up and running with the &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;ASP.NET Web API&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx"&gt;HttpClient&lt;/a&gt; samples that you can find in our &lt;a href="http://aspnet.codeplex.com/SourceControl/list/changesets"&gt;samples repository on aspnet.codeplex.com&lt;/a&gt;. For a list of the samples please see &lt;a href="http://blogs.msdn.com/b/webdev/archive/2012/08/26/asp-net-web-api-and-httpclient-samples.aspx"&gt;List of ASP.NET Web API and HttpClient Samples&lt;/a&gt; as well as our &lt;a href="http://www.asp.net"&gt;list of samples on www.asp.net&lt;/a&gt;.&lt;/p&gt;  &lt;h1&gt;Prerequisites&lt;/h1&gt;  &lt;p&gt;The samples are split into two parts: those that target .Net 4 and those that target .Net 4.5. The latter use the async/await keywords introduced in Visual Studio 2012 which makes programming with asynchronous tasks much simpler.&lt;/p&gt;  &lt;p&gt;Many of the samples use self host for starting ASP.NET Web API (that is, they run outside ASP.NET). These samples all use the local TCP port 50231 to listen for HTTP traffic. In order to start listening on that port you have to &lt;strong&gt;register an HTTP namespace with http.sys&lt;/strong&gt; (or alternatively run Visual Studio as Administrator). You register the namespace from an &lt;strong&gt;elevated&lt;/strong&gt; command prompt like this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;netsh http add urlacl &lt;/strong&gt;&lt;strong&gt;http://+:50231/&lt;/strong&gt;&lt;strong&gt; user=%USERDOMAIN%\%USERNAME%&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For details, see &lt;a href="http://msdn.microsoft.com/en-us/library/windows/desktop/cc307236"&gt;how to register an http namespace with http.sys&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;h1&gt;Getting the Samples&lt;/h1&gt;  &lt;p&gt;You can either clone the samples repository using the command (see &lt;a href="http://codeplex.codeplex.com/wikipage?title=Using%20Git%20with%20CodePlex&amp;amp;referringTitle=Source%20control%20clients&amp;amp;ProjectName=codeplex"&gt;Using Git with CodePlex&lt;/a&gt; for details):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git clone &lt;/strong&gt;&lt;strong&gt;https://git01.codeplex.com/aspnet&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt; or &lt;a href="http://aspnet.codeplex.com/SourceControl/list/changesets"&gt;download the samples by selecting the Download link&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3580.Download_5F00_5D4F7029.png"&gt;&lt;img title="Download" style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" border="0" alt="Download" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8371.Download_5F00_thumb_5F00_0334FAB3.png" width="604" height="394" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The former (i.e. &lt;a href="http://codeplex.codeplex.com/wikipage?title=Using%20Git%20with%20CodePlex&amp;amp;referringTitle=Source%20control%20clients&amp;amp;ProjectName=codeplex" target="_blank"&gt;using git&lt;/a&gt;) is best if you want to stay up to date with respect to the samples.&lt;/p&gt;  &lt;h1&gt;Running the Samples&lt;/h1&gt;  &lt;p&gt;The samples can all be run by hitting F5 in Visual Studio but some may need additional information such as an application key. The first time you run a sample, it will download the various NuGet packages and ask you to confirm their installation for that project.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: When downloading the NuGet packages you may see a compilation warning saying something like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, click on Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;In that case do as the message says and check &lt;strong&gt;Allow NuGet to download missing packages during build&lt;/strong&gt; under Package Manager in Options. &lt;/p&gt;  &lt;h1&gt;Comments and Suggestions&lt;/h1&gt;  &lt;p&gt;Please &lt;a href="http://aspnet.codeplex.com/workitem/list/basic"&gt;file issues on the samples&lt;/a&gt; as well as ideas for other samples. Let us know what you think; what you would like to see, and how this can be a useful collection of samples.&amp;#160; &lt;/p&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10332082" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>HttpClient, HttpClientHandler, and WebRequestHandler Explained</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/08/07/httpclient-httpclienthandler-and-httpwebrequesthandler.aspx</link><pubDate>Tue, 07 Aug 2012 14:32:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10337522</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10337522</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/08/07/httpclient-httpclienthandler-and-httpwebrequesthandler.aspx#comments</comments><description>&lt;p&gt;In two previous blogs I describe &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/16/httpclient-is-here.aspx"&gt;how to use HttpClient&lt;/a&gt; as well as how to use the &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/27/asp-net-web-api-updates-april-27.aspx"&gt;HttpMessageHandler pipeline&lt;/a&gt;. What we haven’t done explicitly is showing when and how to use &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx"&gt;HttpClient&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler(v=VS.110).aspx"&gt;HttpClientHandler&lt;/a&gt;, and &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler(v=vs.110).aspx"&gt;WebRequestHandler&lt;/a&gt;. This is the purpose of this blog.&lt;/p&gt;  &lt;p&gt;The first thing to remember is that HttpClient &lt;a href="http://www.asp.net/web-api/overview/working-with-http/http-message-handlers"&gt;uses the HttpMessageHandler pipeline for sending and receiving requests&lt;/a&gt;. The default handler implementations (HttpClientHandler and WebRequestHandler) both sit on top of &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx"&gt;HttpWebRequest&lt;/a&gt; which has a lot of properties for controlling how to deal with requests and responses. However, in order to stay simple, HttpClient doesn’t expose all these properties up front – it would make it unwieldy and show a lot of things that are rarely used.&amp;#160; &lt;/p&gt;  &lt;p&gt;If you need to access these properties then there are two ways of doing it: use either HttpClientHandler or WebRequestHandler. Both are HttpMessageHandlers hooked in as part of the HttpMessageHandler pipeline. Below we will describe when and how to use these handlers, how they differ, as well as how to combine them with your own handlers.&lt;/p&gt;  &lt;p&gt;You can find this code for this sample in the &lt;a href="http://aspnet.codeplex.com/SourceControl/list/changesets"&gt;aspnet.codeplex.com code repository&lt;/a&gt; and there are instructions here for &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/07/20/asp-net-web-api-sample-on-codeplex.aspx"&gt;how to use the samples&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;h1&gt;HttpClient&lt;/h1&gt;  &lt;p&gt;The default HttpClient is the simplest way in which you can start sending requests. A single HttpClient can be used to send as many HTTP requests as you want concurrently so in many scenarios you can just create one HttpClient and then use that for all your requests.&lt;/p&gt;  &lt;p&gt;HttpClient has a few properties that are commonly used and which you can set &lt;strong&gt;up until the point&lt;/strong&gt; where you start sending requests, namely:&lt;/p&gt;  &lt;table border="1" cellspacing="0"&gt;&lt;caption&gt;The properties exposed by HttpClient directly&lt;/caption&gt;&lt;thead&gt;     &lt;tr&gt;       &lt;th&gt;Name&lt;/th&gt;        &lt;th&gt;Description&lt;/th&gt;     &lt;/tr&gt;   &lt;/thead&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.baseaddress(v=vs.110).aspx"&gt;BaseAddress&lt;/a&gt; &lt;/td&gt;        &lt;td&gt;&lt;span&gt;Gets or sets the base address of Uniform Resource Identifier (URI) of the Internet resource used when sending requests.&lt;/span&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.defaultrequestheaders(v=vs.110).aspx"&gt;DefaultRequestHeaders&lt;/a&gt; &lt;/td&gt;        &lt;td&gt;&lt;span&gt;Gets the headers which should be sent with each request.&lt;/span&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.maxresponsecontentbuffersize(v=vs.110).aspx"&gt;MaxResponseContentBufferSize&lt;/a&gt; &lt;/td&gt;        &lt;td&gt;&lt;span&gt;Gets or sets the maximum number of bytes to buffer when reading the response content.&lt;/span&gt; &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclient.timeout(v=vs.110).aspx"&gt;Timeout&lt;/a&gt; &lt;/td&gt;        &lt;td&gt;&lt;span&gt;Gets or sets the number of milliseconds to wait before the request times out.&lt;/span&gt; &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Here’s an example of how to create a simple HttpClient and issue a request while setting the timeout for all requests:&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create an HttpClient and set the timeout for requests&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; HttpClient client = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClient();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; client.Timeout = TimeSpan.FromSeconds(10);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Issue a request&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; client.GetAsync(_address).ContinueWith(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     getTask =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (getTask.IsCanceled)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request was canceled&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (getTask.IsFaulted)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request failed: {0}&amp;quot;&lt;/span&gt;, getTask.Exception);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;             HttpResponseMessage response = getTask.Result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request completed with status code {0}&amp;quot;&lt;/span&gt;, response.StatusCode);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     });&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;If you have additional handlers which you want to wire up as well then the simplest way is to use the HttpClientFactory class. Here’s an example wiring up 3 custom message handlers:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create an HttpClient and add message handlers for the client&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; HttpClient client = HttpClientFactory.Create(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client A&amp;quot;&lt;/span&gt;, 2),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client B&amp;quot;&lt;/span&gt;, 4),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client C&amp;quot;&lt;/span&gt;, 6));&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;HttpClientHandler&lt;/h1&gt;

&lt;p&gt;HttpClientHandler is an HttpMessageHandler with a common set of properties that works across most versions of the HttpWebRequest API. This is the default handler and so is what you get if you use the default constructor. However, in order to actually get access to the various properties (see below) you have to explicitly create it and then pass it to HttpClient.&lt;/p&gt;

&lt;table border="1" cellspacing="0"&gt;&lt;caption&gt;List of Properties for HttpClientHandler&lt;/caption&gt;&lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;

      &lt;th&gt;Description&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.allowautoredirect%28v=vs.110%29.aspx"&gt;AllowAutoRedirect&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets a value that indicates whether the handler should follow redirection responses.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.automaticdecompression%28v=vs.110%29.aspx"&gt;AutomaticDecompression&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets the type of decompression method used by the handler for automatic decompression of the HTTP content response.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.clientcertificateoptions%28v=vs.110%29.aspx"&gt;ClientCertificateOptions&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets the collection of security certificates that are associated with this handler.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.cookiecontainer%28v=vs.110%29.aspx"&gt;CookieContainer&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets the cookie container used to store server cookies by the handler.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.credentials%28v=vs.110%29.aspx"&gt;Credentials&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets authentication information used by this handler.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.maxautomaticredirections%28v=vs.110%29.aspx"&gt;MaxAutomaticRedirections&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets the maximum number of redirects that the handler follows.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.maxrequestcontentbuffersize%28v=vs.110%29.aspx"&gt;MaxRequestContentBufferSize&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets the maximum request content buffer size used by the handler.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.preauthenticate%28v=vs.110%29.aspx"&gt;PreAuthenticate&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets a value that indicates whether the handler sends an Authorization header with the request.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.proxy%28v=vs.110%29.aspx"&gt;Proxy&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets proxy information used by the handler.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.supportsautomaticdecompression%28v=vs.110%29.aspx"&gt;SupportsAutomaticDecompression&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets a value that indicates whether the handler supports automatic response content decompression.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.supportsproxy%28v=vs.110%29.aspx"&gt;SupportsProxy&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets a value that indicates whether the handler supports proxy settings.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.supportsredirectconfiguration%28v=vs.110%29.aspx"&gt;SupportsRedirectConfiguration&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets a value that indicates whether the handler supports configuration settings for the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.allowautoredirect%28v=vs.110%29.aspx"&gt;AllowAutoRedirect&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.maxautomaticredirections%28v=vs.110%29.aspx"&gt;MaxAutomaticRedirections&lt;/a&gt; properties.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.usecookies%28v=vs.110%29.aspx"&gt;UseCookies&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets a value that indicates whether the handler uses the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.cookiecontainer%28v=vs.110%29.aspx"&gt;CookieContainer&lt;/a&gt; property to store server cookies and uses these cookies when sending requests.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.usedefaultcredentials%28v=vs.110%29.aspx"&gt;UseDefaultCredentials&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets a value that controls whether default credentials are sent with requests by the handler.&lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.httpclienthandler.useproxy%28v=vs.110%29.aspx"&gt;UseProxy&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets a value that indicates whether the handler uses a proxy for requests. &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Here’s an example of how to create an HttpClientHandler,&amp;#160; set a property, and pass it to HttpClient:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create HttpClientHandler and set UseDefaultCredentials property&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; HttpClientHandler clientHandler = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClientHandler();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; clientHandler.UseDefaultCredentials = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create an HttpClient using the HttpClientHandler&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; HttpClient client = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClient(clientHandler);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Like above, you can combine your HttpClientHandler instance with other custom handlers, here’s what it looks like:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create HttpClientHandler and set UseDefaultCredentials property&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; HttpClientHandler clientHandler = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClientHandler();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; clientHandler.UseDefaultCredentials = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create an HttpClient and add message handlers for the client&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; HttpClient client = HttpClientFactory.Create(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     clientHandler,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client A&amp;quot;&lt;/span&gt;, 2),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client B&amp;quot;&lt;/span&gt;, 4),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client C&amp;quot;&lt;/span&gt;, 6));&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;WebRequestHandler&lt;/h1&gt;

&lt;p&gt;WebRequestHandler derives from HttpClientHandler but adds properties that generally only are available on full .NET. The WebRequestHandler is &lt;strong&gt;not&lt;/strong&gt; included in the System.Net.Http DLL but rather in System.Net.Http.WebRequest DLL so you have to explicitly include that as a reference in order to see it. Otherwise it won’t show up.&lt;/p&gt;

&lt;table border="1" cellspacing="0"&gt;&lt;caption&gt;List of Properties for WebRequestHandler in addition to those of HttpClientHandler&lt;/caption&gt;&lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Name&lt;/th&gt;

      &lt;th&gt;Description&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.allowpipelining(v=vs.110).aspx"&gt;AllowPipelining&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets a value that indicates whether to pipeline the request to the Internet resource. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.authenticationlevel(v=vs.110).aspx"&gt;AuthenticationLevel&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets a value indicating the level of authentication and impersonation used for this request. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.cachepolicy(v=vs.110).aspx"&gt;CachePolicy&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets the cache policy for this request. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.clientcertificates(v=vs.110).aspx"&gt;ClientCertificates&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets the collection of security certificates that are associated with this request. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.continuetimeout(v=vs.110).aspx"&gt;ContinueTimeout&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets the amount of time, in milliseconds, the application will wait for 100-continue from the server before uploading data. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.impersonationlevel(v=vs.110).aspx"&gt;ImpersonationLevel&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets the impersonation level for the current request. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.maxresponseheaderslength(v=vs.110).aspx"&gt;MaxResponseHeadersLength&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets the maximum allowed length of the response headers. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.readwritetimeout(v=vs.110).aspx"&gt;ReadWriteTimeout&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets a time-out in milliseconds when writing a request to or reading a response from a server. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.servercertificatevalidationcallback(v=vs.110).aspx"&gt;ServerCertificateValidationCallback&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt;Gets or sets a callback for verifying the remote Secure Sockets Layer (SSL) certificate used for authentication. &lt;/td&gt;
    &lt;/tr&gt;

    &lt;tr&gt;
      &lt;td&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.net.http.webrequesthandler.unsafeauthenticatedconnectionsharing(v=vs.110).aspx"&gt;UnsafeAuthenticatedConnectionSharing&lt;/a&gt;&lt;/td&gt;

      &lt;td&gt; Gets or sets a value that indicates whether to allow high-speed NTLM-authenticated connection sharing. &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Here’s an example of how to create an WebRequestHandler, set a property, and pass it to HttpClient:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create WebRequestHandler and set UseDefaultCredentials and AllowPipelining (for HTTP) properties&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; WebRequestHandler webRequestHandler = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; WebRequestHandler();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; webRequestHandler.UseDefaultCredentials = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; webRequestHandler.AllowPipelining = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create an HttpClient using the WebRequestHandler&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; HttpClient client = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClient(webRequestHandler);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Again, you can combine the WebRequestHandler with your own handlers as well – here’s what it looks like:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create WebRequestHandler and set UseDefaultCredentials and AllowPipelining (for HTTP) properties&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; WebRequestHandler webRequestHandler = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; WebRequestHandler();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; webRequestHandler.UseDefaultCredentials = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; webRequestHandler.AllowPipelining = &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create an HttpClient and add message handlers for the client&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; HttpClient client = HttpClientFactory.Create(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     webRequestHandler,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client A&amp;quot;&lt;/span&gt;, 2),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client B&amp;quot;&lt;/span&gt;, 4),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SampleHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Client C&amp;quot;&lt;/span&gt;, 6));&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10337522" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item><item><title>Performance Implications of Bundling and Minification on Web Browsing</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/06/17/performance-implications-of-bundling-and-minification-on-http.aspx</link><pubDate>Sat, 16 Jun 2012 23:18:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10321037</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10321037</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/06/17/performance-implications-of-bundling-and-minification-on-http.aspx#comments</comments><description>&lt;p&gt;In this blog we analyze the impact of bundling, &lt;a href="http://en.wikipedia.org/wiki/Minification_(programming)"&gt;minification&lt;/a&gt;, compression, and pipelining on HTTP performance and in particular the impact on traditional browser scenarios. First we look at the impact of bundling and minification on the content in terms of size. Then we look at the impact of bundling and minification on download and page layout times in a browser-style application.&lt;/p&gt;  &lt;p&gt;The purpose is to get a handle on what kind of performance gains can be achieved with a modern HTTP/1.1 implementation when combined with efficient organization of content. The results presented show that only when content and protocol work together is it possible to get significantly faster performance. Just looking at the protocol alone is not sufficient. &lt;/p&gt;  The data analyzed shows that bundling and minification can result in significant savings in terms of bytes exchanged and requests executed and hence lead to faster page render times. Further, by adding compression and pipelining it is possible to get significant speedup in the time it takes to download the HTML, CSS and JS for laying out a page, especially by putting the links to the bundled and minified CSS and JS at the very top of the HTML.&amp;#160; &lt;p&gt;In the test evaluated, the speedup was from 638 ms (uncompressed, unbundled, unminified, and not pipelined) down to 146 ms for the equivalent compressed, bundled, minified, and pipelined content. However, by just looking at the data necessary to lay out the page (HTML, CSS, and JS but not images), the time went from 631 ms to 126 ms with the images being finalized within the remaining timespan from 126 to 146 ms.&lt;/p&gt;  &lt;p&gt;Thanks to &lt;a href="http://codebetter.com/howarddierking/"&gt;Howard Dierking&lt;/a&gt; for help getting the test data and for computing the gains of bundling and minification!&lt;/p&gt;  &lt;h1&gt;Bundling and Minification Impact on Content Size&lt;/h1&gt;  &lt;p&gt;Bundling and minification are two popular (and relatively new) mechanisms for optimizing content used in web pages (see for example these &lt;a href="https://developers.google.com/speed/docs/best-practices/rtt"&gt;guidelines on saving round trip times&lt;/a&gt; (RTT)). Traditionally they focus on optimizing CSS and JS resources but there is no inherent limitation in the general model that prevents it from being used on other content. In this experiment we only looked at saving with respect to CSS and JS but future work could include looking at other content as well.&lt;/p&gt;  &lt;p&gt;The general idea behind bundling is to concatenate multiple files of the same type into a single file hence getting a single large resource rather than a number of small resources. Minification takes bundling one step further by adding model-based compression to the content. In addition to removing white space, minification typically shortens variable names and other identifiers and removes pieces that are not used.&lt;/p&gt;  &lt;p&gt;Bundled and minified content is a resource like any other resource with a URI so no modification of the client side is needed to accommodate bundling or minification. Further, these resources are fully cachable and can be compressed like any other content.&lt;/p&gt;  &lt;p&gt;The bundling and minification we use in this experiment is &lt;a href="http://weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx"&gt;shipping with ASP.NET 4.5&lt;/a&gt;. However, there is nothing particular about that implementation compared to other alternatives and so we think it is possible to get similar benefits from other implementations.&lt;/p&gt;  &lt;h2&gt;How about GZip-style Compression?&lt;/h2&gt;  &lt;p&gt;Compression algorithms like GZip and Deflate are commonly used in HTTP and so we have compared compression with bundling and minification. Note that the two are not mutually exclusive; in fact our data shows that compression works better on a bundled document due to the larger size and hence the opportunity for better compression ratio. For example, for one of the web pages tested with 7 JS and 6 CSS resources, the results of compressing the individual resources vs. compressing the minified bundles were as follows:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="199"&gt;Compressing 7 JS individually&lt;/td&gt;        &lt;td valign="top" width="199"&gt;161178 bytes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="199"&gt;Compressing the minified JS bundle &lt;/td&gt;        &lt;td valign="top" width="199"&gt;137817 bytes&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Similarly for CSS:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="600"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="199"&gt;Compressing 6 CSS individually&lt;/td&gt;        &lt;td valign="top" width="199"&gt;77495 bytes&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="199"&gt;Compressing the minified CSS bundle &lt;/td&gt;        &lt;td valign="top" width="199"&gt;69803 bytes&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;While not something we have investigated, one can imagine that minification also reduces the time it takes to parse the content as there is less data that has to be parsed.&lt;/p&gt;  &lt;p&gt;In addition to the bytes saved in the content, it also saves HTTP overhead in going from 7 to 1 request for JS and 6 to 1 for CSS. This, as we shall see, makes other significant savings possible due to network implications of being able to retrieve the entire bundle in a single request.&lt;/p&gt;  &lt;h2&gt;Bundling and Minification Content Size Results&lt;/h2&gt;  &lt;p&gt;We first looked at data from the following web site home pages to get the difference in size by bundling and minifying the CSS and JS files referenced from those pages. We only looked at CSS and JS coming from the same DNS domain (i.e. for &lt;strong&gt;digg.com&lt;/strong&gt; we looked at anything under &lt;strong&gt;*.digg.com&lt;/strong&gt;. The result is listed below where the last three columns illustrate the percentage saved in terms of bytes and the requests saved by bundling all the CSS into one file and all the JS into another.&lt;/p&gt;  &lt;p&gt;The data shows significant savings in terms of size of CSS and JS as well as number of requests executed. This bundling algorithm may not work in all cases but it should be possible to limit the number of bundles to less than a handful and typically it would be one or two.&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="0" width="600"&gt;&lt;caption&gt;&lt;strong&gt;Analysis of content from various web sites around June 11 2012.&lt;/strong&gt;&lt;/caption&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;url&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;# js&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;# css&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;# imgs&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;js size (kb)&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;css size (kb)&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;image size (kb)&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;css bundle size (kb)&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;css minified size (kb)&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;js bundle size (kb)&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;js minified size (kb)&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;%css savings&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;%js savings&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;Requests saved&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;digg.com&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;7&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;2&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;17&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;512&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;161&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;170&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;162&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;133&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;514&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;235&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;21.80%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;118.72%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;7&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;bbc.co.uk&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;8&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;5&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;31&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;165&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;168&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;492&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;169&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;134&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;166&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;146&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;26.12%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;13.70%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;11&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;bloomberg.com&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;7&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;4&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;29&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;408&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;517&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;273&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;519&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;419&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;410&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;383&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;23.87%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;7.05%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;9&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;huffingtonpost.com&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;7&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;6&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;24&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;568&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;636&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;138&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;638&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;510&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;570&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;456&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;25.10%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;25.00%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;11&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;decor8.com&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;11&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;6&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;69&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;269&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;32.&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;12.9&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;33&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;26&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;270&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;204&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;26.92%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;32.35%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;15&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;cricinfo.com&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;10&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;1&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;14&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;568&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;464&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;73&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;464&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;370&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;571&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;508&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;25.41%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;12.40%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;9&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;p&gt;&lt;b&gt;economictimes.com&lt;/b&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;11&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;1&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;53&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;369&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;94&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;274&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;94&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;76&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;372&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;322&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;23.68%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;15.53%&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top"&gt;         &lt;p&gt;10&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;h1&gt;Bundling and Minification Impact on Download and Page Layout Time&lt;/h1&gt;  &lt;p&gt;In addition to comparing the bundled and minified content with the original content we ran a set of download experiments to evaluate the impact on the HTTP performance and rendering time within a browser. For this experiment we only looked at huffingtonpost.com which we re-created as a local copy so that we could work with the data without it changing under us as the web site gets updated.&lt;/p&gt;  &lt;h2&gt;Page Layout Performance &lt;/h2&gt;  &lt;p&gt;A critical part of being able to measure performance of a web page is the time it takes to layout the page which may be shorter than the time it takes to download the entire content. With modern uses of HTML, there are typically three parts that needs to be downloaded in order for the content to be rendered:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The HTML itself&lt;/li&gt;    &lt;li&gt;CSS resources determining the layout&lt;/li&gt;    &lt;li&gt;JS resources containing scripts to be executed on the page&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Other content such as images are typically not critical for the layout to be completed and can be filled out as data is being downloaded. To get a measure for how quickly a page may be rendered we measured the download time for each of four groups of content: HTML, CSS, JS, and images. We could then determine when the entire content was downloaded vs. when the HTML, CSS, and JS (but not images) were downloaded.&lt;/p&gt;  &lt;h2&gt;How About Pipelining?&lt;/h2&gt;  &lt;p&gt;In the download data presented below we look at both pipelined GET requests and non-pipelined requests (but with persistent TCP connections). In the setup we used (100MBit wireless Ethernet) and even though the RTTs in this environment are very small we did notice a difference between pipelined and non-pipelined requests. However, in any networking environment with larger RTTs being able to submit requests without waiting for a response becomes a necessity. As has been most recently documented in Mark Nottingham’s IETF draft &amp;quot;&lt;a href="http://tools.ietf.org/html/draft-nottingham-http-pipeline-01"&gt;Making HTTP Pipelining Usable on the Open Web&lt;/a&gt;”, there are known problems with practical deployment if pipelining in open network environments. However, it is clear that in order to achieve the best possible performance where RTTs is a factor, it is required to eliminate RTTs aggressively and pipelining can help doing that.&lt;/p&gt;  &lt;h2&gt;Bundling and Minification Download Results&lt;/h2&gt;  &lt;p&gt;The first table shows the total download time for each of the four content categories starting from the point where the first resource (i.e. the HTML page) is requested. That is, the values indicate the times it took to complete the download of all the HTML, CSS, JS, and images respectively counting from the beginning of the very first request asking for the HTML. This means that not all the time is actually used downloading as the CSS, JS, and images only can be initiated once the HTML is being downloaded and links are identified. The times do not include DNS lookups as we used literal IP addresses to connect to the server.&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="600"&gt;&lt;caption&gt;&lt;strong&gt;Total download completing times in ms of various types of content in different configurations.&lt;/strong&gt;&lt;/caption&gt;&lt;thead&gt;     &lt;tr&gt;       &lt;th valign="top" width="100"&gt;Content category&lt;/th&gt;        &lt;th valign="top" width="100"&gt;Plain, no pipeline (4 TCP)&lt;/th&gt;        &lt;th valign="top" width="100"&gt;GZip’ed, no pipeline (4 TCP)&lt;/th&gt;        &lt;th valign="top" width="100"&gt;GZip’ed and pipelined (2 TCP)&lt;/th&gt;        &lt;th valign="top" width="100"&gt;GZip’ed, bundled and minified but no pipeline (4 TCP)&lt;/th&gt;        &lt;th valign="top" width="100"&gt;GZip’ed, pipelined, bundled, and minified (2 TCP)&lt;/th&gt;     &lt;/tr&gt;   &lt;/thead&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top"&gt;HTML&lt;/td&gt;        &lt;td valign="top"&gt;264&lt;/td&gt;        &lt;td valign="top"&gt;49&lt;/td&gt;        &lt;td valign="top"&gt;44&lt;/td&gt;        &lt;td valign="top" width="20%"&gt;45&lt;/td&gt;        &lt;td valign="top"&gt;48&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;CSS&lt;/td&gt;        &lt;td valign="top"&gt;622&lt;/td&gt;        &lt;td valign="top"&gt;162&lt;/td&gt;        &lt;td valign="top"&gt;134&lt;/td&gt;        &lt;td valign="top" width="20%"&gt;97&lt;/td&gt;        &lt;td valign="top"&gt;104&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;JS&lt;/td&gt;        &lt;td valign="top"&gt;631&lt;/td&gt;        &lt;td valign="top"&gt;175&lt;/td&gt;        &lt;td valign="top"&gt;146&lt;/td&gt;        &lt;td valign="top" width="20%"&gt;135&lt;/td&gt;        &lt;td valign="top"&gt;126&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;Images&lt;/td&gt;        &lt;td valign="top"&gt;638&lt;/td&gt;        &lt;td valign="top"&gt;179&lt;/td&gt;        &lt;td valign="top"&gt;150&lt;/td&gt;        &lt;td valign="top" width="20%"&gt;162&lt;/td&gt;        &lt;td valign="top"&gt;146&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The first thing that is apparent is that the download time shrinks from left to right in the table with &lt;strong&gt;plain&lt;/strong&gt; being the slowest with a total download time of 638 ms and &lt;strong&gt;GZip compressed, pipelined, bundled, and minified&lt;/strong&gt; being the fastest with a total download time of 146 ms for the same web page. However, there is more to the data than just the total download time. In the section on page layout we described how getting the HTML, CSS, and JS was critical to laying out the page. &lt;/p&gt;  &lt;p&gt;To better being able to interpret the data we represent it in a set of graphs where the Y axis is total download time in ms for the content of a particular category. Looking at the plain data column, it is apparent that the HTML is done after 264 ms but neither the CSS nor the JS is anywhere near done. In fact, the last parts of the CSS, JS, and images all end roughly at the same time (622, 631, and 638 ms respectively).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/0358.image_5F00_2850D2EC.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4064.image_5F00_thumb_5F00_43892BED.png" width="504" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Below are similar graphs for the other four columns above but we have adjusted the scale of the Y axis to more easily see the differences in detail. Looking at the compressed data, it is clear that even though the download is much faster than plain data, downloading the CSS and JS still takes almost as long as downloading the images (162, 175, and 179 ms respectively). That is, compression does not reorganize the order in which links are referenced within the HTML and hence it is still possible to see a significant delay before the page can be rendered.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6138.image_5F00_472746CA.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/5226.image_5F00_thumb_5F00_46BB13D5.png" width="504" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Turning on HTTP/1.1 pipelining further lowers the total download time, but just like compression, does not alter the location of the links in the HTML, leading to similar data as for compression. That is, the JS is not completely downloaded until the images also have been downloaded (146 vs. 150 ms). The important thing to note here is that without deliberate organization of the content, there is little the protocol can do to optimize the performance. Only when content and protocol work together is it possible to get significantly faster performance.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8875.image_5F00_4244930E.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3482.image_5F00_thumb_5F00_34061A1E.png" width="504" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;With bundling and minification, the picture starts to look different for two reasons: First, the links to the CSS and JS have been put all the way at the top of the HTML so that it the client parser gets to the links very fast and can submit them to the server. In the original content, the first CSS link was found at byte offset 2213 within the HTML and the first JS link was found at byte offset 3730. By moving these links to the very beginning they could be initiated earlier. &lt;/p&gt;  &lt;p&gt;Second, with the fewer requests there is also less protocol overhead and less interruption of parsing the data. The result is that the CSS and JS are completely downloaded after 135 ms, allowing the page to be rendered while the remaining images are still being loaded. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4571.image_5F00_137EDA6C.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/1854.image_5F00_thumb_5F00_3A4CF0AC.png" width="504" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Lastly, we tried the full suite of compressed, pipelined, bundled, and minified content. Even with the low RTT we did observe a difference in lower times to download the content and it produced the fastest time of 146 for downloading the images and only 126 to download the JS and hence being able to layout the page,&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/1030.image_5F00_72F79AB9.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="image" border="0" alt="image" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4064.image_5F00_thumb_5F00_19C5B0FA.png" width="504" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;Summary&lt;/h1&gt;  &lt;p&gt;Bundling and minification can result in significant savings in terms of bytes to exchange and requests necessary to execute and hence lead to faster page render times. In addition, by applying compression and pipelining to bundling and minification it is possible to get significant speedup in the time it takes to download the HTML, CSS and JS for laying out a page, especially by putting the links to the bundled and minified CSS and JS at the very top of the HTML. In short, only when content and protocol work together is it possible to get significantly faster performance. Just looking at the protocol alone is not sufficient. &lt;/p&gt;  &lt;p&gt;In the test evaluated, the speedup was from 638 ms in plain mode down to 146 ms for the equivalent compressed, pipelined, bundled and minified content. However, by just looking at the data necessary to lay out the page (HTML, CSS, and JS but not images), the time went from 631 ms to 126 ms with the images being finalized within the remaining timespan from 126 to 146 ms.&lt;/p&gt;  &lt;h1&gt;Practical Advice for Page Designers&lt;/h1&gt;  &lt;p&gt;Here’s a short list of the possible optimizations that we observed:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Bundle and minify CSS and JS resources.&lt;/strong&gt; This saves both rendering time and reduces bandwidth consumption.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Add references to the CSS and JS bundles as close to the top of the HTML page as possible.&lt;/strong&gt; Many HTML pages have a huge header containing several kByte of metadata before links referencing CSS and JS which takes time to parse through and costs valuable time before subsequent HTTP requests can be initiated.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Ensure that both the HTML and the CSS and JavaScript bundles use compression if supported by the client.&lt;/strong&gt; It will further reduce the bandwidth and speed up getting the data to the client.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;These parts will in combination with an efficient browser implementation leveraging compression and pipelining provide a much faster rendering time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10321037" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category></item><item><title>ASP.NET MVC, Web API, and Web Pages RC NuGet Packages</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/06/01/asp-net-mvc-web-api-and-web-pages-nuget-packages.aspx</link><pubDate>Fri, 01 Jun 2012 18:52:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10313697</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>12</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10313697</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/06/01/asp-net-mvc-web-api-and-web-pages-nuget-packages.aspx#comments</comments><description>&lt;p&gt;The official ASP.NET Web Stack RC NuGet packages are now available on &lt;a href="http://nuget.org"&gt;NuGet&lt;/a&gt;. If you are new to &lt;a href="http://nuget.org/"&gt;NuGet&lt;/a&gt; then it is a Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects (check out the &lt;a href="http://docs.nuget.org/docs/start-here/overview"&gt;NuGet overview&lt;/a&gt;).&lt;/p&gt;  &lt;h1&gt;NuGet Packages&lt;/h1&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://nuget.org/packages/Microsoft.AspNet.WebApi"&gt;Microsoft ASP.NET Web API (RC)&lt;/a&gt; -- this package contains everything you need to host ASP.NET Web API on IIS.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://nuget.org/packages/Microsoft.AspNet.WebApi.SelfHost"&gt;Microsoft ASP.NET Web API Self Host (RC)&lt;/a&gt; -- this package contains everything you need to host ASP.NET Web API within your own process (outside of IIS).&lt;/li&gt;    &lt;li&gt;&lt;a href="http://nuget.org/packages/Microsoft.AspNet.WebApi.Client"&gt;Microsoft ASP.NET Web API Client Libraries (RC)&lt;/a&gt; -- this package adds support for formatting and content negotiation to System.Net.Http. It includes support for JSON, XML, and form URL encoded data.&lt;/li&gt;    &lt;li&gt;&lt;a href="https://nuget.org/packages/Microsoft.AspNet.Mvc/4.0.20505.0"&gt;Microsoft ASP.NET MVC 4 (RC)&lt;/a&gt; -- this package contains the runtime assemblies for ASP.NET MVC.&lt;/li&gt;    &lt;li&gt;&lt;a href="https://nuget.org/packages/Microsoft.AspNet.Razor/2.0.20505.0"&gt;Microsoft ASP.NET Razor 2 (RC)&lt;/a&gt; -- this package contains the runtime assemblies for ASP.NET Web Pages.&lt;/li&gt;  &lt;/ol&gt;  &lt;p&gt;If you are interested in using the latest nightly builds instead then please &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/06/01/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx"&gt;check out this description&lt;/a&gt; for how to get set up.&lt;/p&gt;  &lt;h1&gt;NuGet Package Tags&lt;/h1&gt;  &lt;p&gt;When searching for a package on &lt;a href="http://nuget.org"&gt;NuGet&lt;/a&gt; it is convenient to use tags for your query. Here are some convenient tags for the ASP.NET Web Stack packages:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://nuget.org/packages?q=AspNetWebApi"&gt;AspNetWebApi&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://nuget.org/packages?q=AspNetMvc"&gt;AspNetMvc&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://nuget.org/packages?q=AspNetWebPages"&gt;AspNetWebPages&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://nuget.org/packages?q=HttpClient"&gt;HttpClient&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;h1&gt;Additional Information&lt;/h1&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.asp.net/whitepapers/mvc4-release-notes"&gt;Release Notes for RC&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2012/04/14/april-14th-links-asp-net-asp-net-mvc-net-and-nuget.aspx"&gt;Useful links&lt;/a&gt; with blogs, additional information, etc.&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:06e015ec-c087-483c-a1e3-e74ac04507be" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/aspnetwebapi" rel="tag"&gt;aspnetwebapi&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10313697" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/Razor/">Razor</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/MVC/">MVC</category></item><item><title>Using Nightly ASP.NET Web Stack NuGet Packages with Visual Studio 2012</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/06/01/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx</link><pubDate>Fri, 01 Jun 2012 06:28:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10313130</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10313130</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/06/01/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;Note: this blog uses Visual Studio 2012 but the instructions for VS 2010 are the same.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;This blog describes using the nightly NuGet packages with &lt;a href="http://www.microsoft.com/visualstudio/11"&gt;Visual Studio 2012&lt;/a&gt;. Note well that the packages come with &lt;strong&gt;no guarantees&lt;/strong&gt; and they do not substitute for the &lt;a href="http://www.asp.net/web-api"&gt;official installers&lt;/a&gt; which contain the official MSI and NuGet packages. And of course, don’t use your dev machine for anything important.&lt;/p&gt;  &lt;h1&gt;Prerequisites: Visual Studio 2012 and GacUtil&lt;/h1&gt;  &lt;p&gt;In contrast to &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;compiling the code yourself&lt;/a&gt;, it is possible to use the nightly NuGets with &lt;a href="http://www.microsoft.com/visualstudio/11" target="_blank"&gt;Visual Studio 2012&lt;/a&gt; installed so that you can use the project templates. &lt;/p&gt;  &lt;p&gt;As Web API is &lt;strong&gt;not&lt;/strong&gt; in the GAC it is very simple to update – just get the nightly NuGets and you are done. For &lt;strong&gt;MVC&lt;/strong&gt; and &lt;strong&gt;Web Pages&lt;/strong&gt; you still need to work with the &lt;a href="http://msdn.microsoft.com/en-us/library/yf1d93sz.aspx"&gt;Global Assembly Cache (GAC)&lt;/a&gt; so you do need the &lt;a href="http://msdn.microsoft.com/en-us/library/ex0ss12c.aspx"&gt;GacUtil tool&lt;/a&gt; for updating assemblies in the GAC.&lt;/p&gt;  &lt;h1&gt;Configuring NuGet&lt;/h1&gt;  &lt;p&gt;In order to see the nightly packages you first need to configure Visual Studio to point to the MyGet feed at&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.myget.org/F/aspnetwebstacknightly/"&gt;http://www.myget.org/F/aspnetwebstacknightly/&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Under the &lt;strong&gt;Visual Studio Tools menu&lt;/strong&gt; select &lt;strong&gt;Options&lt;/strong&gt; and then &lt;strong&gt;Package Manager&lt;/strong&gt; and add the feed – it should look like this: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7853.UpdateFeedSource3_5F00_0B2FCACC.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="UpdateFeedSource3" border="0" alt="UpdateFeedSource3" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6866.UpdateFeedSource3_5F00_thumb_5F00_26D456C2.png" width="604" height="352" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;Updating an ASP.NET MVC4 Web Application Project&lt;/h1&gt;  &lt;p&gt;Assume we have an &lt;strong&gt;ASP.NET MVC4 Web Application&lt;/strong&gt; Visual Studio project (below we created a Web API but it should work for any of the project variants). Under the &lt;strong&gt;Visual Studio Project menu&lt;/strong&gt;, select &lt;strong&gt;Manage NuGet Packages&lt;/strong&gt;, then select &lt;strong&gt;Updates&lt;/strong&gt; from the MyGet feed you just added, and then select &lt;strong&gt;Include Prerelease&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/5383.PrereleasePackages_5F00_1FB51A4A.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="PrereleasePackages" border="0" alt="PrereleasePackages" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/5315.PrereleasePackages_5F00_thumb_5F00_0D6C5388.png" width="604" height="432" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Install the updates and close the window.&lt;/p&gt;  &lt;h1&gt;Updating the GAC&lt;/h1&gt;  &lt;p&gt;For Web API you are all set – nothing else is needed! However, if you are using MVC or Web Pages then before you can run the project you have to update the GAC with the new assemblies which NuGet downloaded and stuck in the &lt;strong&gt;packages&lt;/strong&gt; folder which you can find in your solutions folder. You can get a view of the assembles by typing the following in the packages folder&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;dir /s /b *.dll&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;It should look something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4300.PackageAssemblies2_5F00_656BEBD8.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="PackageAssemblies2" border="0" alt="PackageAssemblies2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3632.PackageAssemblies2_5F00_thumb_5F00_33081859.png" width="604" height="312" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The list below is the set of DLLs that are GAC’ed in VS 2012. Look for the assemblies on the list below and match them against the directory list above. Depending on which project variant you picked you may not have all of them – that’s ok. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;System.Web.Mvc&lt;/li&gt;    &lt;li&gt;System.Web.Razor&lt;/li&gt;    &lt;li&gt;System.Web.Helpers&lt;/li&gt;    &lt;li&gt;System.Web.WebPages.Deployment&lt;/li&gt;    &lt;li&gt;System.Web.WebPages&lt;/li&gt;    &lt;li&gt;System.Web.WebPages.Razor&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For each of the assemblies that match the GAC’ed list install them in the GAC using GacUtil (running as Administrator) like this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;GacUtil.exe -i &amp;lt;path to assembly in your packages folder&amp;gt;&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;For example, &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4705.GacUtil_5F00_thumb8_5F00_4B2B82B4.png"&gt;&lt;img style="border: 0px currentcolor; display: inline; background-image: none;" title="GacUtil_thumb8" border="0" alt="GacUtil_thumb8" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6036.GacUtil_5F00_thumb8_5F00_thumb_5F00_03D62CC2.png" width="604" height="56" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;Trying It Out&lt;/h1&gt;  &lt;p&gt;You are now ready to run your application. When running in the Visual Studio debugger you can verify that you use the new assemblies by looking at the &lt;strong&gt;Modules&lt;/strong&gt; window available under the &lt;strong&gt;Visual Studio Debug&lt;/strong&gt; menu. It should look something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6036.Modules2_5F00_5C9BE38C.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="Modules2" border="0" alt="Modules2" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8400.Modules2_5F00_thumb_5F00_692990A8.png" width="604" height="429" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The version numbers should correspond to the numbers used to name the folders under the &lt;strong&gt;packages&lt;/strong&gt; folder we looked at above.&lt;/p&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:aadcb8ca-c066-4402-8fa3-2b1a6100af5f" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/Asp.net" rel="tag"&gt;Asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/codeplex" rel="tag"&gt;codeplex&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10313130" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>ASP.NET Web API Updates – May 14</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/05/14/asp-net-web-api-updates-may-14.aspx</link><pubDate>Mon, 14 May 2012 00:30:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10304709</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10304709</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/05/14/asp-net-web-api-updates-may-14.aspx#comments</comments><description>&lt;p&gt;We have been on a roll with respect to changes over the last few weeks – here’s some of the highlights. If you want to see the full list then you can either &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/list/changesets"&gt;track the commit page&lt;/a&gt; or &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;follow the project&lt;/a&gt; which will then show you the updates on your &lt;a href="http://www.codeplex.com/"&gt;codeplex home page&lt;/a&gt;. As in the &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/27/asp-net-web-api-updates-april-27.aspx"&gt;previous update&lt;/a&gt; this is a sneak-peak of code checked into our &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;CodePlex source code repository&lt;/a&gt; but not yet released as part of our &lt;a href="http://www.asp.net/web-api"&gt;official installer&lt;/a&gt;. See &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/29/using-nightly-nuget-packages-with-asp-net-web-stack.aspx"&gt;Using Nightly ASP.NET Web Stack NuGet Packages&lt;/a&gt; for how to try out these features.&lt;/p&gt;  &lt;h1&gt;Per Controller Type Configuration&lt;/h1&gt;  &lt;p&gt;ASP.NET Web API has a &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Web.Http%2fHttpConfiguration.cs" target="_blank"&gt;HttpConfiguration&lt;/a&gt; object that provides configuration for features including routing, dependency resolution, media type formatters, and message handlers. However, while the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Web.Http%2fHttpConfiguration.cs" target="_blank"&gt;HttpConfiguration&lt;/a&gt; allows you to configure most aspects of ASP.NET Web API, it does not allow different configurations per controller type.&amp;#160; This feature changes that in that we have added &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/fcfc9f49f96a"&gt;per-controller-type configuration&lt;/a&gt;. In essence, a controller type can have its own “shadow copy” of the global &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Web.Http%2fHttpConfiguration.cs" target="_blank"&gt;HttpConfiguration&lt;/a&gt; object but override specific settings that only applies to that controller type. This is automatically applied to all controller instances of the given controller-type.&lt;/p&gt;  &lt;p&gt;Mike Stall &lt;a href="http://blogs.msdn.com/b/jmstall/archive/2012/05/11/per-controller-configuration-in-webapi.aspx" target="_blank"&gt;has a great blog about the feature&lt;/a&gt; in detail including examples of how to use it with an ApiController so check it out – this is an exciting feature!&lt;/p&gt;  &lt;h1&gt;Content Negotiated Error Messages&lt;/h1&gt;  &lt;p&gt;We have unified the generation of error messages regardless of whether they are generated as part of a normal message flow, as part of an exception path, or as part of model state validation. This means that regardless of how you generate a 4xx or 5xx status code, the result will be a uniform, content negotiated message, making it easier to handle by clients.&lt;/p&gt;  &lt;p&gt;For example, you can generate a 409 Conflict response like this:&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Contact Get()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     HttpResponseMessage response = Request.CreateErrorResponse(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         HttpStatusCode.Conflict, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Check out this message!&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseException(response);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;or like this: &lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; HttpResponseMessage Get(HttpRequestMessage request)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     HttpResponseMessage response = request.CreateErrorResponse(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         HttpStatusCode.Conflict, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Check out this message!&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; response;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In either case, the response will look like this in Fiddler if you ask for “text/json”:&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2337.409Conflict_5F00_543B7126.png"&gt;&lt;img style="display: inline; background-image: none;" title="409Conflict" border="0" alt="409Conflict" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3733.409Conflict_5F00_thumb_5F00_61A1842C.png" width="604" height="449" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; By default the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8ff0d2799efc#src%2fSystem.Web.Http%2fHttpConfiguration.cs" target="_blank"&gt;HttpConfiguration&lt;/a&gt;.IncludeErrorDetailPolicy setting only exposes a generic message to external users so that we inadvertently leak internal information.&lt;/p&gt;

&lt;h1&gt;Content Negotiation Improvements&lt;/h1&gt;

&lt;p&gt;Lastly, we re-organized the content negotiation code to all be gathered in our &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Net.Http.Formatting%2fFormatting%2fDefaultContentNegotiator.cs"&gt;DefaultContentNegotiator&lt;/a&gt; class. The content negotiation is fully pluggable so that if you want to roll your own then you can implement the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Net.Http.Formatting%2fFormatting%2fIContentNegotiator.cs" target="_blank"&gt;IContentNegotiator&lt;/a&gt; interface and hook it in through the configuration. However, now you can also just derive from &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Net.Http.Formatting%2fFormatting%2fDefaultContentNegotiator.cs"&gt;DefaultContentNegotiator&lt;/a&gt; and pretty much override any aspect that you like instead of starting from scratch. For a full description, please &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/640a43cbaeb4" target="_blank"&gt;see this commit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In addition we added support for &lt;strong&gt;not&lt;/strong&gt; picking accept header values with a quality factor of 0.0. Before we treated this as a small but possible match while now we completely filter them out of the picture. That is, if you send something like “Accept: text/xml; q=0.0” then you won’t get it. &lt;/p&gt;

&lt;p&gt;We also added a hook so that it is possible to create an instance of the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Net.Http.Formatting%2fFormatting%2fDefaultContentNegotiator.cs"&gt;DefaultContentNegotiator&lt;/a&gt; that returns null if none of the accept header values were matched. This makes it possible to inject your own &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Net.Http.Formatting%2fFormatting%2fDefaultContentNegotiator.cs"&gt;DefaultContentNegotiator&lt;/a&gt; instance (in &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Web.Http%2fHttpConfiguration.cs" target="_blank"&gt;HttpConfiguration.Services&lt;/a&gt;) that is suited for generating 406 responses if no match on accept headers were found.&lt;/p&gt;

&lt;p&gt;This sample shows a simple self host which hooks in a special &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/bea0a11bc6b4#src%2fSystem.Net.Http.Formatting%2fFormatting%2fDefaultContentNegotiator.cs"&gt;DefaultContentNegotiator&lt;/a&gt; instance set to return null if not matching on any Accept header field in the request:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; baseAddress = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080/&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; HttpSelfHostConfiguration config = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostConfiguration(baseAddress);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; DefaultContentNegotiator negotiator = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; DefaultContentNegotiator(excludeMatchOnTypeOnly: &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; config.Services.Replace(&lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;(IContentNegotiator), negotiator);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Add a route&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt; config.Routes.MapHttpRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;   name: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;defaultAction&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;   routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;api/{controller}/{action}/{id}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;   defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { controller = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;, id = RouteParameter.Optional });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt; config.Routes.MapHttpRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;   name: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;default&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;   routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;api/{controller}/{id}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;   defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { controller = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;, id = RouteParameter.Optional });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt; HttpSelfHostServer server = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostServer(config);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt; server.OpenAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt; Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Listening on &amp;quot;&lt;/span&gt; + baseAddress);&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We should now see a 406 Not Acceptable response if there is no matching Accept header field so let’s try it out in Fiddler with no Accept header at all:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6064.ContentNegotiationNotAcceptable_5F00_7311E504.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="ContentNegotiationNotAcceptable" border="0" alt="ContentNegotiationNotAcceptable" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3312.ContentNegotiationNotAcceptable_5F00_thumb_5F00_07973483.png" width="604" height="449" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And indeed there is a 406 response. If we add an Accept header then we get a 200 response like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2251.ContentNegotiationAcceptable_5F00_000BC516.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="ContentNegotiationAcceptable" border="0" alt="ContentNegotiationAcceptable" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4478.ContentNegotiationAcceptable_5F00_thumb_5F00_117C25EE.png" width="604" height="449" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Have fun!&lt;/h1&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9ff8facf-6cba-43b6-8dd0-70a6f263d4bd" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/httpclient" rel="tag"&gt;httpclient&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10304709" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>ASP.NET Web API Updates – May 3</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/05/03/asp-net-web-api-updates-may-3.aspx</link><pubDate>Thu, 03 May 2012 22:05:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10300643</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10300643</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/05/03/asp-net-web-api-updates-may-3.aspx#comments</comments><description>&lt;p&gt;Some interesting updates were checked in over the last week. As in the &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/27/asp-net-web-api-updates-april-27.aspx"&gt;previous update&lt;/a&gt; this is a sneak-peak of code checked into our &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;CodePlex source code repository&lt;/a&gt; but hasn’t yet been released as part of our &lt;a href="http://www.asp.net/web-api"&gt;official installer&lt;/a&gt;. See &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/29/using-nightly-nuget-packages-with-asp-net-web-stack.aspx"&gt;Using Nightly ASP.NET Web Stack NuGet Packages&lt;/a&gt; for how to try out these features.&lt;/p&gt;  &lt;h1&gt;Per-Route Message Handlers&lt;/h1&gt;  &lt;p&gt;Support for &lt;a href="http://aspnetwebstack.codeplex.com/workitem/52"&gt;per-route message handlers&lt;/a&gt; has been a popular request on our &lt;a href="http://aspnetwebstack.codeplex.com/workitem/list/basic"&gt;issues list&lt;/a&gt;. The issue is that HttpMessageHandlers is a flexible extensibility point for dealing with HTTP requests and responses but they are configured once per application within the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f59892797e46#src%2fSystem.Web.Http%2fHttpConfiguration.cs"&gt;HttpConfiguration&lt;/a&gt;. In some scenarios you have different needs for different services so a more flexible registration is needed.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://bradwilson.typepad.com/"&gt;Brad Wilson&lt;/a&gt; describes the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/f59892797e46"&gt;per-route message handler feature&lt;/a&gt; thusly: The implementation of this feature allows users to specify the &amp;quot;final&amp;quot; message handler in the request chain for a given route. This will enable two scenarios:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Support for adding message handlers on a per-route basis.&lt;/li&gt;    &lt;li&gt;Allow “ride-along” frameworks to use routing to dispatch to their own (non-&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f59892797e46#src%2fSystem.Web.Http%2fControllers%2fIHttpController.cs"&gt;IHttpController&lt;/a&gt;) endpoints.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;To illustrate the change in the pipeline, this is what the pipeline looked like before this change:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8561.OldPipeline_5F00_5CAB72F9.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="OldPipeline" border="0" alt="OldPipeline" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8154.OldPipeline_5F00_thumb_5F00_15561D07.png" width="300" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The old HttpControllerDispatcher was in charge of &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Routing lookup (if not already done)&lt;/li&gt;    &lt;li&gt;Generating a 404 when no routes match&lt;/li&gt;    &lt;li&gt;Generate a 404 when no controllers match&lt;/li&gt;    &lt;li&gt;Dispatch to IHttpController&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In the new pipeline we have split this into two handlers like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7870.NewPipeline_5F00_1C09268A.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="NewPipeline" border="0" alt="NewPipeline" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2605.NewPipeline_5F00_thumb_5F00_06AB7122.png" width="300" height="421" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The new responsibilities are as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f59892797e46#src%2fSystem.Web.Http%2fDispatcher%2fHttpRoutingDispatcher.cs"&gt;HttpRoutingDispatcher&lt;/a&gt; &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Routing lookup (if not already done)&lt;/li&gt;    &lt;li&gt;Generating a 404 when no routes match&lt;/li&gt;    &lt;li&gt;     &lt;div align="left"&gt;Dispatch to &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f59892797e46#src%2fSystem.Web.Http%2fRouting%2fIHttpRoute.cs"&gt;IHttpRoute&lt;/a&gt;.Handler (HttpControllerDispatcher by default when null)&lt;/div&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f59892797e46#src%2fSystem.Web.Http%2fDispatcher%2fHttpControllerDispatcher.cs"&gt;HttpControllerDispatcher&lt;/a&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Generating a 404 when no controllers match&lt;/li&gt;    &lt;li&gt;Dispatch to IHttpController&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;What this means in practical terms is that, if you want to provide one or more message handlers on a per-route basis, those message handlers will have to run after routing has run (so, basically last), and if you want to preserve the dispatching to controllers, your final handler must delegate to &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f59892797e46#src%2fSystem.Web.Http%2fDispatcher%2fHttpControllerDispatcher.cs"&gt;HttpControllerDispatcher&lt;/a&gt;. To generate a message handler pipeline you can use the &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/27/asp-net-web-api-updates-april-27.aspx"&gt;HttpClientFactory as described in the previous update&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;As an example of how to use this, we introduce a simple “hello world” message handler that simply responds with a static HTTP response like this:&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; HelloWorldMessageHandler : HttpMessageHandler&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; SendAsync(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;         HttpRequestMessage request,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         CancellationToken cancellationToken)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         var response = request.CreateResponse(HttpStatusCode.OK, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Hello, world!&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         var tcs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; TaskCompletionSource&amp;lt;HttpResponseMessage&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         tcs.SetResult(response);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; tcs.Task;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We can now hook it in by adding a route with the new handler – in this case we use a self-host snippet:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Program&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {    &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         var config = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostConfiguration(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080/&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         IHttpRoute route = config.Routes.CreateRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;             routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;hello&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;             defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpRouteValueDictionary(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;route&amp;quot;&lt;/span&gt;),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;             constraints: &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;             dataTokens: &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;             parameters: &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;             handler: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HelloWorldMessageHandler());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         config.Routes.Add(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;HelloRoute&amp;quot;&lt;/span&gt;, route);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         config.Routes.MapHttpRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;           name: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;default&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;           routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;api/{controller}/{id}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;           defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { controller = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;, id = RouteParameter.Optional });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;         &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         var server = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostServer(config);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         server.OpenAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Listening on {0}...&amp;quot;&lt;/span&gt;, config.BaseAddress);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         Console.ReadLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;         server.CloseAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;If you now access &lt;strong&gt;http://localhost:8080/hello&lt;/strong&gt; you will get the response from HelloWorldMessageHandler and for requests under &lt;strong&gt;http://localhost:8080/api/*&lt;/strong&gt; you will get the regular Web API controllers. Because message handlers can be chained you can also insert the default &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f59892797e46#src%2fSystem.Web.Http%2fDispatcher%2fHttpControllerDispatcher.cs"&gt;HttpControllerDispatcher&lt;/a&gt; at the end – the opportunities are endless!&lt;/p&gt;

&lt;h1&gt;Reading Form Data&lt;/h1&gt;

&lt;p&gt;In addition to doing model binding in your &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/f59892797e46#src%2fSystem.Web.Http%2fApiController.cs"&gt;ApiController&lt;/a&gt; actions where you get the form data directly as part of your action signature, you can parse form data throughout Web API (both client side and server side). Two common ways to get form data is either as a &lt;a href="http://msdn.microsoft.com/en-us/library/System.Collections.Specialized.NameValueCollection.aspx"&gt;NameValueCollection&lt;/a&gt; or as a &lt;a href="http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_Linq_JToken.htm"&gt;JToken&lt;/a&gt; which is the &lt;a href="http://json.codeplex.com/"&gt;Json.NET&lt;/a&gt; LINQ to JSON data model. &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/bc62072118a6"&gt;This commit&lt;/a&gt; rounds out the functionality by providing equal support for reading form data from a URI or from the body of an HTTP message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reading as NameValueCollection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can read the query component of a URI as a &lt;a href="http://msdn.microsoft.com/en-us/library/System.Collections.Specialized.NameValueCollection.aspx"&gt;NameValueCollection&lt;/a&gt; doing something like this (first line creates some sample content and the second line reads it):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    Uri address = &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;&amp;quot;http://example.com/path?a[]=1&amp;amp;a[]=5&amp;amp;a[]=333&amp;quot;&lt;/span&gt;);
    NameValueCollection nvcUri = address.ParseQueryString();&lt;/pre&gt;
Similarly you can read HTML form URL encoded data from an HttpContent which can be part of an HttpRequestMessage or HttpResponseMessage like this (first line creates some sample content and the second line reads it):

&lt;pre class="csharpcode"&gt;    StringContent content = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringContent(&lt;span class="str"&gt;&amp;quot;a[]=1&amp;amp;a[]=5&amp;amp;a[]=333&amp;quot;&lt;/span&gt;,&lt;br /&gt;        Encoding.UTF8, &lt;span class="str"&gt;&amp;quot;application/x-www-form-urlencoded&amp;quot;&lt;/span&gt;);
    NameValueCollection nvcContent = content.ReadAsFormDataAsync().Result;&lt;/pre&gt;


&lt;p&gt;In both cases will you get a NameValueCollection with one key (“a”) and three values (“1”, “5”, and “333”).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reading as JObject&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also read the query component of a URI as a &lt;a href="http://james.newtonking.com/projects/json/help/html/T_Newtonsoft_Json_Linq_JToken.htm"&gt;JToken&lt;/a&gt; which is the &lt;a href="http://json.codeplex.com/"&gt;Json.NET&lt;/a&gt; LINQ to JSON data model (we use the same sample URI as above):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    JObject jObjectUri;
    address.TryReadQueryAsJson(&lt;span class="kwrd"&gt;out&lt;/span&gt; jObjectUri);&lt;/pre&gt;


&lt;p&gt;Similar you can read the HTML form URL encoded data from an HttpContent as JObject like this (we use the same sample content as above):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    JObject jObjectContent = content.ReadAsAsync&amp;lt;JObject&amp;gt;().Result;
&lt;/pre&gt;

&lt;p&gt;In both cases will you get a JObject which you can use to traverse the data as you wish.&lt;/p&gt;


&lt;h1&gt;Accepted Pull Requests&lt;/h1&gt;

&lt;p&gt;Finally we have accepted a set of pull requests – thanks for the contributions!&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Andre Azevedo: &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/network/forks/andreazevedo/UnitTests/contribution/2066"&gt;Correct unit tests by replacing culture&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Patrick McDonald: &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/network/forks/PatrickMcDonald/aspnetwebstack/contribution/2051"&gt;Modified System.Web.Mvc.RouteCollectionExtensions.MapRoute to work with dictionary defaults and/or constraints&lt;/a&gt;&lt;/li&gt;

  &lt;li&gt;Patrick McDonald: &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/2c6f4008ed98"&gt;Fixed RouteCollectionExtensions.MapRoute to work when defaults and constraints are dictionaries, currently method only works with anonymous types or similar&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:60bb7c13-f989-4789-98a5-c13f35bbcadf" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/httpclient" rel="tag"&gt;httpclient&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10300643" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>Using Nightly ASP.NET Web Stack NuGet Packages</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/04/29/using-nightly-nuget-packages-with-asp-net-web-stack.aspx</link><pubDate>Sun, 29 Apr 2012 18:25:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10298886</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>10</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10298886</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/04/29/using-nightly-nuget-packages-with-asp-net-web-stack.aspx#comments</comments><description>&lt;p&gt;&lt;strong&gt;Note: This blog has been &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/06/01/using-nightly-asp-net-web-stack-nuget-packages-with-vs-2012-rc.aspx"&gt;superseded by this one&lt;/a&gt; – the instructions for Visual Studio 2012 and 2010 are the same.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We are very excited about the &lt;a href="http://aspnetwebstack.codeplex.com/discussions/353867"&gt;recent announcement&lt;/a&gt; of nightly NuGet packages being available on &lt;a href="http://www.myget.org/"&gt;MyGet&lt;/a&gt;. This blog will show using these packages with Visual Studio 2010 but first you should be aware of the &lt;a href="http://aspnetwebstack.codeplex.com/discussions/353867"&gt;disclaimers&lt;/a&gt;. In short, these packages come with no guarantees and they do not substitute for the &lt;a href="http://www.asp.net/web-api"&gt;official installers&lt;/a&gt; which contain the official MSI and NuGet packages. And of course, don’t use your dev machine for anything important.&lt;/p&gt;  &lt;h1&gt;Prerequisites: Visual Studio 2010 and GacUtil&lt;/h1&gt;  &lt;p&gt;In contrast to &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;compiling the code yourself&lt;/a&gt;, it is possible to use the nightly NuGets with &lt;a href="http://go.microsoft.com/fwlink/?LinkId=243392"&gt;ASP.NET MVC 4 Beta for Visual Studio 2010&lt;/a&gt; installed so that you can use the project templates. The instructions here are for&lt;strong&gt; .NET 4.0 and Visual Studio 2010 only&lt;/strong&gt; – it won’t work with Dev 11 Beta due to a conflict in System.Net.Http. Also, you do need to work with the &lt;a href="http://msdn.microsoft.com/en-us/library/yf1d93sz.aspx"&gt;Global Assembly Cache (GAC)&lt;/a&gt; so you do need the &lt;a href="http://msdn.microsoft.com/en-us/library/ex0ss12c.aspx"&gt;GacUtil tool&lt;/a&gt; for updating assemblies in the GAC.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; In &lt;a href="http://go.microsoft.com/fwlink/?LinkId=243392"&gt;ASP.NET MVC 4 Beta for Visual Studio 2010&lt;/a&gt; we GAC’ed more than necessary and so when updating the NuGet packages you have to update the GAC as well as the GAC always wins when resolving assembly references. In the next official drop we GAC a lot less so much of this will go away.&lt;/p&gt;  &lt;h1&gt;Configuring NuGet&lt;/h1&gt;  &lt;p&gt;In order to see the nightly packages you first need to configure Visual Studio to point to the MyGet feed at&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.myget.org/F/aspnetwebstacknightly/"&gt;http://www.myget.org/F/aspnetwebstacknightly/&lt;/a&gt;&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;Under the &lt;strong&gt;Visual Studio Tools menu&lt;/strong&gt; select &lt;strong&gt;Options&lt;/strong&gt; and then &lt;strong&gt;Package Manager&lt;/strong&gt; and add the feed – it should look like this: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4861.UpdateFeedSource_5F00_03ADD5B1.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="UpdateFeedSource" border="0" alt="UpdateFeedSource" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3872.UpdateFeedSource_5F00_thumb_5F00_708CA904.png" width="604" height="354" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;Updating an ASP.NET MVC4 Web Application Project&lt;/h1&gt;  &lt;p&gt;Assume we have an &lt;strong&gt;ASP.NET MVC4 Web Application&lt;/strong&gt; Visual Studio project (below we created a Web API but it should work for any of the project variants). Now, under the &lt;strong&gt;Visual Studio Project menu&lt;/strong&gt;, select &lt;strong&gt;Manage NuGet Packages&lt;/strong&gt; and select Updates from the MyGet feed you just added:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3060.UpdatePackages_5F00_091C4655.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="UpdatePackages" border="0" alt="UpdatePackages" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2705.UpdatePackages_5F00_thumb_5F00_13D99DAA.png" width="604" height="404" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Install the updates and close the window.&lt;/p&gt;  &lt;h1&gt;Updating the GAC&lt;/h1&gt;  &lt;p&gt;Before you can run the project you have to update the GAC with the new assemblies which NuGet downloaded and stuck in the &lt;strong&gt;packages&lt;/strong&gt; folder which you can find in your solutions folder. You can get a view of the assembles by typing the following in the packages folder&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;dir /s /b *.dll&lt;/strong&gt;&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;It should look something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4530.PackageAssemblies_5F00_136D6AB5.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="PackageAssemblies" border="0" alt="PackageAssemblies" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3750.PackageAssemblies_5F00_thumb_5F00_20D37DBB.png" width="604" height="306" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The list below is the set of DLLs we GAC’ed in &lt;a href="http://go.microsoft.com/fwlink/?LinkId=243392"&gt;ASP.NET MVC 4 Beta for Visual Studio 2010.&lt;/a&gt; Moving forward we are GAC’ing a lot less so this will get much easier. Look for the assemblies on the list below and match them against the directory list above. Depending on which project variant you picked you may not have all of them – that’s ok. &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;System.Web.Mvc&lt;/li&gt;    &lt;li&gt;System.Web.Razor&lt;/li&gt;    &lt;li&gt;System.Net.Http.Formatting&lt;/li&gt;    &lt;li&gt;System.Web.Http&lt;/li&gt;    &lt;li&gt;System.Web.Http.WebHost&lt;/li&gt;    &lt;li&gt;System.Web.Helpers&lt;/li&gt;    &lt;li&gt;System.Web.WebPages.Deployment&lt;/li&gt;    &lt;li&gt;System.Web.WebPages&lt;/li&gt;    &lt;li&gt;System.Web.WebPages.Razor&lt;/li&gt;    &lt;li&gt;System.Net.Http&lt;/li&gt;    &lt;li&gt;System.Net.Http.WebRequest&lt;/li&gt;    &lt;li&gt;System.Json&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;For each of the assemblies that match the GAC’ed list install them in the GAC using GacUtil (running as Administrator) like this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;GacUtil.exe -i &amp;lt;path to assembly in your packages folder&amp;gt;&lt;/strong&gt;&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;For example, &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4848.GacUtil_5F00_004C3E09.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="GacUtil" border="0" alt="GacUtil" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/1200.GacUtil_5F00_thumb_5F00_271A5449.png" width="604" height="56" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;Trying It Out&lt;/h1&gt;  &lt;p&gt;You are now ready to run your application. When running in the Visual Studio debugger you can verify that you use the new assemblies by looking at the &lt;strong&gt;Modules&lt;/strong&gt; window available under the &lt;strong&gt;Visual Studio Debug&lt;/strong&gt; menu. It should look something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3060.Modules_5F00_38F6E816.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="Modules" border="0" alt="Modules" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8233.Modules_5F00_thumb_5F00_660BD4E4.png" width="604" height="249" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The version numbers should correspond to the numbers used to name the folders under the &lt;strong&gt;packages&lt;/strong&gt; folder we looked at above.&lt;/p&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e6c6f8d7-d27a-4276-ac1e-226016e53b32" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/Asp.net" rel="tag"&gt;Asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/codeplex" rel="tag"&gt;codeplex&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10298886" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>ASP.NET Web API Updates – April 27</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/04/27/asp-net-web-api-updates-april-27.aspx</link><pubDate>Fri, 27 Apr 2012 04:11:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10298316</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10298316</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/04/27/asp-net-web-api-updates-april-27.aspx#comments</comments><description>&lt;p&gt;Here’s a few more updates coming your way in ASP.NET Web API. As in the &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/23/using-cookies-with-asp-net-web-api.aspx"&gt;previous update&lt;/a&gt; the code has been checked into our &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;CodePlex source code repository&lt;/a&gt; but hasn’t yet been released as part of our &lt;a href="http://www.asp.net/web-api"&gt;official installer&lt;/a&gt;. Think of this as a sneak-peak for you to try out and comment on as part of our source code repository (see &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;Getting Started With ASP.NET Web Stack Source on CodePlex&lt;/a&gt; for details).&lt;/p&gt;  &lt;h1&gt;Helper for Wiring up Message Handlers&lt;/h1&gt;  &lt;p&gt;HttpMessageHandlers are pluggable “filters” that sit between HttpClient and the network and allow you to modify the request and/or response as they travel from a HttpClient to the network and back (see &lt;a href="http://www.asp.net/web-api/overview/working-with-http/http-message-handlers"&gt;Mike Wasson’s blog on message handlers&lt;/a&gt; for a detailed walkthrough). HttpMessageHandlers are plugged together in a “Russian doll” model where each handler delegates to the inner handler until the last one hits the network (or a previous one short-circuited the path). The model can be illustrated like this:&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8623.HttpMessageHandlers1_5F00_3242B2A6.png"&gt;&lt;img style="border: 0px currentcolor; margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="HttpMessageHandlers1" border="0" alt="HttpMessageHandlers1" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/5327.HttpMessageHandlers1_5F00_thumb_5F00_2D5FFEEA.png" width="600" height="150" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/1c4e80fcf59e"&gt;This commit&lt;/a&gt; provides a simple &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/1c4e80fcf59e#src%2fSystem.Net.Http.Formatting%2fHttpClientFactory.cs"&gt;HttpClientFactory&lt;/a&gt; that can wire up DelegatingHandlers and create an HttpClient with the desired pipeline ready to go. It also provides functionality for wiring up with alternative inner handlers (the default is HttpClientHandler) as well as do the wiring up when using HttpMessageInvoker or another DelegatingHandler instead of HttpClient as the top-invoker.&lt;/p&gt;  &lt;p&gt;To demonstrate this we first create a handler where we override the SendAsync method to intercept the request and response path:&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; MyHandler : DelegatingHandler&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; _name;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; MyHandler(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; name)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         _name = name;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// We override the SendAsync method to intercept both the request and response path&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request path in handler {0}&amp;quot;&lt;/span&gt;, _name);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;.SendAsync(request, cancellationToken).ContinueWith(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;             requestTask =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;                 Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Response path in handler {0}&amp;quot;&lt;/span&gt;, _name);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; requestTask.Result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;             }, TaskContinuationOptions.OnlyOnRanToCompletion);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Then we use this handler in a sample where we instantiate three instances and wire them together:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create three instances of handlers&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; MyHandler handlerA = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MyHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;A&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; MyHandler handlerB = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MyHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;B&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; MyHandler handlerC = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MyHandler(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;C&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create HttpClient with handlers A, B, and C wired up&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; HttpClient client = HttpClientFactory.Create(handlerC, handlerB, handlerA);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Issue asynchronous GET request&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt; client.GetAsync(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://msdn.microsoft.com&amp;quot;&lt;/span&gt;).ContinueWith(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     requestTask =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (requestTask.IsCanceled)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request was cancelled&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (requestTask.IsFaulted)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request failed with an exception: {0}&amp;quot;&lt;/span&gt;, requestTask.Exception.GetBaseException());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         HttpResponseMessage response = requestTask.Result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request succeeded&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;     });&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;When running this sample we get the following output on the console (note the order with A being first on request and last on response, etc.):&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4810.MultipleHandlers_5F00_7E9A4647.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="MultipleHandlers" border="0" alt="MultipleHandlers" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3252.MultipleHandlers_5F00_thumb_5F00_1E492010.png" width="604" height="212" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Progress Notifications&lt;/h1&gt;

&lt;p&gt;Being able to get progress notifications on data being uploaded and downloaded was a popular request on the beta bits which we didn’t support directly. &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/0033416a1cc1"&gt;This commit&lt;/a&gt; defines a &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/0033416a1cc1#src%2fSystem.Net.Http.Formatting%2fHandlers%2fProgressMessageHandler.cs"&gt;ProgressMessageHandler&lt;/a&gt; which generates progress notification for both request entities being uploaded and response entities being downloaded. Using this handler it is possible to keep track of how far you are uploading a request body or downloading a response body.&lt;/p&gt;

&lt;p&gt;The &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/0033416a1cc1#src%2fSystem.Net.Http.Formatting%2fHandlers%2fProgressMessageHandler.cs"&gt;ProgressMessageHandler&lt;/a&gt; exposes two events, one for tracking upload and download progress respectively. Each progress notification is associated with a specific request so it is possible to track progress notifications from multiple ongoing requests at the same time. A sample receive progress event handler looks like this:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; HttpReceiveProgress(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, HttpProgressEventArgs e)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// The sender is the originating HTTP request&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     HttpRequestMessage request = sender &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; HttpRequestMessage;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Write different message depending on whether we have a total length or not&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; message;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (e.TotalBytes != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         message = String.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request {0} downloaded {1} of {2} bytes ({3}%)&amp;quot;&lt;/span&gt;, request.RequestUri, e.BytesTransferred, e.TotalBytes, e.ProgressPercentage);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         message = String.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request {0} downloaded {1} bytes&amp;quot;&lt;/span&gt;, request.RequestUri, e.BytesTransferred, e.TotalBytes, e.ProgressPercentage);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Write progress message to console&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;     Console.WriteLine(message);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The send progress event handler looks exactly the same – it also receives a &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/0033416a1cc1#src%2fSystem.Net.Http.Formatting%2fHandlers%2fHttpProgressEventArgs.cs"&gt;HttpProgressEventArgs&lt;/a&gt; instance with the exact same shape. Below is a sample which uses the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/1c4e80fcf59e#src%2fSystem.Net.Http.Formatting%2fHttpClientFactory.cs"&gt;HttpClientFactory&lt;/a&gt; to create an HttpClient with progress notifications hooked in:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create a progress notification handler and wire up events for upload and download progress&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; ProgressMessageHandler progress = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ProgressMessageHandler();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; progress.HttpReceiveProgress += &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; EventHandler&amp;lt;HttpProgressEventArgs&amp;gt;(HttpReceiveProgress);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; progress.HttpSendProgress += &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; EventHandler&amp;lt;HttpProgressEventArgs&amp;gt;(HttpSendProgress);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create a client and wire up the progress handler&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; HttpClient client = HttpClientFactory.Create(progress);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// We can now submit an HTTP request and see the progress notifications in action&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt; client.GetAsync(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://msdn.microsoft.com&amp;quot;&lt;/span&gt;).ContinueWith(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     (requestTask) =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (requestTask.IsCanceled)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request was cancelled&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (requestTask.IsFaulted)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request failed with an exception: {0}&amp;quot;&lt;/span&gt;, requestTask.Exception.GetBaseException());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         HttpResponseMessage response = requestTask.Result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Request succeeded&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;     });&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;A sample output written to the console looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7043.ProgressConsole_5F00_7D55AD68.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="ProgressConsole" border="0" alt="ProgressConsole" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2678.ProgressConsole_5F00_thumb_5F00_0ABBC06F.png" width="604" height="194" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Multipart Improvements&lt;/h1&gt;

&lt;p&gt;Support for reading MIME multipart messages as handled by the HttpContent.&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/d4dfe82c9ac5#src%2fSystem.Net.Http.Formatting%2fHttpContentMultipartExtensions.cs"&gt;ReadAsMultipartAsync&lt;/a&gt; extension methods had two usability problems in the original design:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The result was IEnumerable&amp;lt;HttpContent&amp;gt; which is too low-level to facilitate easy consumption. For example, it doesn't allow for converting multipart html form data into NameValueCollection data or for any other higher-level abstraction on top of the raw IEnumerable&amp;lt;HttpContent&amp;gt;.&lt;/li&gt;

  &lt;li&gt;The stream provider doesn't enable any post processing of the data such as converting the read data into another format before the read task completed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This made it hard to provide a higher-level abstraction on top of IEnumerable&amp;lt;HttpContent&amp;gt; as the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/d4dfe82c9ac5#src%2fSystem.Net.Http.Formatting%2fMultipartStreamProvider.cs"&gt;MultipartStreamProvider&lt;/a&gt; does not know when the message has been completely read. &lt;/p&gt;

&lt;p&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/8fda60945d49"&gt;This commit&lt;/a&gt; fixes these short comings by first changing the signature of the ReadAsMultipartAsync to&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;public static Task&amp;lt;T&amp;gt; ReadAsMultipartAsync&amp;lt;T&amp;gt;(this HttpContent content, T streamProvider) where T : MultipartStreamProvider&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This means that it is now possible to write a &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/d4dfe82c9ac5#src%2fSystem.Net.Http.Formatting%2fMultipartStreamProvider.cs"&gt;MultipartStreamProvider&lt;/a&gt; that is completely tailored to the type of MIME multipart that it can read and present the result in the optimal way to the user. &lt;/p&gt;

&lt;p&gt;Second, we introduce a “post processing” step as part of the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8fda60945d49#src%2fSystem.Net.Http.Formatting%2fMultipartStreamProvider.cs"&gt;MultipartStreamProvider&lt;/a&gt; that allows the implementation to do whatever post processing it wants on the MIME multipart body parts. For example, the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8fda60945d49#src%2fSystem.Net.Http.Formatting%2fMultipartFormDataStreamProvider.cs"&gt;MultipartFormDataStreamProvider&lt;/a&gt; implementation reads the HTML form data parts and adds them to a NameValueCollection so they are easy to get at from the caller.&lt;/p&gt;

&lt;p&gt;The built-in set of &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8fda60945d49#src%2fSystem.Net.Http.Formatting%2fMultipartStreamProvider.cs"&gt;MultipartStreamProvider&lt;/a&gt; consists of:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8fda60945d49#src%2fSystem.Net.Http.Formatting%2fMultipartMemoryStreamProvider.cs"&gt;MultipartMemoryStreamProvider&lt;/a&gt; saves all MIME body parts in memory allowing them to be read, deserialized, etc.&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8fda60945d49#src%2fSystem.Net.Http.Formatting%2fMultipartFileStreamProvider.cs"&gt;MultipartFileStreamProvider&lt;/a&gt; saves all MIME body parts as individual files.&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8fda60945d49#src%2fSystem.Net.Http.Formatting%2fMultipartFormDataStreamProvider.cs"&gt;MultipartFormDataStreamProvider&lt;/a&gt; saves all form data parts in a NameValueCollection and all file parts to file. This allows the form data to be easily manipulated and files to be persisted.&lt;/li&gt;

  &lt;li&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8fda60945d49#src%2fSystem.Net.Http.Formatting%2fMultipartRelatedStreamProvider.cs"&gt;MultipartRelatedStreamProvider&lt;/a&gt; parses multipart related entities as defined by &lt;a href="http://www.ietf.org/rfc/rfc2387.txt"&gt;RFC 2387 “The MIME Multipart/Related Content-type&lt;/a&gt;”.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An example of how to implement an Action that handles file uploads with parameters using &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/8fda60945d49#src%2fSystem.Net.Http.Formatting%2fMultipartFormDataStreamProvider.cs"&gt;MultipartFormDataStreamProvider&lt;/a&gt; looks like this:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; [HttpPost]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Task&amp;lt;List&amp;lt;FileResult&amp;gt;&amp;gt; UploadFile()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Verify that this is an HTML Form file upload request&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!Request.Content.IsMimeMultipartContent(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;form-data&amp;quot;&lt;/span&gt;))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Create a stream provider for setting up output streams&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     MultipartFormDataStreamProvider streamProvider = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MultipartFormDataStreamProvider(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;d:\\src\\tmp\\uploads&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Read the MIME multipart asynchronously content using the stream provider we just created.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         readTask =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;             MultipartFormDataStreamProvider provider = readTask.Result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Create response containing information about the stored files.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; provider.FileData.Select(fileData =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;                 FileInfo fileInfo = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; FileInfo(fileData.LocalFileName);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;                 ContentDispositionHeaderValue disposition = fileData.Headers.ContentDisposition;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; filename = (disposition != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; disposition.FileName != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;) ? disposition.FileName : String.Empty;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; FileResult&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;                 {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;                     FileName = filename,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;                     LocalPath = fileInfo.FullName,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;                     LastModifiedTime = fileInfo.LastWriteTimeUtc,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;                     Length = fileInfo.Length,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;                     Submitter = provider.FormData[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;submitter&amp;quot;&lt;/span&gt;]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;                 };&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;             }).ToList();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;         });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;As always please use the &lt;a href="http://aspnetwebstack.codeplex.com/discussions"&gt;CodePlex discussion forum&lt;/a&gt; and go vote on your favorite issue in &lt;a href="http://aspnetwebstack.codeplex.com/workitem/list/advanced"&gt;Issue Tracker&lt;/a&gt; – we would love to hear you feedback.&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b6c5e71f-d600-4dde-a21c-eae7586219f1" class="wlWriterSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/httpclient" rel="tag"&gt;httpclient&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/http" rel="tag"&gt;http&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10298316" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>Recent ASP.NET Web API Updates – April 24</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/04/23/using-cookies-with-asp-net-web-api.aspx</link><pubDate>Mon, 23 Apr 2012 19:58:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10296795</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10296795</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/04/23/using-cookies-with-asp-net-web-api.aspx#comments</comments><description>&lt;p&gt;Here’s a few updates coming your way in ASP.NET Web API. The code has been checked into our &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;CodePlex source code repository&lt;/a&gt; but hasn’t yet been released as part of our &lt;a href="http://www.asp.net/web-api"&gt;official installer&lt;/a&gt;. Think of this as a sneak-peak for you to try out and comment on as part of our source code repository (see &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;Getting Started With ASP.NET Web Stack Source on CodePlex&lt;/a&gt; for details).&lt;/p&gt;  &lt;h1&gt;Cookie Support&lt;/h1&gt;  &lt;p&gt;Until now the HTTP Cookie and Set-Cookie headers were only exposed as raw strings and not structured classes in the HttpRequestMessage and HttpResponseMessage classes. This made it cumbersome and error prone to work with cookies in ASP.NET Web API. To fix this we introduced two new classes called &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fHeaders%2fCookieHeaderValue.cs"&gt;CookieHeaderValue&lt;/a&gt; and &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fHeaders%2fCookieState.cs"&gt;CookieState&lt;/a&gt; that follow the &lt;a href="http://tools.ietf.org/html/rfc6265"&gt;RFC 6265 HTTP State Management Mechanism&lt;/a&gt;. Each Cookie or Set-Cookie header is represented as one CookieHeaderValue. A CookieHeaderValue contains information about the domain, path, expiration, and other common cookie information as well as one or more CookieStates. Each CookieState contains a name and whatever state is associate with that name. This representation allows for multiple related CookieStates to be carried within the same Cookie header while still providing separation between each cookie state.&lt;/p&gt;  &lt;p&gt;To see how this works, look at the sample cookie exchange where a server sends a cookie to the client using the Set-Cookie header including the cookie state as well as domain and expiration information:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Set-Cookie: &lt;strong&gt;StateA&lt;/strong&gt;=n1=v1&amp;amp;n2=v2; &lt;strong&gt;StateZ&lt;/strong&gt;=n3=v3&amp;amp;n4=v4; &lt;strong&gt;Domain&lt;/strong&gt;=domain1; &lt;strong&gt;Path&lt;/strong&gt;=path1; &lt;strong&gt;Expires&lt;/strong&gt;=Mon, 23 Apr 2012 08:49:37 GMT&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;The client then returns the cookie on a subsequent request passing just the cookie state:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Cookie: &lt;strong&gt;StateA&lt;/strong&gt;=n1=v1&amp;amp;n2=v2; &lt;strong&gt;StateZ&lt;/strong&gt;=n3=v3&amp;amp;n4=v4&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;In this example, there is one &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fHeaders%2fCookieHeaderValue.cs"&gt;CookieHeaderValue&lt;/a&gt; with two &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fHeaders%2fCookieState.cs"&gt;CookieStates&lt;/a&gt; in the Set-Cookie response and also in the subsequent Cookie request. The CookieStates have names &lt;strong&gt;StateA&lt;/strong&gt; and &lt;strong&gt;StateZ&lt;/strong&gt; respectively. The CookieState names are followed by a value consisting of name-value pairs encoded as &lt;a href="http://www.w3.org/TR/html5/form-submission.html#url-encoded-form-data"&gt;URL-encoded form data&lt;/a&gt; (also known as application/x-www-form-urlencoded) so that you can pass relatively structured data back and forth. In the above example, &lt;strong&gt;StateA&lt;/strong&gt; has two name/value pairs (n1=v1 and n2=v2).&lt;/p&gt;  &lt;p&gt;Getting all the CookieHeaderValues from a request:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;var cookies = Request.Headers.&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fHttpRequestHeadersExtensions.cs"&gt;GetCookies&lt;/a&gt;();&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;Getting a CookieHeaderValue with a particular CookieState name:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;var cookie = Request.Headers.&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fHttpRequestHeadersExtensions.cs"&gt;GetCookies&lt;/a&gt;(“StateA”);&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;Adding one or more Set-Cookie headers to a response&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt; Response.Headers.&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fHttpResponseHeadersExtensions.cs"&gt;AddCookies&lt;/a&gt;(cookies);&lt;/li&gt;  &lt;/ul&gt;  &lt;p&gt;You can access the CookieState using C# indexers. For example, the following would return “v2”:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;var value = cookie[“StateA”][“n2”];&lt;/li&gt;  &lt;/ul&gt;  &lt;h1&gt;Push Content&lt;/h1&gt;  &lt;p&gt;The HttpContent model supports writing data by either pushing data to the output stream directly or pulling data from an input stream and then copying it to the output stream (see &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/17/push-and-pull-streams-using-httpclient.aspx"&gt;Push and Pull Streams using HttpClient&lt;/a&gt;). Pull is supported out of the box in the form of StreamContent but until there was no equivalent built-in support for pushing data.&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fPushStreamContent.cs"&gt;PushStreamContent&lt;/a&gt; class enables scenarios where a data producer wants to write directly (either synchronously or asynchronously) using a stream. When the PushStreamContent is ready to accept data it calls out to an action with the output stream. The developer can then write to the stream for as long as necessary and close the stream when writing has completed. The PushStreamContent detects the closing of the stream and completes the underlying asynchronous Task for writing out the content. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fPushStreamContent.cs"&gt;PushStreamContent&lt;/a&gt; is entirely asynchronous and does not block any threads. It is up to the user of the PushStreamContent to write data either synchronously or asynchronously which of course then will determine whether a thread is blocked or not. For more details, see &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/0e1d63b7e7e5"&gt;this commit&lt;/a&gt;. Here’s a sample push controller which writes out the plaintext string “Here’s some more data” every second. On the wire this will be sent using HTTP Chunked Encoding where each string will be an individual chunk. &lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; PushController : ApiController&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; Lazy&amp;lt;Timer&amp;gt; _timer = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Lazy&amp;lt;Timer&amp;gt;(() =&amp;gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Timer(TimerCallback, &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;, 0, 1000));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; ConcurrentDictionary&amp;lt;StreamWriter, StreamWriter&amp;gt; _outputs = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ConcurrentDictionary&amp;lt;StreamWriter, StreamWriter&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; HttpResponseMessage GetUpdates(HttpRequestMessage request)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         Timer t = _timer.Value;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         request.Headers.AcceptEncoding.Clear();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         HttpResponseMessage response = request.CreateResponse();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         response.Content = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; PushStreamContent(OnStreamAvailable, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;text/plain&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; response;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; OnStreamAvailable(Stream stream, HttpContentHeaders headers, TransportContext context)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         StreamWriter sWriter = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StreamWriter(stream);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         _outputs.TryAdd(sWriter, sWriter);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; TimerCallback(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; state)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; (var kvp &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; _outputs.ToArray())&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;                 kvp.Value.Write(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Here's some more data...&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;                 kvp.Value.Flush();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;catch&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;                 StreamWriter sWriter;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;                 _outputs.TryRemove(kvp.Value, &lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; sWriter);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Buffered Media Type Formatter&lt;/h1&gt;

&lt;p&gt;The &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fFormatting%2fBufferedMediaTypeFormatter.cs"&gt;BufferedMediaTypeFormatter&lt;/a&gt; provides a convenient way for writing a &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fFormatting%2fMediaTypeFormatter.cs"&gt;MediaTypeFormatter&lt;/a&gt; that primarily is writing or reading small, synchronous pieces of data. This is for example the case by many serializers which don’t quite support asynchronous reading and writing. Instead of having to implement the Task-oriented &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fFormatting%2fMediaTypeFormatter.cs"&gt;MediaTypeFormatter&lt;/a&gt; for reading and writing the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fFormatting%2fBufferedMediaTypeFormatter.cs"&gt;BufferedMediaTypeFormatter&lt;/a&gt; exposes a simplified model backed by a buffer that is well suited to handle many small reads or writes. For more details, see &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/89074022e22c"&gt;this commit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Below is a sample plaintext formatter written using the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/edc64a277047#src%2fSystem.Net.Http.Formatting%2fFormatting%2fBufferedMediaTypeFormatter.cs"&gt;BufferedMediaTypeFormatter&lt;/a&gt; which supports writing or reading plain text using either UTF8 or UTF-16 as determined automatically by the built-in content negotiation algorithm (see &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/22/asp-net-web-api-content-negotiation-and-accept-charset.aspx"&gt;ASP.NET Web API Content Negotiation and Accept-Charset&lt;/a&gt;):&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; SampleBufferedMediaTypeFormatter : BufferedMediaTypeFormatter&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; SampleBufferedMediaTypeFormatter()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Set supported media type&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         SupportedMediaTypes.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MediaTypeHeaderValue(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;text/plain&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Set default supported character encodings&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         SupportedEncodings.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; UTF8Encoding(encoderShouldEmitUTF8Identifier: &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;, throwOnInvalidBytes: &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         SupportedEncodings.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; UnicodeEncoding(bigEndian: &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;, byteOrderMark: &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;, throwOnInvalidBytes: &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanReadType(Type type)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; type == &lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanWriteType(Type type)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; type == &lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; ReadFromStream(Type type, Stream stream, HttpContentHeaders contentHeaders, IFormatterLogger formatterLogger)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;         Encoding effectiveEncoding = SelectCharacterEncoding(contentHeaders);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (StreamReader sReader = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StreamReader(stream, effectiveEncoding))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; sReader.ReadToEnd();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; WriteToStream(Type type, &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;, Stream stream, HttpContentHeaders contentHeaders)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;         Encoding effectiveEncoding = SelectCharacterEncoding(contentHeaders);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (StreamWriter sWriter = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StreamWriter(stream, effectiveEncoding))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;             sWriter.Write(&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;What do you think? Please use the &lt;a href="http://aspnetwebstack.codeplex.com/discussions"&gt;CodePlex discussion forum&lt;/a&gt; and go vote on your favorite issue in &lt;a href="http://aspnetwebstack.codeplex.com/workitem/list/advanced"&gt;Issue Tracker&lt;/a&gt; – we would love to hear you feedback.&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f06cfde5-88ae-412f-a390-ce3366b0eb24" class="wlWriterSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/http" rel="tag"&gt;http&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10296795" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item><item><title>ASP.NET Web API Content Negotiation and Accept-Charset</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/04/22/asp-net-web-api-content-negotiation-and-accept-charset.aspx</link><pubDate>Sun, 22 Apr 2012 19:46:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10296250</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10296250</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/04/22/asp-net-web-api-content-negotiation-and-accept-charset.aspx#comments</comments><description>&lt;p&gt;There are several good blogs on content negotiation in ASP.NET Web API (see for example &lt;a href="http://weblogs.asp.net/gunnarpeipman/archive/2012/04/19/asp-net-web-api-how-content-negotiation-works.aspx"&gt;ASP.NET Web API: How content negotiation works?&lt;/a&gt;) describing how to get JSON, XML, and other response formats depending on what you ask for in a request using the &lt;a href="http://tools.ietf.org/html/draft-ietf-httpbis-p3-payload-19#section-6.1"&gt;Accept HTTP request header field&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;However, recently we added support for the header &lt;a href="http://tools.ietf.org/html/draft-ietf-httpbis-p3-payload-19#section-6.2"&gt;Accept-Charset&lt;/a&gt; which can be used by the client to indicate which character encoding it prefers the response to be encoded with. Typical encodings are &lt;a href="http://en.wikipedia.org/wiki/Utf-8"&gt;UTF-8&lt;/a&gt; and &lt;a href="http://en.wikipedia.org/wiki/Utf-16"&gt;UTF-16&lt;/a&gt; (and our built-in formatters support those) but the set is extensible to other encodings as well.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This is the first in a series of blogs on upcoming features that have been checked into our &lt;a href="http://aspnetwebstack.codeplex.com/"&gt;CodePlex source code repository&lt;/a&gt; but haven’t yet been released as part of our &lt;a href="http://www.asp.net/web-api"&gt;official installer&lt;/a&gt;. Think of this as a sneak-peak for you to try out and comment on as part of our source code repository (see &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;Getting Started With ASP.NET Web Stack Source on CodePlex&lt;/a&gt; for details).&lt;/p&gt;  &lt;h1&gt;Seeing Accept-Charset in Action&lt;/h1&gt;  &lt;p&gt;To see how the Accept-Charset header affects the content negotiation it is simplest to use &lt;a href="http://www.fiddler2.com/fiddler2/"&gt;Fiddler&lt;/a&gt;. In the following we use the completely vanilla out-of-the-box &lt;strong&gt;ValuesController&lt;/strong&gt; without any changes – we just run it. In Fiddler we use the Composer tab to send a request to the &lt;strong&gt;ValuesController&lt;/strong&gt; like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8666.FiddlerComposer_5F00_700D97FE.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="FiddlerComposer" border="0" alt="FiddlerComposer" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/5127.FiddlerComposer_5F00_thumb_5F00_53FCD913.png" width="604" height="392" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The response coming from the server looks like this. Note the media type parameter &lt;strong&gt;charset=utf-8&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7776.FiddlerCharsetUtf8_5F00_13C6BF99.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="FiddlerCharsetUtf8" border="0" alt="FiddlerCharsetUtf8" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7752.FiddlerCharsetUtf8_5F00_thumb_5F00_33759961.png" width="604" height="392" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now, go back to the composer tab and add &lt;strong&gt;Accept-Charset: utf-16&lt;/strong&gt; and you will see this response:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/0624.FiddlerCharsetUtf16_5F00_64821FE1.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="FiddlerCharsetUtf16" border="0" alt="FiddlerCharsetUtf16" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7077.FiddlerCharsetUtf16_5F00_thumb_5F00_4E4C048F.png" width="604" height="392" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note also that the Content-Length is twice as big as UTF-16 takes more space.&lt;/p&gt;  &lt;p&gt;Now, you can also use q-values with the Accept-Charset header to indicate multiple values with varying quality factors associated. For example if you in the composer tab insert the header field &lt;strong&gt;Accept-Charset: utf-16, utf-8; q=0.5&lt;/strong&gt; (which means I prefer UTF-16 but can also take UTF-8) then you get the same response as above with a UTF-16 encoded response.&lt;/p&gt;  &lt;h1&gt;Changing the Default Encodings&lt;/h1&gt;  &lt;p&gt;The default encoding used by the built-in formatters is UTF-8. This means that if the request doesn’t indicate any preference then we will use UTF-8. However, you can easily change this on a per-formatter basis by changing the &lt;strong&gt;SupportEncodings&lt;/strong&gt; property on the &lt;strong&gt;MediaTypeFormatter&lt;/strong&gt; class. For example, if you want to swap the default encoding from UTF-8 with UTF-16 then you can just reverse the default list so that UTF-16 is fist and UTF-8 is second (see line 3-5):&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Application_Start()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     Encoding oldDefault = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SupportedEncodings[0];&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     GlobalConfiguration.Configuration.Formatters.JsonFormatter.SupportedEncodings.Add(oldDefault);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     GlobalConfiguration.Configuration.Formatters.JsonFormatter.SupportedEncodings.RemoveAt(0);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     AreaRegistration.RegisterAllAreas();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     RegisterGlobalFilters(GlobalFilters.Filters);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     RegisterRoutes(RouteTable.Routes);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     BundleConfig.RegisterBundles(BundleTable.Bundles);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;When running the same sample above you will see a UTF-16 response when no accept-charset header is present. However, if you set the accept-charset header to UTF-8 then you will still get that.&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6fc85dfd-a2d4-42f7-b76f-77215e262644" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/http" rel="tag"&gt;http&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10296250" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/REST/">REST</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item><item><title>Contributing to ASP.NET Web Stack Source on CodePlex</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/04/10/using-forks-with-asp-net-web-stack-source-on-codeplex.aspx</link><pubDate>Tue, 10 Apr 2012 20:16:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292379</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10292379</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/04/10/using-forks-with-asp-net-web-stack-source-on-codeplex.aspx#comments</comments><description>&lt;p&gt;In the blog &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;Getting Started With ASP.NET Web Stack Source on CodePlex&lt;/a&gt; we describe how to set up a &lt;strong&gt;read-only&lt;/strong&gt; clone of the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/list/changesets"&gt;ASP.NET Web Stack source repository&lt;/a&gt;. This allows you to sync your tree to the latest changes as soon as they appear but you can’t update the code, fix bugs, or suggest changes. In short, it is read-only.&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;This blog describes how to set up and then use a fork to be able to contribute to the project. It first describes setting up a fork as a one-time process and then it describes three common workflows for working with the fork on a regular basis.&lt;/p&gt;  &lt;p&gt;If you haven’t already, then now is a good time to check out the &lt;a href="http://aspnetwebstack.codeplex.com/wikipage?title=Contributing&amp;amp;referringTitle=Home"&gt;process for contributing to the ASP.NET Web Stack project&lt;/a&gt;. It describes in detail what you need to do in order to contribute with as little pain as possible.&lt;/p&gt;  &lt;h1&gt;Why a Fork?&lt;/h1&gt;  &lt;p&gt;A common way for open source projects to allow contributions is by using &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/network"&gt;forks&lt;/a&gt;. A fork is not actually a &lt;a href="http://git-scm.com/"&gt;Git&lt;/a&gt; concept but a way for you to host your own copy of the ASP.NET Web Stack repository in CodePlex where you have write access and can submit changes without interfering with anybody else. The fork also allows you to work on your changes simultaneously across multiple machines or even with other people with whom you collaborate.&lt;/p&gt;  &lt;h1&gt;Creating a Fork&lt;/h1&gt;  &lt;p&gt;The first step is to create a fork which you do by going to the &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/list/changesets"&gt;CodePlex repository&lt;/a&gt; and selecting &lt;strong&gt;Create Fork&lt;/strong&gt;:&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8372.CreateFork_5F00_78CF700D.png"&gt;&lt;img style="display: inline; background-image: none;" title="CreateFork" border="0" alt="CreateFork" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/0451.CreateFork_5F00_thumb_5F00_115F0D5E.png" width="504" height="333" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You will now see another page where you can fill in the fork name and a description. A good name to use for your fork is &lt;strong&gt;aspnetwebstack&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8877.ForkName_5F00_661A7656.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="ForkName" border="0" alt="ForkName" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/1524.ForkName_5F00_thumb_5F00_25E45CDC.png" width="504" height="333" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now hit &lt;strong&gt;Save&lt;/strong&gt; to create the fork. Select the &lt;strong&gt;Forks&lt;/strong&gt; menu and you will see the fork you just created along with a clone URI. &lt;/p&gt;  &lt;h1&gt;Cloning the Fork&lt;/h1&gt;  &lt;p&gt;As the fork lives on &lt;a href="http://aspnetwebstack.codeplex.com/SourceControl/network"&gt;CodePlex&lt;/a&gt; you need to clone it to your local dev machine in order to work on it. As in the &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;previous blog&lt;/a&gt; we use PowerShell with &lt;a href="https://github.com/dahlbyk/posh-git"&gt;Git extensions&lt;/a&gt; so if you haven’t yet set that up then please check that blog for details. &lt;/p&gt;  &lt;p&gt;We use the fork URI that you got above to create a clone on your local dev machine. This looks similar to when you cloned the main repository in the &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;previous blog&lt;/a&gt; – the only difference is the repository URI which has your CodePlex user name in two places:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;https://&lt;strong&gt;&amp;lt;CodePlexUserName&amp;gt;&lt;/strong&gt;@git01.codeplex.com/forks/&lt;strong&gt;&amp;lt;CodePlexUserName&amp;gt;&lt;/strong&gt;/aspnetwebstack&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You use it with the clone command like this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git clone &lt;/strong&gt;&lt;strong&gt;https://&lt;font style="background-color: rgb(255, 255, 0);"&gt;&amp;lt;UserName&amp;gt;@&lt;/font&gt;git01.codeplex.com/forks/&lt;font style="background-color: rgb(255, 255, 0);"&gt;&amp;lt;UserName&amp;gt;&lt;/font&gt;/aspnetwebstack&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Make sure the folder aspnetwebstack doesn’t conflict with anything you already have in the folder where you do the clone.&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3326.Clone_5F00_4A54FF45.png"&gt;&lt;img style="display: inline; background-image: none;" title="Clone" border="0" alt="Clone" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7612.Clone_5F00_thumb_5F00_510808C8.png" width="504" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The next step of getting the fork up and running is configuring Git with your name and email alias so that it is clear that the commits come from you. From the same prompt as above run the two commands from the aspnetwebstack folder:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git config user.name YourCodePlexUserName&lt;/strong&gt;&amp;#160; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;git config user.email &lt;/strong&gt;&lt;a href="mailto:name@example.com"&gt;&lt;strong&gt;name@example.com&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Also, if you run a commit from the command line and you don’t include the –m option, it will pop up a text editor for you to compose the commit message. That text editor is VIM by default. If you’re not a VI person, then you might want to set an alternative editor (I use &lt;a href="http://www.flos-freeware.ch/notepad2.html"&gt;notepad2&lt;/a&gt; but you can also use &lt;a href="https://github.com/blog/975-gitpad-write-your-commits-in-notepad"&gt;GitPad&lt;/a&gt;). You can do this with this command (note the forward slashes instead of backslashes):&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git config core.editor C:/Path/To/MyFavoriteEditor.exe&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In order not to get confused about the setup, the thing to keep in mind is that there are three repositories in play:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;The &lt;strong&gt;upstream repository&lt;/strong&gt; which is the main repository on CodePlex&lt;/li&gt;    &lt;li&gt;The &lt;strong&gt;origin repository&lt;/strong&gt; which is your fork on CodePlex&lt;/li&gt;    &lt;li&gt;The &lt;strong&gt;local repository&lt;/strong&gt; on your dev machine&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;To make it easy to refer to the upstream repository we create an alias in addition to &lt;strong&gt;origin&lt;/strong&gt;. You add an alias called &lt;strong&gt;upstream&lt;/strong&gt; referring to the main repository URI and &lt;strong&gt;not&lt;/strong&gt; the fork URI by running the command from the &lt;strong&gt;aspnetwebapi&lt;/strong&gt; folder:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git remote add upstream &lt;/strong&gt;&lt;a href="https://git01.codeplex.com/aspnetwebstack.git"&gt;&lt;strong&gt;https://git01.codeplex.com/aspnetwebstack.git&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt; This command merely creates a local alias – nothing else happens so you won’t see more than this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3683.UpdateRemote_5F00_7C5D4890.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="UpdateRemote" border="0" alt="UpdateRemote" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3276.UpdateRemote_5F00_thumb_5F00_1C0C2259.png" width="504" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Ok, that’s it for setting up the repositories. While it took some effort to get here the good part is that up to this point the process is something you only have to do once. With some care (as will be described below) a fork can last you a long time serving as your environment for fixing any number of bugs, suggesting new features, and more. In short, it is your environment for actively working on the source.&amp;#160; &lt;/p&gt;  &lt;p&gt;The actual day-to-day process of working in a fork typically involves the following three steps:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Synchronizing master branches across the three repositories.&lt;/li&gt;    &lt;li&gt;Creating a feature branch for each bug fix or feature work you work on.&lt;/li&gt;    &lt;li&gt;Submitting pull requests with your feature branch changes.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In the following we will describe all three of these workflows in detail.&lt;/p&gt;  &lt;h1&gt;Workflow 1: Synchronizing Master Branches&lt;/h1&gt;  &lt;p&gt;The term &lt;strong&gt;origin&lt;/strong&gt; is now referring to your fork repository and not to the upstream repository. That is, when you push to origin, you push to your fork, not to the upstream repository. In other words, the fork acts in all respects like the upstream repository except that you can submit your changes whenever you want.&lt;/p&gt;  &lt;p&gt;After you created your origin and your local repository, changes will continue to happen in the upstream repository. In order to see these changes in your origin and local repositories you need to pull them – it is not done automatically. The goal of this workflow is to ensure that your local master is in sync with your origin master which is in sync with the upstream master.&lt;/p&gt;  &lt;p&gt;The synchronization actually happens in your local repository on your dev box – the origin won’t get updated until you push the edits to it. That is, you sync your local master with the upstream master and push that to the origin master. Here is what you do:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git checkout master&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;git pull --rebase upstream master&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;git push origin&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;It should look something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7624.SyncUpstream_5F00_49E8CC50.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="SyncUpstream" border="0" alt="SyncUpstream" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6646.SyncUpstream_5F00_thumb_5F00_42C98FD8.png" width="504" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h1&gt;Workflow 2: Creating a Feature Branch&lt;/h1&gt;  &lt;p&gt;In order to keep the fork clean and use it for a long time you should do all your work in feature branches and &lt;strong&gt;not&lt;/strong&gt; in the master branch. Keeping the master branch clean will make it easier to stay in sync with the upstream repository and generally avoid heartaches.&lt;/p&gt;  &lt;p&gt;Whenever you create a new feature branch, make sure you are in the master branch (you don’t want to create a branch of a branch just yet). That is, you should see &lt;strong&gt;[master]&lt;/strong&gt; in your prompt. You create a branch using the command &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git checkout -b Feature1&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;which will look like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/0383.FeatureBranch_5F00_6997A618.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="FeatureBranch" border="0" alt="FeatureBranch" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/1854.FeatureBranch_5F00_thumb_5F00_627869A0.png" width="504" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note that the prompt now says &lt;strong&gt;[Feature1]&lt;/strong&gt; and not &lt;strong&gt;[master]&lt;/strong&gt;. Within the new branch we start Visual Studio and load the runtime.sln solution as described in the &lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/04/09/getting-started-with-asp-net-web-stack-source-on-codeplex.aspx"&gt;previous blog&lt;/a&gt;. Here it doesn’t matter what the change is but for illustration purposes we fix a typo in the class MediaTypeHeaderValueExtensions where we change the documentation to say “subset” instead of “superset”. &lt;/p&gt;  &lt;p&gt;We then compile and run unit tests to see that everything is as we expect. Once the fix has been verified you can either commit it using &lt;a href="http://code.google.com/p/tortoisegit/"&gt;TortoiseGit&lt;/a&gt; or the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/63a7e40d-4d71-4fbb-a23b-d262124b8f4c"&gt;Git Source Control Provider&lt;/a&gt; directly from within Visual Studio. For simplicity we here just commit it using the PowerShell and the command &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git checkout Feature1&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;git commit -am &amp;quot;Fixed documentation typo&amp;quot;&lt;/strong&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;which will show this (note the &lt;a href="https://github.com/dahlbyk/posh-git#readme"&gt;red numbers which tells you that you have 1 modified file&lt;/a&gt;):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/5148.LocalCommit_5F00_5B592D28.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="LocalCommit" border="0" alt="LocalCommit" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4087.LocalCommit_5F00_thumb_5F00_16AC92E7.png" width="504" height="285" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You now make sure that your feature branch is up to date with the local master branch by typing this command:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git checkout Feature1&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;git rebase master&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Depending on your changes and the changes in your local master you may be asked to merge but in this scenario there are no merges.&lt;/p&gt;  &lt;p&gt;Once you are done with your change and want to submit it back to the origin (the fork) you push to origin&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;git checkout Feature1&lt;/strong&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;git push origin&lt;/strong&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Workflow 3: Submitting a Pull Request&lt;/h1&gt;  &lt;p&gt;When you are done with your change in the feature branch and committed it to origin you can now suggest that it be incorporated into the main repository. You do this by submitting a &lt;a href="http://aspnetwebstack.codeplex.com/sourcecontrol/list/contributions?statusFilter=all&amp;amp;reviewerFilter=all"&gt;pull request&lt;/a&gt; with your change. Before submitting a pull request please review carefully the &lt;a href="http://aspnetwebstack.codeplex.com/wikipage?title=Contributing"&gt;process for submitting contributions&lt;/a&gt;. The pull request will then go through a process of review looking at things like how it fits with the overall design, whether it has unit tests, whether the coding guidelines are used, etc. &lt;/p&gt;  &lt;p&gt;To submit a pull request go to your fork and select the repository link as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6138.Fork_5F00_7A9BD3FB.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="Fork" border="0" alt="Fork" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8765.Fork_5F00_thumb_5F00_16405FF2.png" width="504" height="371" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now set &lt;strong&gt;Branch&lt;/strong&gt; to your feature branch and you should see the submits that you have done:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3581.ForkRepository_5F00_0F21237A.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="ForkRepository" border="0" alt="ForkRepository" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2018.ForkRepository_5F00_thumb_5F00_0EB4F085.png" width="504" height="373" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now select &lt;strong&gt;Send Pull Request&lt;/strong&gt;, fill in the details including &lt;a href="http://aspnetwebstack.codeplex.com/workitem/list/basic"&gt;which issue you are submitting a pull request for&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Once the change &lt;a href="http://aspnetwebstack.codeplex.com/wikipage?title=Contributing"&gt;passes the process and gone through a full review&lt;/a&gt; it will get checked into the main repository and voila – you have contributed to the project!&lt;/p&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:020c05e1-0b0f-4997-ab8a-341b98ab192f" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/Asp.net" rel="tag"&gt;Asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/codeplex" rel="tag"&gt;codeplex&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292379" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/CodePlex/">CodePlex</category></item><item><title>Async Mashups using ASP.NET Web API</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/03/03/async-mashups-using-asp-net-web-api.aspx</link><pubDate>Sat, 03 Mar 2012 23:41:27 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10277154</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10277154</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/03/03/async-mashups-using-asp-net-web-api.aspx#comments</comments><description>&lt;p&gt;This blog shows an example of how to build an &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; ApiController that asynchronously talks to multiple other Web APIs in parallel without blocking a thread on the server. Btw, if you have detected a certain theme in these blogs around using &lt;a href="http://msdn.microsoft.com/library/dd460693.aspx"&gt;Tasks&lt;/a&gt; with &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; then you are indeed on to something :) &lt;/p&gt;  &lt;p&gt;Asynchronous programming is an important part of building scalable, robust, and responsive Web applications regardless of whether on client side or server side. Asynchronous programming has traditionally been very complicated leaving it to only the most dedicated to implement it but with the new Task model even complex patterns such as dealing with multiple asynchronous requests in parallel are manageable without braking too much of a sweat. The sample is written using &lt;a href="http://www.microsoft.com/vstudio"&gt;Visual Studio 11 Beta&lt;/a&gt; but can be modified to run on Visual Studio 2010 as well.&lt;/p&gt;  &lt;h1&gt;Scenario&lt;/h1&gt;  &lt;p&gt;In the scenario we have an ApiController that exposes a query operation with a single token (in the sequence diagram below the sample query token is “microsoft”). The ApiController then turns around and issues a query to &lt;a href="http://developers.digg.com/documentation"&gt;digg&lt;/a&gt; and &lt;a href="http://delicious.com/developers"&gt;delicious&lt;/a&gt; respectively for stories on the query token. When both results are complete, the results are accumulated into a single response that is then sent back to the client. The goal is to do the entire ApiController request asynchronously and to issue the queries to digg and delicious in parallel so that we don’t every block a thread and optimize network utilization.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3580.MashupScenario_5F00_18DADC99.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="MashupScenario" border="0" alt="MashupScenario" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3554.MashupScenario_5F00_thumb_5F00_1F8DE61C.png" width="504" height="277" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The response we send back to the client is a collection of “stories” that simply look like this:&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Story&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// The source (either digg or delicious)&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Source { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// The description of the story&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Description { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Creating the ApiController&lt;/h1&gt;

&lt;p&gt;Writing the controller involves three things: two helpers for processing the requests for digg and delicious respectively and then the controller to put it all together. &lt;/p&gt;

&lt;h3&gt;Executing digg Query&lt;/h3&gt;

&lt;p&gt;First we write a helper for processing the digg query. Here we submit a request, wait for the response, and then process it as JsonValue to build a set of Story instances as defined in the scenario above. As there is no instance state involved the query processing can be done as a static method.&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; async Task&amp;lt;List&amp;lt;Story&amp;gt;&amp;gt; ExecuteDiggQuery(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; queryToken)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     List&amp;lt;Story&amp;gt; result = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; List&amp;lt;Story&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// URI query for a basic digg query -- see http://developers.digg.com/documentation&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; query = &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://services.digg.com/2.0/search.search?query={0}&amp;quot;&lt;/span&gt;, queryToken);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Submit async request &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     HttpResponseMessage diggResponse = await _client.GetAsync(query);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Read result using JsonValue and process the stories &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (diggResponse.IsSuccessStatusCode)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         JsonValue diggResult = await diggResponse.Content.ReadAsAsync&amp;lt;JsonValue&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; (var story &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; diggResult[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;stories&amp;quot;&lt;/span&gt;] &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; JsonArray)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;             result.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Story&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;                 Source = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;digg&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;                 Description = story[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;title&amp;quot;&lt;/span&gt;].ReadAs&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt;()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;             });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Executing delicious Query&lt;/h3&gt;

&lt;p&gt;Then we write a similar helper for processing the delicious query. It follows the exact same pattern and also uses JsonValue to read the response and create a set of Story instances. Again, as there is no instance state involved the query processing can be done as a static method.&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; async Task&amp;lt;List&amp;lt;Story&amp;gt;&amp;gt; ExecuteDeliciousQuery(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; queryToken)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     List&amp;lt;Story&amp;gt; result = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; List&amp;lt;Story&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// URI query for a basic delicious query -- see http://delicious.com/developers&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; query = &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://feeds.delicious.com/v2/json/tag/{0}&amp;quot;&lt;/span&gt;, queryToken);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Submit async request &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     HttpResponseMessage deliciousResponse = await _client.GetAsync(query);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Read result using JsonValue and process the stories &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (deliciousResponse.IsSuccessStatusCode)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         JsonArray deliciousResult = await deliciousResponse.Content.ReadAsAsync&amp;lt;JsonArray&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; (var story &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; deliciousResult)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;             result.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Story&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;                 Source = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;delicious&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;                 Description = story[&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;d&amp;quot;&lt;/span&gt;].ReadAs&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt;()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;             });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Writing the Controller&lt;/h3&gt;

&lt;p&gt;Now we can write the actual ApiController. First we look for a valid query token (we don’t want it to contain any ‘&amp;amp;’ characters). Then we kick off the two helpers in parallel and wait for them to complete (but without blocking a thread using the Task.WhenAll construct). Finally we aggregate the two results and return them to the client. &lt;/p&gt;

&lt;p&gt;We of course use HttpClient to submit requests to dig and delicious but as HttpClient can handler requests submitted from multiple threads simultaneously we only need one instance for all requests. This means that the same HttpClient instance is reused for all requests across all ApiController instances.&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; async Task&amp;lt;List&amp;lt;Story&amp;gt;&amp;gt; GetContent(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; topic)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     List&amp;lt;Story&amp;gt; result = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; List&amp;lt;Story&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Check that we have a topic or return empty list&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (topic == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Isolate topic to ensure we have a single term&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; queryToken = topic.Split(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;char&lt;/span&gt;[] { &lt;span style="color: rgb(0, 96, 128);"&gt;'&amp;amp;'&lt;/span&gt; }).FirstOrDefault();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Submit async query requests and process responses in parallel&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     List&amp;lt;Story&amp;gt;[] queryResults = await Task.WhenAll(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         ExecuteDiggQuery(queryToken),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         ExecuteDeliciousQuery(queryToken));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Aggregate results from digg and delicious&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;foreach&lt;/span&gt; (List&amp;lt;Story&amp;gt; queryResult &lt;span style="color: rgb(0, 0, 255);"&gt;in&lt;/span&gt; queryResults)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         result.AddRange(queryResult);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;That’s all we need for the controller – next is just to host it and then run it.&lt;/p&gt;

&lt;h1&gt;Hosting the Controller&lt;/h1&gt;

&lt;p&gt;As usual we use a simple command line program for hosting the ApiController and it follows the usual pattern seen in the other blogs:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     var baseAddress = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080/&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     HttpSelfHostServer server = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create configuration&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         var config = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostConfiguration(baseAddress);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Add a route&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         config.Routes.MapHttpRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;           name: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;default&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;           routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;api/{controller}/{id}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;           defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { controller = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;, id = RouteParameter.Optional });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create server&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         server = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostServer(config);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Start server&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         server.OpenAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Hit ENTER to exit&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         Console.ReadLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;finally&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (server != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;             server.CloseAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Trying it Out&lt;/h1&gt;

&lt;p&gt;To try it out it is useful to use &lt;a href="http://www.fiddler2.com"&gt;Fiddler&lt;/a&gt; as it allows you to see both the incoming and outgoing requests. In the screen capture below we use fiddler to directly compose a request to our localhost ApiController. To the left we can see the two requests to digg and delicious respectively and in the right lower corner you can see the result with parts coming from digg and parts coming from delicious.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8737.MashupResult_5F00_68E37175.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="MashupResult" border="0" alt="MashupResult" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/0714.MashupResult_5F00_thumb_5F00_75711E91.png" width="604" height="382" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f9089b2b-d96f-453f-af1e-6afa0ac362cc" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/http" rel="tag"&gt;http&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/httpclient" rel="tag"&gt;httpclient&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10277154" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/REST/">REST</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item><item><title>Asynchronous File Upload using ASP.NET Web API</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx</link><pubDate>Thu, 01 Mar 2012 09:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10272905</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10272905</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx#comments</comments><description>&lt;p&gt;HTML Form File upload (defined in &lt;a href="http://www.faqs.org/rfcs/rfc1867.html"&gt;RFC 1867&lt;/a&gt;) is a classic mechanism for uploading content to a Web server and is supported by all browsers that I am aware of. This blog shows how to handle Form File Upload in &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; asynchronously using the &lt;a href="http://msdn.microsoft.com/library/dd460693.aspx"&gt;Task-based pattern&lt;/a&gt; introduced in .NET 4 and enhanced in .NET 4.5.&lt;/p&gt;  &lt;p&gt;Using ASP.NET Web API you can upload files of any size when self hosted (well, up to &lt;a href="http://msdn.microsoft.com/library/system.int64.maxvalue.aspx"&gt;System.Int64.MaxValue&lt;/a&gt; which in practice is “any size”). ASP.NET has a maximum limit of 2G in terms of file size that you can upload.&lt;/p&gt;  &lt;h1&gt;What is HTML File Upload?&lt;/h1&gt;  &lt;p&gt;Let’s first remind ourselves what HTML File Upload is. If you don’t need to brush up on HTML file upload then you can just skip to the next section…&lt;/p&gt;  &lt;p&gt;You enable support for HTML File Upload in an &lt;a href="http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.3"&gt;HTML form&lt;/a&gt; by using the &lt;a href="http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13.4"&gt;attribute enctype=”multipart/form-data”&lt;/a&gt; and then have a &lt;a href="http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.4"&gt;input field&lt;/a&gt; of type “file” like this: &lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;DOCTYPE&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;HTML&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;PUBLIC&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;quot;-//W3C//DTD HTML 4.01 Transitional//EN&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;html&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;head&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;title&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;File Upload Sample&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;title&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;head&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;body&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;form&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;action&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://localhost:8080/api/upload&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;enctype&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;&lt;font style="background-color: rgb(255, 255, 0);"&gt;multipart/form-data&lt;/font&gt;&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;method&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;POST&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     What is your name?&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;&lt;font style="background-color: rgb(0, 255, 0);"&gt;submitter&lt;/font&gt;&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;size&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;40&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;br&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     What file are you uploading?&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;&lt;font style="background-color: rgb(0, 255, 0);"&gt;data&lt;/font&gt;&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;size&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;40&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;&lt;font style="background-color: rgb(255, 255, 0);"&gt;file&lt;/font&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;br&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;submit&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;form&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;body&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;html&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This will cause all the data to be encoded using MIME multipart as follows when submitted in an HTTP POST request:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; Content-type: multipart/form-data, boundary=AaB03x&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; --AaB03x&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; content-disposition: form-data; name=&amp;quot;&lt;font style="background-color: rgb(0, 255, 0);"&gt;submitter&lt;/font&gt;&amp;quot;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; Henrik Nielsen&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; --AaB03x&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt; content-disposition: form-data ; name=&amp;quot;&lt;font style="background-color: rgb(0, 255, 0);"&gt;data&lt;/font&gt;&amp;quot;; filename=&amp;quot;file1.txt&amp;quot;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt; Content-Type: text/plain&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;  ... contents of file1.txt ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt; --AaB03x--&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Note how the input field &lt;font style="background-color: rgb(0, 255, 0);"&gt;names&lt;/font&gt; in the form are mapped to a &lt;a href="http://www.faqs.org/rfcs/rfc6266.html"&gt;Content-Disposition&lt;/a&gt; header in the MIME multipart message. Each form field such as the &lt;strong&gt;submitter&lt;/strong&gt; field above is encoded as its own MIME body part (that is the term for each segment between the boundaries -- above it is the string –&lt;strong&gt;AaB03x&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;In HTML5 many browsers support upload of multiple files within a single form submission using the &lt;font style="background-color: rgb(223, 206, 4);"&gt;multiple&lt;/font&gt; keyword:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;!&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;DOCTYPE&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;HTML&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;html&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;head&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;title&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;HTML5 Multiple File Upload Sample&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;title&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;head&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;body&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;form&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;action&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;http://localhost:8080/api/upload&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;enctype&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;multipart/form-data&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;method&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;POST&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     What is your name?&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;submitter&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;size&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;40&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;br&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     What files are you uploading?&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;data&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;=&lt;span style="color: rgb(255, 0, 0);"&gt;file&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;&lt;font style="background-color: rgb(223, 206, 4);"&gt;multiple&lt;/font&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;br&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;input&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0);"&gt;type&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;=&amp;quot;submit&amp;quot;&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;form&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;body&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;html&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The principle in submitting the data is the same as for HTML 4 but you can now select multiple files that each end up in their own MIME body part.&lt;/p&gt;

&lt;h1&gt;Creating an ApiController&lt;/h1&gt;

&lt;p&gt;First we create an ApiController that implements an HTTP POST action handling the file upload. Note that the action returns &lt;strong&gt;Task&amp;lt;T&amp;gt;&lt;/strong&gt; as we read the file asynchronously. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We use the new async/await keywords introduced in &lt;a href="http://www.microsoft.com/vstudio"&gt;Visual Studio 11 Beta&lt;/a&gt; but you can equally well use Tasks and the ContinueWith pattern already present in Visual Studio 2010.&lt;/p&gt;

&lt;p&gt;The first thing we do is check that the content is indeed &lt;strong&gt;“multipart/form-data”&lt;/strong&gt;. The second thing we do is creating a MultipartFormDataStreamProvider which gives you control over where the content ends up. In this case we save the file in the folder “c:\tmp\uploads”. It also contains information about the files stored.&lt;/p&gt;

&lt;p&gt;If you want complete control over how the file is written and what file name is used then you can derive from MultipartFormDataStreamProvider, override the functionality you want and use that StreamProvider instead. &lt;/p&gt;

&lt;p&gt;Once the read operation has completed we check the at is done we read the content asynchronously and when that task has completed we generate a response containing the submitter and the file names we use on the server, Obviously this is not a typical response but this is just so that you can see the information.&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; UploadController : ApiController&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; async Task&amp;lt;List&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt;&amp;gt; PostMultipartStream()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Verify that this is an HTML Form file upload request&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!Request.Content.IsMimeMultipartContent(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;form-data&amp;quot;&lt;/span&gt;))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseException(HttpStatusCode.UnsupportedMediaType);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create a stream provider for setting up output streams that saves the output under c:\tmp\uploads&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// If you want full control over how the stream is saved then derive from MultipartFormDataStreamProvider&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// and override what you need.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         MultipartFormDataStreamProvider streamProvider = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MultipartFormDataStreamProvider(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;c:\\tmp\\uploads&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Read the MIME multipart content using the stream provider we just created.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         IEnumerable&amp;lt;HttpContent&amp;gt; bodyparts = await Request.Content.ReadAsMultipartAsync(streamProvider);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// The submitter field is the entity with a Content-Disposition header field with a &amp;quot;name&amp;quot; parameter with value &amp;quot;submitter&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; submitter;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!bodyparts.TryGetFormFieldValue(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;submitter&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; submitter))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;             submitter = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;unknown&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Get a dictionary of local file names from stream provider.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// The filename parameters provided in Content-Disposition header fields are the keys.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// The local file names where the files are stored are the values.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;         IDictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt; bodyPartFileNames = streamProvider.BodyPartFileNames;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create response containing information about the stored files.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         List&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt; result = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;         result.Add(submitter);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;         IEnumerable&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt; localFiles = bodyPartFileNames.Select(kv =&amp;gt; kv.Value);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;         result.AddRange(localFiles);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;In the above code we added an extension method for getting the value of the submitter form field as a string. That extension method looks like this (don’t worry, we will integrate this better):&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; TryGetFormFieldValue(&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt; IEnumerable&amp;lt;HttpContent&amp;gt; contents, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; dispositionName, &lt;span style="color: rgb(0, 0, 255);"&gt;out&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; formFieldValue)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (contents == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;contents&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     HttpContent content = contents.FirstDispositionNameOrDefault(dispositionName);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (content != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         formFieldValue = content.ReadAsStringAsync().Result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     formFieldValue = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Hosting the Controller&lt;/h1&gt;

&lt;p&gt;In this example we build a simple console application for hosting the ApiController while setting the MaxReceivedMessageSize and TransferMode in the HttpSelfHostConfiguration. We then use a simple HTML form to point to the ApiController so that we can use a browser to upload a file. That HTML form can be hosted anywhere – here we just drop it into the folder &lt;strong&gt;C:\inetpub\wwwroot\Samples&lt;/strong&gt; and serve it using IIS.&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Program&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         var baseAddress = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080/&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         HttpSelfHostServer server = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Create configuration&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;             var config = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostConfiguration(baseAddress);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Set the max message size to 1M instead of the default size of 64k and also&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// set the transfer mode to 'streamed' so that don't allocate a 1M buffer but &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// rather just have a small read buffer.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;             config.MaxReceivedMessageSize = 1024 * 1024;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;             config.TransferMode = TransferMode.Streamed;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Add a route&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             config.Routes.MapHttpRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;               name: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;default&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;               routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;api/{controller}/{id}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;               defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { controller = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;, id = RouteParameter.Optional });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;             server = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostServer(config);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;             server.OpenAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Hit ENTER to exit&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;             Console.ReadLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;finally&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (server != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;                 server.CloseAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Trying it Out&lt;/h1&gt;

&lt;p&gt;Start the console application, then point your browser at the HTML form, for example &lt;strong&gt;&lt;a href="http://localhost/samples/uploadsample.html"&gt;http://localhost/samples/uploadsample.html&lt;/a&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Once you have uploaded a file you will find it in the folder &lt;strong&gt;c:\\tmp\uploads&lt;/strong&gt; and also get a content negotiated result which if asking for JSON looke like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[&amp;quot;henrik&amp;quot;,&amp;quot;c:\\tmp\\uploads\\sample.random&amp;quot;]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8c272dd4-85e8-4b3a-ac3d-53abd9997cca" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/http" rel="tag"&gt;http&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10272905" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/REST/">REST</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item><item><title>Async Streaming in ASP.NET Web API</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/02/24/async-actions-in-asp-net-web-api.aspx</link><pubDate>Fri, 24 Feb 2012 11:03:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10270897</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10270897</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/02/24/async-actions-in-asp-net-web-api.aspx#comments</comments><description>&lt;strike&gt;&lt;/strike&gt;  &lt;p&gt;ASP.NET Web API supports asynchronous actions using the new &lt;a href="http://msdn.microsoft.com/library/dd460693.aspx"&gt;Task-based programming model&lt;/a&gt; introduced in .NET 4. In .NET 4.5 the model has improved further and in addition is supported directly from C# using the new async and await keywords (see “&lt;a href="http://msdn.microsoft.com/en-us/vstudio/gg316360"&gt;Visual Studio Asynchronous Programming&lt;/a&gt;” for background). &lt;/p&gt;  &lt;p&gt;What this means is that you can have actions that look like this:&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Task&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[]&amp;gt; GetContent(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; topic)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;as well as &lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; GetContent(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; topic)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;and even this&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Task GetContent(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; topic)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     ...&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The benefit of writing Task-based actions is that you don’t block a thread on the server even if things take a long time to complete and that allows the server to scale better and be more responsive.&lt;/p&gt;

&lt;p&gt;In the blog “&lt;a href="http://blogs.msdn.com/b/henrikn/archive/2012/02/17/push-and-pull-streams-using-httpclient.aspx"&gt;Push and Pull Streams using HttpClient&lt;/a&gt;” we described how to use push and pull streams with HttpContent. As HttpRequestMessage, HttpResponseMesssage, and HttpContent apply to both client side (as part of HttpClient) as well as server side (as part of ASP.NET Web API) the push vs. pull model described in that blog applies equally well to the server side. &lt;/p&gt;

&lt;p&gt;In this blog we expand on the topic of reading request content using asynchronous streaming within an action.&lt;/p&gt;

&lt;h1&gt;Reading Request Body Asynchronously&lt;/h1&gt;

&lt;p&gt;In the first scenario we implement a POST action that takes a JSON entity body and writes it to another stream. Note that the action returns Task&amp;lt;HttpResponseMessage&amp;gt; which means that the action completes when the task completes. The important part of this action is line 11 where we copy the content from the request to another stream (we describe the SummaryStream below):&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Task&amp;lt;HttpResponseMessage&amp;gt; PostContent()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Verify that this is JSON content&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!Request.Content.IsJsonContent())&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseException(HttpStatusCode.UnsupportedMediaType);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Copy content asynchronously to our SummaryStream and return the continuation task&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     SummaryStream summaryStream = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; SummaryStream();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Request.Content.CopyToAsync(summaryStream).ContinueWith(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         (readTask) =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;             summaryStream.Close();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Check whether we completed successfully and generate response&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (readTask.IsCompleted)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.OK);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;else&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseMessage(HttpStatusCode.BadRequest);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;         });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;This is essentially all you have to do – the rest is just filler but if you want to dive in a little more then keep going! The first thing the action does is checking that the content is actually JSON. To do this we use a little extension method that we have added for this purpose:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// Determines whether the specified content has an JSON media type of either &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;c&amp;gt;application/json&amp;lt;/c&amp;gt; or &amp;lt;c&amp;gt;text/json&amp;lt;/c&amp;gt;. &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;param name=&amp;quot;content&amp;quot;&amp;gt;The content.&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;returns&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;c&amp;gt;true&amp;lt;/c&amp;gt; if the specified content is XML with a media type of either &amp;lt;c&amp;gt;application/json&amp;lt;/c&amp;gt; or &amp;lt;c&amp;gt;text/json&amp;lt;/c&amp;gt;.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; IsJsonContent(&lt;span style="color: rgb(0, 0, 255);"&gt;this&lt;/span&gt; HttpContent content)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (content == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;content&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (content.Headers == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt; || content.Headers.ContentType == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;     MediaTypeHeaderValue contentType = content.Headers.ContentType;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         contentType.MediaType.Equals(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;, StringComparison.OrdinalIgnoreCase) ||&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         contentType.MediaType.Equals(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;text/json&amp;quot;&lt;/span&gt;, StringComparison.OrdinalIgnoreCase);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;To&amp;#160; see what is going on when reading the content we create a special stream called &lt;strong&gt;SummaryStream&lt;/strong&gt; that simply indicates when it gets called by writing to the console. You don’t have to use this but if you want to try it out then it looks like this:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// Sample stream that write how many characters were written to it.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;internal&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; SummaryStream : DelegatingStream&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; SummaryStream()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         : &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;(Stream.Null)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Flush()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Flushing stream...&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         _innerStream.Flush();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Write(&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] buffer, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; offset, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; count)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Writing {0} bytes SYNChronously...&amp;quot;&lt;/span&gt;, count);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;         _innerStream.Write(buffer, offset, count);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; WriteByte(&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Writing a single byte SYNChronously...&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;         _innerStream.WriteByte(&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; IAsyncResult BeginWrite(&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] buffer, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; offset, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; count, AsyncCallback callback, &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; state)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Writing {0} bytes ASYNChronously...&amp;quot;&lt;/span&gt;, count);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.BeginWrite(buffer, offset, count, callback, state);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Close()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Closing stream...&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;.Close();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The &lt;strong&gt;DelegatingStream&lt;/strong&gt; which &lt;strong&gt;SummaryStream&lt;/strong&gt; derives from is nothing more than delegating every call to the inner stream. It looks like this:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// Utility &amp;lt;see cref=&amp;quot;Stream&amp;quot;/&amp;gt; which delegates everything to an inner &amp;lt;see cref=&amp;quot;Stream&amp;quot;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;internal&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;abstract&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; DelegatingStream : Stream&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; Stream _innerStream;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; DelegatingStream(Stream innerStream)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         Contract.Assert(innerStream != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         _innerStream = innerStream;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanRead&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.CanRead; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanSeek&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.CanSeek; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanWrite&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;         get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.CanWrite; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; Length&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;         get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.Length; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; Position&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;         get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.Position; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;         set { _innerStream.Position = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; ReadTimeout&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum41"&gt;  41:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum42"&gt;  42:&lt;/span&gt;         get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.ReadTimeout; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum43"&gt;  43:&lt;/span&gt;         set { _innerStream.ReadTimeout = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum44"&gt;  44:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum45"&gt;  45:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum46"&gt;  46:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanTimeout&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum47"&gt;  47:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum48"&gt;  48:&lt;/span&gt;         get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.CanTimeout; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum49"&gt;  49:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum50"&gt;  50:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum51"&gt;  51:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; WriteTimeout&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum52"&gt;  52:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum53"&gt;  53:&lt;/span&gt;         get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.WriteTimeout; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum54"&gt;  54:&lt;/span&gt;         set { _innerStream.WriteTimeout = &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum55"&gt;  55:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum56"&gt;  56:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum57"&gt;  57:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Dispose(&lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; disposing)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum58"&gt;  58:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum59"&gt;  59:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (disposing)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum60"&gt;  60:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum61"&gt;  61:&lt;/span&gt;             _innerStream.Dispose();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum62"&gt;  62:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum63"&gt;  63:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;.Dispose(disposing);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum64"&gt;  64:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum65"&gt;  65:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum66"&gt;  66:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; Seek(&lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; offset, SeekOrigin origin)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum67"&gt;  67:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum68"&gt;  68:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.Seek(offset, origin);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum69"&gt;  69:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum70"&gt;  70:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum71"&gt;  71:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; Read(&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] buffer, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; offset, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; count)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum72"&gt;  72:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum73"&gt;  73:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.Read(buffer, offset, count);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum74"&gt;  74:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum75"&gt;  75:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum76"&gt;  76:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; IAsyncResult BeginRead(&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] buffer, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; offset, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; count, AsyncCallback callback, &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; state)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum77"&gt;  77:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum78"&gt;  78:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.BeginRead(buffer, offset, count, callback, state);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum79"&gt;  79:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum80"&gt;  80:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum81"&gt;  81:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; EndRead(IAsyncResult asyncResult)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum82"&gt;  82:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum83"&gt;  83:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.EndRead(asyncResult);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum84"&gt;  84:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum85"&gt;  85:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum86"&gt;  86:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; ReadByte()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum87"&gt;  87:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum88"&gt;  88:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.ReadByte();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum89"&gt;  89:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum90"&gt;  90:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum91"&gt;  91:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Flush()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum92"&gt;  92:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum93"&gt;  93:&lt;/span&gt;         _innerStream.Flush();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum94"&gt;  94:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum95"&gt;  95:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum96"&gt;  96:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; SetLength(&lt;span style="color: rgb(0, 0, 255);"&gt;long&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum97"&gt;  97:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum98"&gt;  98:&lt;/span&gt;         _innerStream.SetLength(&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum99"&gt;  99:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum100"&gt; 100:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum101"&gt; 101:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Write(&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] buffer, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; offset, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; count)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum102"&gt; 102:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum103"&gt; 103:&lt;/span&gt;         _innerStream.Write(buffer, offset, count);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum104"&gt; 104:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum105"&gt; 105:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum106"&gt; 106:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; IAsyncResult BeginWrite(&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt;[] buffer, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; offset, &lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; count, AsyncCallback callback, &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; state)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum107"&gt; 107:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum108"&gt; 108:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _innerStream.BeginWrite(buffer, offset, count, callback, state);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum109"&gt; 109:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum110"&gt; 110:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum111"&gt; 111:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; EndWrite(IAsyncResult asyncResult)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum112"&gt; 112:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum113"&gt; 113:&lt;/span&gt;         _innerStream.EndWrite(asyncResult);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum114"&gt; 114:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum115"&gt; 115:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum116"&gt; 116:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; WriteByte(&lt;span style="color: rgb(0, 0, 255);"&gt;byte&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum117"&gt; 117:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum118"&gt; 118:&lt;/span&gt;         _innerStream.WriteByte(&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum119"&gt; 119:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum120"&gt; 120:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Trying It Out&lt;/h1&gt;

&lt;p&gt;To run the sample we start it in self host as usual. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: &lt;/strong&gt;By default the max message size in self host is 64k so to accept larger request sizes we set it to 1M and also turn on streaming so that we don’t buffer the whole thing in memory at any point in time.&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     var baseAddress = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080/&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     HttpSelfHostServer server = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create configuration&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         var config = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostConfiguration(baseAddress);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Set the max message size to 1M instead of the default size of 64k and also&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// set the transfer mode to 'streamed' so that don't allocate a 1M buffer but &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// rather just have a small read buffer.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         config.MaxReceivedMessageSize = 1024 * 1024;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         config.TransferMode = TransferMode.Streamed;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Add a route&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         config.Routes.MapHttpRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;           name: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;default&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;           routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;api/{controller}/{id}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;           defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { controller = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt;, id = RouteParameter.Optional });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         server = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostServer(config);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;         server.OpenAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Hit ENTER to exit&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;         Console.ReadLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;finally&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (server != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;             server.CloseAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We then use Fiddler to submit an HTTP POST request with an JSON request body. That is, we open the Composer tab and fill in a POST request with whatever JSON content you want to submit:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4718.SaveJson_5F00_465303EA.png"&gt;&lt;img style="display: inline; background-image: none;" title="SaveJson" border="0" alt="SaveJson" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2577.SaveJson_5F00_thumb_5F00_6CB4E735.png" width="604" height="469" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The resulting output to the console shows that the data is written asynchronously to the SummaryStream:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4214.SummaryStreamOutput_5F00_255F9143.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="SummaryStreamOutput" border="0" alt="SummaryStreamOutput" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7851.SummaryStreamOutput_5F00_thumb_5F00_1E4054CB.png" width="404" height="142" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:962b76bd-ec8f-4340-9fdf-0185943b327c" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/http" rel="tag"&gt;http&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10270897" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/REST/">REST</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item><item><title>Using ASP.NET Web API with ASP.NET Web Forms</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/02/23/using-asp-net-web-api-with-asp-net-web-forms.aspx</link><pubDate>Thu, 23 Feb 2012 21:30:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10271811</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>17</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10271811</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/02/23/using-asp-net-web-api-with-asp-net-web-forms.aspx#comments</comments><description>&lt;p&gt;Several of the &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API tutorials&lt;/a&gt; (see for example &lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;“Your First ASP.NET Web API”&lt;/a&gt;) show how you can use ASP.NET Web API with MVC applications. However, you can equally well add a Web API to a &lt;a href="http://www.asp.net/web-forms"&gt;Web Form&lt;/a&gt; enabling the same Web API support as in MVC applications.&lt;/p&gt;  &lt;p&gt;To show how you do this, let’s build a Web Site from scratch and then add a Web API to it. We use the &lt;a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-web-developer-express"&gt;Visual Web Developer 2010 Express&lt;/a&gt; version of Visual Studio with &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API Beta&lt;/a&gt; installed.&lt;/p&gt;  &lt;p&gt;First we create a new &lt;strong&gt;ASP.NET Empty Web Site&lt;/strong&gt; and give it a reasonable name:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2500.NewWebSite_5F00_1A37AABA.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="NewWebSite" border="0" alt="NewWebSite" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/8688.NewWebSite_5F00_thumb_5F00_7007FCD1.png" width="604" height="419" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then we add an &lt;strong&gt;ASP.NET Folder&lt;/strong&gt; to hold our Web API implementation. We do this by adding an &lt;strong&gt;App_Code&lt;/strong&gt; folder as follows:&lt;/p&gt;  &lt;p align="center"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4812.NewAppCodeFolder_5F00_6CA22DA7.png"&gt;&lt;img style="display: inline; background-image: none;" title="NewAppCodeFolder" border="0" alt="NewAppCodeFolder" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4428.NewAppCodeFolder_5F00_thumb_5F00_50253BC7.png" width="604" height="446" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Next we add a &lt;strong&gt;Web API Controller Class&lt;/strong&gt; within the &lt;strong&gt;App_Code&lt;/strong&gt; folder using &lt;strong&gt;Add New Item&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Make sure the name ends in “Controller” and not “Controller&lt;strong&gt;1&lt;/strong&gt;” or similar.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2084.NewController_5F00_5D53031A.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="NewController" border="0" alt="NewController" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6786.NewController_5F00_thumb_5F00_64060C9D.png" width="604" height="419" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The newly created ValuesController illustrates a very basic Web API with support for HTTP GET, POST, PUT, and DELETE.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You may have to fix the namespace so that it doesn’t start with a &amp;quot;dot “.” (this is a bug):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4666.FixNamespace_5F00_0EDE70B0.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="FixNamespace" border="0" alt="FixNamespace" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/2313.FixNamespace_5F00_thumb_5F00_67A4277A.png" width="304" height="369" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Let’s leave the default ValuesController for now and instead add a route to the global route table so that we can route messages to the Web API.&lt;/p&gt;  &lt;p&gt;To do this, open the file &lt;strong&gt;Global.asax&lt;/strong&gt; in the project. Here we need to add two things:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;First we add a couple of import statements for &lt;strong&gt;System.Web.Routing&lt;/strong&gt; and &lt;strong&gt;System.Web.Http&lt;/strong&gt; to get the right name places&lt;/li&gt;    &lt;li&gt;Second we add a route entry in the global route table in the &lt;strong&gt;Application_Start&lt;/strong&gt; method&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;The two edits together look like this:&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &amp;lt;%@ Application Language=&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;C#&amp;quot;&lt;/span&gt; %&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; &amp;lt;%@ Import Namespace=&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;System.Web.Routing&amp;quot;&lt;/span&gt; %&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; &amp;lt;%@ Import Namespace=&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;System.Web.Http&amp;quot;&lt;/span&gt; %&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &amp;lt;script runat=&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Application_Start(&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; sender, EventArgs e) &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         RouteTable.Routes.MapHttpRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;             name: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;DefaultApi&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;             routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;api/{controller}/{id}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;             defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { id = System.Web.Http.RouteParameter.Optional }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         );&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;You are now ready to try it out so hit F5 and start it! &lt;/p&gt;

&lt;p&gt;To see what is going on you can use your browser to send a request to your controller. Typically you would use JavaScript AJAX calls (see for example the tutorial “&lt;a href="http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api"&gt;Your First ASP.NET Web API&lt;/a&gt;”) to invoke the ApiController but for GET you can also just use your browser and point it at the address “api/values” relative to the base address of your Web Site.&lt;/p&gt;

&lt;p&gt;For example, if your Web Site is running as&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a title="http://localhost:47836/WebSite1/" href="http://localhost:47836/WebSite1/"&gt;http://localhost:47836/WebSite1/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;then your values controller will be answering at &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a title="http://localhost:47836/WebSite1/" href="http://localhost:47836/WebSite1/api/values"&gt;http://localhost:47836/WebSite1&lt;strong&gt;/api/values&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In IE the default response will be returned as application/json which IE will ask whether you want to open or save. If you save the result and open it then see the JSON result &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;[&amp;quot;value1&amp;quot;,&amp;quot;value2&amp;quot;]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alternatively, if you use the address&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a title="http://localhost:47836/WebSite1/" href="http://localhost:47836/WebSite1/api/values/1"&gt;http://localhost:47836/WebSite1/api/values&lt;strong&gt;/1&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;then you will see only the first value&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&amp;quot;value&amp;quot;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s it – you now have a Web API running in your Web Site.&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:62c03541-d945-4e54-9a0a-2af24b4fd8bc" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/web" rel="tag"&gt;web&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10271811" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/REST/">REST</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item><item><title>ASP.NET Web API and HttpClient Available on NuGet</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/02/20/asp-net-web-api-and-httpclient-available-on-nuget.aspx</link><pubDate>Mon, 20 Feb 2012 19:35:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10269948</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>13</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10269948</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/02/20/asp-net-web-api-and-httpclient-available-on-nuget.aspx#comments</comments><description>&lt;p&gt;If you don’t need the full &lt;a href="http://www.microsoft.com/download/en/details.aspx?id=28942"&gt;ASP.NET MVC 4 installer&lt;/a&gt; with project and item templates for Visual Studio 2010 then you can download the various ASP.NET Web API packages directly from &lt;a href="http://nuget.org/"&gt;NuGet&lt;/a&gt; (see list of packages below). If you are new to &lt;a href="http://nuget.org/"&gt;NuGet&lt;/a&gt; then it is a Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects that use the .NET Framework (check out the &lt;a href="http://docs.nuget.org/docs/start-here/overview"&gt;NuGet overview&lt;/a&gt;).&lt;/p&gt;  &lt;h1&gt;NuGet Packages&lt;/h1&gt;  &lt;p&gt;Here are the relevant NuGet packages depending on what you want to build:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Web API hosted in ASP.NET:&lt;/strong&gt; &lt;a href="http://nuget.org/packages/AspNetWebApi"&gt;AspNetWebApi&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Self-hosted Web API:&lt;/strong&gt; &lt;a href="http://nuget.org/packages/AspNetWebApi.SelfHost"&gt;AspNetWebApi.Selfhost&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;HttpClient including XML and JSON formatters: &lt;/strong&gt;&lt;a href="http://nuget.org/packages/System.Net.Http.Formatting"&gt;System.Net.Http.Formatting&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;JsonValue for navigating and manipulating JSON: &lt;/strong&gt;&lt;a href="http://nuget.org/packages/System.Json"&gt;System.Json&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;h1&gt;Additional Information&lt;/h1&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://www.asp.net/whitepapers/mvc4-release-notes"&gt;Release notes&lt;/a&gt; for installation instructions and to find out what’s new.&lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API home&lt;/a&gt; complete with docs, samples, tutorials and videos.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Have fun!&lt;/p&gt;  &lt;p&gt;Henrik&lt;/p&gt;  &lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:266a9684-b8b3-4b85-9813-dbdd5b9ff879" class="wlWriterEditableSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/httpclient" rel="tag"&gt;httpclient&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10269948" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/REST/">REST</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item><item><title>Using MongoDB with ASP.NET Web API</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/02/19/using-web-api-with-mongodb.aspx</link><pubDate>Sun, 19 Feb 2012 06:53:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10269429</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10269429</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/02/19/using-web-api-with-mongodb.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.mongodb.org/"&gt;MongoDB&lt;/a&gt; is a popular &lt;a href="http://en.wikipedia.org/wiki/NoSQL"&gt;NoSQL database&lt;/a&gt; that makes it a great backend for Web APIs which lend themselves towards a &lt;a href="http://en.wikipedia.org/wiki/Document-oriented_database"&gt;document store&lt;/a&gt; rather than a &lt;a href="http://en.wikipedia.org/wiki/Relational_database"&gt;relational store&lt;/a&gt;. In this blog we show how you can use &lt;a href="http://www.mongodb.org/"&gt;MongoDB&lt;/a&gt; with &lt;a href="http://www.asp.net/web-api"&gt;ASP.NET Web API&lt;/a&gt; to build an ApiController with support for HTTP GET, PUT, POST, and DELETE. Our sample controller is a simple contact manager Web API which builds on many of the same concepts as in the tutorial “&lt;a href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/creating-a-web-api-that-supports-crud-operations"&gt;Creating a Web API that Supports CRUD Operations&lt;/a&gt;” so I would recommend that you skim that for background. &lt;/p&gt;  &lt;p&gt;In particular, the URI patterns are very similar to that of the tutorial:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="500" align="center"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="133"&gt;&lt;strong&gt;Action&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="133"&gt;&lt;strong&gt;HTTP Method&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="133"&gt;&lt;strong&gt;Relative URI&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;Get a list of all contacts&lt;/td&gt;        &lt;td valign="top" width="133"&gt;GET&lt;/td&gt;        &lt;td valign="top" width="133"&gt;/api/contacts&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;Get a filtered list of all contacts&lt;/td&gt;        &lt;td valign="top" width="133"&gt;GET&lt;/td&gt;        &lt;td valign="top" width="133"&gt;/api/contacts?$top=2&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;Get a contacts by ID&lt;/td&gt;        &lt;td valign="top" width="133"&gt;GET&lt;/td&gt;        &lt;td valign="top" width="133"&gt;/api/contacts/id&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;Create a new contact&lt;/td&gt;        &lt;td valign="top" width="133"&gt;POST&lt;/td&gt;        &lt;td valign="top" width="133"&gt;/api/contacts&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;Update a contact&lt;/td&gt;        &lt;td valign="top" width="133"&gt;PUT&lt;/td&gt;        &lt;td valign="top" width="133"&gt;/api/contacts/id&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="133"&gt;Delete a contact&lt;/td&gt;        &lt;td valign="top" width="133"&gt;DELETE&lt;/td&gt;        &lt;td valign="top" width="133"&gt; /api/contacts/id&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;However, there are two differences worth noting:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;We host the sample ApiController in selfhost with a base URI of &lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;We have added support for &lt;a href="http://www.odata.org/developers/protocols/uri-conventions#QueryStringOptions"&gt;OData-style queries&lt;/a&gt; on GET requests so that you can filter the set of contacts returned using $top, $skip, etc.&lt;/li&gt;  &lt;/ol&gt;  &lt;p&gt;But I am getting ahead of myself – let’s get back to building the controller… &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Please see &lt;a href="http://blogs.msdn.com/b/webdev/archive/2012/08/26/asp-net-web-api-and-httpclient-samples.aspx"&gt;List of ASP.NET Web API and HttpClient Samples&lt;/a&gt; for the complete sample solution. Note that you still have to set up the MongoDB as described in the next section.&lt;/p&gt;  &lt;h1&gt;Prerequisites&lt;/h1&gt;  &lt;p&gt;Before you start you obviously need to download and install &lt;a href="http://www.mongodb.org/"&gt;MongoDB&lt;/a&gt;. I followed the &lt;a href="http://www.mongodb.org/display/DOCS/Quickstart+Windows"&gt;quick start instructions&lt;/a&gt; which has all the information you need and got me going in 10 minutes or so.&lt;/p&gt;  &lt;p&gt;Second you need the MongoDB driver for C#. Here we use the &lt;a href="http://www.mongodb.org/display/DOCS/CSharp+Language+Center"&gt;MongoDB C# driver&lt;/a&gt; provided by &lt;a href="https://www.10gen.com/"&gt;10gen&lt;/a&gt; and which is available as a &lt;a href="http://nuget.org/packages/mongocsharpdriver"&gt;NuGet package&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;As an optional third step once your MongoDB installation has been set up you can use a tool like &lt;a href="http://www.mongovue.com/MongoVUE"&gt;MongoVUE&lt;/a&gt; which allows you to browse and interact directly with the data in a MongoDB database.&lt;/p&gt;  &lt;h1&gt;Defining the Contact Type &lt;/h1&gt;  &lt;p&gt;We use the same basic Contact type used in “&lt;a href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/creating-a-web-api-that-supports-crud-operations"&gt;Creating a Web API that Supports CRUD Operations&lt;/a&gt;” but decorate it with an BsonIdAttribute (see the &lt;a href="http://api.mongodb.org/csharp/1.0/index.html"&gt;Mongo C# driver reference documentation&lt;/a&gt; for details) indicating which field is the id:&lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Contact&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     [BsonId]&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Id { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Phone { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; Email { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; DateTime LastModified { get; set; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;Using &lt;a href="http://www.mongovue.com/MongoVUE"&gt;MongoVUE&lt;/a&gt; we can see how Contact instances show up in the MongoDB database. The sample Contact data we use in this sample looks something like this &lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/0702.MongoVUE_5F00_2797C48C.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="MongoVUE" border="0" alt="MongoVUE" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/7536.MongoVUE_5F00_thumb_5F00_39082564.png" width="604" height="469" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;Defining the Contact Repository&lt;/h1&gt;

&lt;p&gt;We use the common &lt;a href="http://msdn.microsoft.com/en-us/library/ff649690.aspx"&gt;repository pattern&lt;/a&gt; to interact with the backend data source so the next step is to define the shape of the repository. We do this by defining an IContactRepository interface which we then implement so that it targets MongoDB. First, the interface is defined like this:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;interface&lt;/span&gt; IContactRepository&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     IEnumerable&amp;lt;Contact&amp;gt; GetAllContacts();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     Contact GetContact(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;     Contact AddContact(Contact item);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; RemoveContact(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; UpdateContact(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id, Contact item);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Implementing the Repository&lt;/h1&gt;

&lt;p&gt;It’s when implementing IContactRepository that we use the &lt;a href="http://api.mongodb.org/csharp/1.0/index.html"&gt;MongoDB C# driver API&lt;/a&gt; to connect to the data and to do the various CRUD operations defined by IContactRepository. First we set up the connection to database and get a Contact collection. By default we use the connection string “mongodb://localhost:27017” pointing at the localhost database we set up above. &lt;/p&gt;

&lt;p&gt;For the purpose of this sample we also reset the database and add some default entries so we have something to start with. Note that &lt;a href="http://www.mongodb.org/display/DOCS/CSharp+Driver+Tutorial#CSharpDriverTutorial-Threadsafety"&gt;the classes MongoServer, MongoDatabase, and MongoCollection&amp;lt;T&amp;gt; are all thread-safe&lt;/a&gt; so they can be used simultaneously by separate threads.&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; ContactRepository(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; connection)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.IsNullOrWhiteSpace(connection))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         connection = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;mongodb://localhost:27017&amp;quot;&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     _server = MongoServer.Create(connection);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     _database = _server.GetDatabase(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Contacts&amp;quot;&lt;/span&gt;, SafeMode.True);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     _contacts = _database.GetCollection&amp;lt;Contact&amp;gt;(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;contacts&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 128, 0);"&gt;// Reset database and add some default entries&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     _contacts.RemoveAll();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;for&lt;/span&gt; (&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt; index = 1; index &amp;lt; 5; index++)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         Contact contact1 = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Contact&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;             Email = &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;test{0}@example.com&amp;quot;&lt;/span&gt;, index),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;             Name = &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;test{0}&amp;quot;&lt;/span&gt;, index),&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             Phone = &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;{0}{0}{0} {0}{0}{0} {0}{0}{0}{0}&amp;quot;&lt;/span&gt;, index)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         };&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         AddContact(contact1);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;We now add the actual CRUD implementations as follows:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; IEnumerable&amp;lt;Contact&amp;gt; GetAllContacts()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _contacts.FindAll();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Contact GetContact(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     IMongoQuery query = Query.EQ(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;_id&amp;quot;&lt;/span&gt;, id);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _contacts.Find(query).FirstOrDefault();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Contact AddContact(Contact item)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     item.Id = ObjectId.GenerateNewId().ToString();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     item.LastModified = DateTime.UtcNow;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;     _contacts.Insert(item);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; item;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; RemoveContact(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     IMongoQuery query = Query.EQ(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;_id&amp;quot;&lt;/span&gt;, id);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     SafeModeResult result = _contacts.Remove(query);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; result.DocumentsAffected == 1;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; UpdateContact(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id, Contact item)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;     IMongoQuery query = Query.EQ(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;_id&amp;quot;&lt;/span&gt;, id);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;     item.LastModified = DateTime.UtcNow;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;     IMongoUpdate update = Update&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         .Set(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Email&amp;quot;&lt;/span&gt;, item.Email)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;         .Set(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;LastModified&amp;quot;&lt;/span&gt;, DateTime.UtcNow)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;         .Set(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Name&amp;quot;&lt;/span&gt;, item.Name)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;         .Set(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Phone&amp;quot;&lt;/span&gt;, item.Phone);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;     SafeModeResult result = _contacts.Update(query, update);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; result.UpdatedExisting;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Creating the Contact Controller&lt;/h1&gt;

&lt;p&gt;That’s it for the repository so we can now implement the actual ApiController. We base the implementation on the common pattern for supporting GET, PUT, POST, and DELETE as follows:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; ContactsController : ApiController&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; IContactRepository _contacts = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; ContactRepository();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; IQueryable&amp;lt;Contact&amp;gt; Get()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _contacts.GetAllContacts().AsQueryable();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Contact Get(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;         Contact contact = _contacts.GetContact(id);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (contact == &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseException(HttpStatusCode.NotFound);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; contact;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; Contact Post(Contact &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;         Contact contact = _contacts.AddContact(&lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; contact;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Put(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id, Contact &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!_contacts.UpdateContact(id, &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseException(HttpStatusCode.NotFound);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Delete(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; id)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (!_contacts.RemoveContact(id))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;throw&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpResponseException(HttpStatusCode.NotFound);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum41"&gt;  41:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum42"&gt;  42:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; We use IQueryable&amp;lt;Contact&amp;gt; as the return type of the Get() method. This enables automatic query-support using OData query syntax including &lt;strong&gt;$top&lt;/strong&gt; and &lt;strong&gt;$skip&lt;/strong&gt;. That is, if you use a URI like “/api/contacts?$top=2” with a “?$top=2” query component then you will only get the first two entries back.&lt;/p&gt;

&lt;h1&gt;Hosting the Controller&lt;/h1&gt;

&lt;p&gt;Now that we have the controller we can either host it in ASP or as selfhost. Here we use selfhost to host the controller in a simple console application but it would work exactly the same if hosted in ASP. As usual we create a HttpSelfHostConfiguration, add a route, then create a server, and start it:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     HttpSelfHostServer server = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Set up server configuration&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         HttpSelfHostConfiguration config = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostConfiguration(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         config.Routes.MapHttpRoute(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;             name: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;DefaultApi&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;             routeTemplate: &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;api/{controller}/{id}&amp;quot;&lt;/span&gt;,&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;             defaults: &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { id = RouteParameter.Optional }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;         );&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create server&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         server = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostServer(config);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Start listening&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;         server.OpenAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Hit ENTER to exit...&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;         Console.ReadLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;finally&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (server != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Stop listening&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;             server.CloseAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: In order to successfully start the selfhost server you have to run as admin (or &lt;a href="http://msdn.microsoft.com/library/windows/desktop/cc307236.aspx"&gt;configure http.sys with the appropriate URI prefix using netsh&lt;/a&gt;).&lt;/p&gt;

&lt;h1&gt;Trying out the Controller&lt;/h1&gt;

&lt;p&gt;When running the controller can be accessed using any HTTP client. In the full sample I show how to use HttpClient to do GET and POST but &lt;a href="http://www.fiddler2.com"&gt;Fiddler&lt;/a&gt; is often very useful for trying out various combinations of GET, PUT, POST, and DELETE by using the Composer tab manually to create requests. For example, you can create a POST request like this to insert a new Contact and then hit &lt;strong&gt;Execute&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/3108.AddContact_5F00_5E44CF94.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="AddContact" border="0" alt="AddContact" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/4505.AddContact_5F00_thumb_5F00_0FD03D2A.png" width="604" height="444" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Similarly you can create a GET request to ask for the two first entries which will yield a result like this where the response body contains the first two Contacts:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/6330.GetTopContactsResult_5F00_1D365030.png"&gt;&lt;img style="margin-right: auto; margin-left: auto; float: none; display: block; background-image: none;" title="GetTopContactsResult" border="0" alt="GetTopContactsResult" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-50-67-metablogapi/5353.GetTopContactsResult_5F00_thumb_5F00_67BD8E0A.png" width="604" height="459" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As mentioned above, when you modify the data you can track the contents of the MongoDB database using &lt;a href="http://www.mongovue.com/MongoVUE"&gt;MongoVUE&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Have fun!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:cf0fe07b-6e4f-4bf9-bf8c-9ab02eab21a5" class="wlWriterSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/httpclient" rel="tag"&gt;httpclient&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mongodb" rel="tag"&gt;mongodb&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10269429" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/REST/">REST</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/MongoDB/">MongoDB</category></item><item><title>Using JSON.NET with ASP.NET Web API</title><link>http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx</link><pubDate>Sat, 18 Feb 2012 00:10:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10269256</guid><dc:creator>Henrik F Nielsen</dc:creator><slash:comments>33</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.msdn.com/b/henrikn/rsscomments.aspx?WeblogPostID=10269256</wfw:commentRss><comments>http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://json.codeplex.com/"&gt;Json.Net&lt;/a&gt; is a popular framework for working with JSON. In particular, it has a bunch of features that are not supported by the &lt;a href="http://msdn.microsoft.com/library/system.runtime.serialization.json.datacontractjsonserializer.aspx"&gt;DataContractJsonSerializer&lt;/a&gt; such as being much more flexible in what kind of types it can serialize and exactly how they should be serialized. The ASP.NET Web API supports an open-ended set of formatters that can read and write data to and from any media type you want to support. For example, if you want to support the &lt;a href="http://tools.ietf.org/html/rfc6350"&gt;vCard format&lt;/a&gt; which has the media type text/vcard (previously it was text/directory) media type then you can write a formatter for vCard and register it for the media type (or types) in question. &lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: JSON.NET is now an integral part of ASP.NET Web API so you can just us it out of the box.&amp;#160; &lt;/p&gt;  &lt;p&gt;This sample shows how to hook in Json.Net as the default formatter replacing the built in DataContractJsonSerializer formatter (in the beta bits DataContractJsonSerializer is the default formatter). There are already a bunch of Json.Net formatters provided by the community that may well be more full-featured but this should allow you to get started.&lt;/p&gt;  &lt;h1&gt;Building the Formatter&lt;/h1&gt;  &lt;p&gt;The first thing we do is building the formatter. The key part of the formatter is to provide support for reading and writing content of a given media type. The sample formatter derives from the base MediaTypeFormatter class; we are working on a buffered media type formatter that will help working with lots of small reads and writes but for this sample the goal is to keep things simple. The formatter looks like this:&amp;#160;&amp;#160; &lt;/p&gt;  &lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;   &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;     &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; JsonNetFormatter : MediaTypeFormatter&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; JsonSerializerSettings _jsonSerializerSettings;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; JsonNetFormatter(JsonSerializerSettings jsonSerializerSettings)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         _jsonSerializerSettings = jsonSerializerSettings ?? &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; JsonSerializerSettings();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Fill out the mediatype and encoding we support&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;         SupportedMediaTypes.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; MediaTypeHeaderValue(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;application/json&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;         Encoding = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; UTF8Encoding(&lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanReadType(Type type)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (type == &lt;span style="color: rgb(0, 0, 255);"&gt;typeof&lt;/span&gt;(IKeyValueModel))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; CanWriteType(Type type)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; Task&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt;&amp;gt; OnReadFromStreamAsync(Type type, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create a serializer&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;         JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create task reading the content&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Task.Factory.StartNew(() =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (StreamReader streamReader = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StreamReader(stream, Encoding))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;                 &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (JsonTextReader jsonTextReader = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; JsonTextReader(streamReader))&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt;                 {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum41"&gt;  41:&lt;/span&gt;                     &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; serializer.Deserialize(jsonTextReader, type);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum42"&gt;  42:&lt;/span&gt;                 }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum43"&gt;  43:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum44"&gt;  44:&lt;/span&gt;         });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum45"&gt;  45:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum46"&gt;  46:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum47"&gt;  47:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; Task OnWriteToStreamAsync(Type type, &lt;span style="color: rgb(0, 0, 255);"&gt;object&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext, TransportContext transportContext)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum48"&gt;  48:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum49"&gt;  49:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create a serializer&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum50"&gt;  50:&lt;/span&gt;         JsonSerializer serializer = JsonSerializer.Create(_jsonSerializerSettings);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum51"&gt;  51:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum52"&gt;  52:&lt;/span&gt;         &lt;span style="color: rgb(0, 128, 0);"&gt;// Create task writing the serialized content&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum53"&gt;  53:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; Task.Factory.StartNew(() =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum54"&gt;  54:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum55"&gt;  55:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;using&lt;/span&gt; (JsonTextWriter jsonTextWriter = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; JsonTextWriter(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; StreamWriter(stream, Encoding)) { CloseOutput = &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt; })&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum56"&gt;  56:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum57"&gt;  57:&lt;/span&gt;                 serializer.Serialize(jsonTextWriter, &lt;span style="color: rgb(0, 0, 255);"&gt;value&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum58"&gt;  58:&lt;/span&gt;                 jsonTextWriter.Flush();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum59"&gt;  59:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum60"&gt;  60:&lt;/span&gt;         });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum61"&gt;  61:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum62"&gt;  62:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;h1&gt;Building a Sample ApiController&lt;/h1&gt;

&lt;p&gt;Next we need a controller to try things out. For illustrative purposes we create a type that would not serialize well with DataContractJsonSerializer but other than that this is a completely vanilla controller that knows nothing about serialization:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; HomeController : ApiController&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; HomeInfo Get()&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HomeInfo();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; HomeInfo&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; DateTime _created = DateTime.UtcNow;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;readonly&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt; _colorMap = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;         { 1, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;blue&amp;quot;&lt;/span&gt;},&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;         { 2, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;red&amp;quot;&lt;/span&gt; },&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;         { 3, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;green&amp;quot;&lt;/span&gt; },&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;         { 4, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;black&amp;quot;&lt;/span&gt; },&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;         { 5, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;white&amp;quot;&lt;/span&gt; },&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;     };&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; DateTime Created { get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _created; } }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;public&lt;/span&gt; IDictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;int&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt; ColorMap { get { &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; _colorMap; } }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;h1&gt;Hosting the Controller&lt;/h1&gt;

&lt;p&gt;Now that we have the controller we can host it in either ASP or as selfhost. In this case we selfhost the controller in a simple console application but it would work exactly the same if hosted in ASP. &lt;/p&gt;

&lt;p&gt;The first part is to configure the selfhost server and injecting the JsonNetFormatter as the first formatter in the configuration so that it becomes the default formatter. We also configure Json.Net to serialize &lt;a href="http://msdn.microsoft.com/library/system.datetime.aspx"&gt;DateTime&lt;/a&gt; types using ISO 8601 format instead of the more esoteric &amp;quot;/Date(1240718400000)/” format. The part of the console app that configures and starts the server looks like this:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Set up server configuration&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; HttpSelfHostConfiguration config = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostConfiguration(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt; config.Routes.MapHttpRoute(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Default&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;{controller}&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { controller = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt; });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create Json.Net formatter serializing DateTime using the ISO 8601 format&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt; JsonSerializerSettings serializerSettings = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; JsonSerializerSettings();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt; serializerSettings.Converters.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; IsoDateTimeConverter());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt; config.Formatters[0] = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; JsonNetFormatter(serializerSettings);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Create server&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt; server = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostServer(config);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;// Start listening&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt; server.OpenAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: In order to successfully start the selfhost server you have to run as admin (or &lt;a href="http://msdn.microsoft.com/library/windows/desktop/cc307236.aspx"&gt;configure http.sys with the appropriate URI prefix using netsh&lt;/a&gt;).&lt;/p&gt;

&lt;h1&gt;Trying it Out&lt;/h1&gt;

&lt;p&gt;Once the controller is running, we can access it using any HTTP client. In this case we use HttpClient to access it and print out the result to the console. If we put both the server configuration and the client in the same Main then we get something like this:&lt;/p&gt;

&lt;div style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 400px; background-color: rgb(244, 244, 244);" id="codeSnippetWrapper"&gt;
  &lt;div style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);" id="codeSnippet"&gt;
    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum1"&gt;   1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;class&lt;/span&gt; Program&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum2"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum3"&gt;   3:&lt;/span&gt;     &lt;span style="color: rgb(0, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; Main(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;[] args)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum4"&gt;   4:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum5"&gt;   5:&lt;/span&gt;         HttpSelfHostServer server = &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum6"&gt;   6:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum7"&gt;   7:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum8"&gt;   8:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Set up server configuration&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum9"&gt;   9:&lt;/span&gt;             HttpSelfHostConfiguration config = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostConfiguration(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum10"&gt;  10:&lt;/span&gt;             config.Routes.MapHttpRoute(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Default&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;{controller}&amp;quot;&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; { controller = &lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Home&amp;quot;&lt;/span&gt; });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum11"&gt;  11:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum12"&gt;  12:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Create Json.Net formatter serializing DateTime using the ISO 8601 format&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum13"&gt;  13:&lt;/span&gt;             JsonSerializerSettings serializerSettings = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; JsonSerializerSettings();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum14"&gt;  14:&lt;/span&gt;             serializerSettings.Converters.Add(&lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; IsoDateTimeConverter());&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum15"&gt;  15:&lt;/span&gt;             config.Formatters[0] = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; JsonNetFormatter(serializerSettings);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum16"&gt;  16:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum17"&gt;  17:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Create server&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum18"&gt;  18:&lt;/span&gt;             server = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpSelfHostServer(config);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum19"&gt;  19:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum20"&gt;  20:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Start listening&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum21"&gt;  21:&lt;/span&gt;             server.OpenAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum22"&gt;  22:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum23"&gt;  23:&lt;/span&gt;             &lt;span style="color: rgb(0, 128, 0);"&gt;// Create HttpClient, do an HTTP GET on the controller, and show the output&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum24"&gt;  24:&lt;/span&gt;             HttpClient client = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; HttpClient();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum25"&gt;  25:&lt;/span&gt;             client.GetAsync(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;http://localhost:8080&amp;quot;&lt;/span&gt;).ContinueWith(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum26"&gt;  26:&lt;/span&gt;                 (requestTask) =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum27"&gt;  27:&lt;/span&gt;                 {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum28"&gt;  28:&lt;/span&gt;                     &lt;span style="color: rgb(0, 128, 0);"&gt;// Get HTTP response from completed task.&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum29"&gt;  29:&lt;/span&gt;                     HttpResponseMessage response = requestTask.Result;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum30"&gt;  30:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum31"&gt;  31:&lt;/span&gt;                     &lt;span style="color: rgb(0, 128, 0);"&gt;// Check that response was successful or throw exception&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum32"&gt;  32:&lt;/span&gt;                     response.EnsureSuccessStatusCode();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum33"&gt;  33:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum34"&gt;  34:&lt;/span&gt;                     &lt;span style="color: rgb(0, 128, 0);"&gt;// Read response asynchronously as string and write out&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum35"&gt;  35:&lt;/span&gt;                     response.Content.ReadAsStringAsync().ContinueWith(&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum36"&gt;  36:&lt;/span&gt;                         (readTask) =&amp;gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum37"&gt;  37:&lt;/span&gt;                         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum38"&gt;  38:&lt;/span&gt;                             Console.WriteLine(readTask.Result);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum39"&gt;  39:&lt;/span&gt;                         });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum40"&gt;  40:&lt;/span&gt;                 });&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum41"&gt;  41:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum42"&gt;  42:&lt;/span&gt;             Console.WriteLine(&lt;span style="color: rgb(0, 96, 128);"&gt;&amp;quot;Hit ENTER to exit...&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum43"&gt;  43:&lt;/span&gt;             Console.ReadLine();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum44"&gt;  44:&lt;/span&gt;&amp;#160; &lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum45"&gt;  45:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum46"&gt;  46:&lt;/span&gt;         &lt;span style="color: rgb(0, 0, 255);"&gt;finally&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum47"&gt;  47:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum48"&gt;  48:&lt;/span&gt;             &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (server != &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum49"&gt;  49:&lt;/span&gt;             {&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum50"&gt;  50:&lt;/span&gt;                 &lt;span style="color: rgb(0, 128, 0);"&gt;// Stop listening&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum51"&gt;  51:&lt;/span&gt;                 server.CloseAsync().Wait();&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum52"&gt;  52:&lt;/span&gt;             }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum53"&gt;  53:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum54"&gt;  54:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;

    &lt;pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &amp;quot;Courier New&amp;quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);" id="lnum55"&gt;  55:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;The resulting output written to the console is&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;{&amp;quot;Created&amp;quot;:&amp;quot;2012-02-18T00:54:06.8447642Z&amp;quot;,&amp;quot;ColorMap&amp;quot;:{&amp;quot;1&amp;quot;:&amp;quot;blue&amp;quot;,&amp;quot;2&amp;quot;:&amp;quot;red&amp;quot;,&amp;quot;3&amp;quot;:&amp;quot;green&amp;quot;,&amp;quot;4&amp;quot;:&amp;quot;black&amp;quot;,&amp;quot;5&amp;quot;:&amp;quot;white&amp;quot;}}&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Note the ISO date and the nice serialization of the dictionary!&lt;/p&gt;

&lt;p&gt;Henrik&lt;/p&gt;

&lt;div style="margin: 0px; padding: 0px; float: none; display: inline;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:f3bc024a-736f-497c-b33e-35e22f68c7d7" class="wlWriterSmartContent"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/asp.net" rel="tag"&gt;asp.net&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/webapi" rel="tag"&gt;webapi&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/mvc" rel="tag"&gt;mvc&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/rest" rel="tag"&gt;rest&lt;/a&gt;,&lt;a href="http://del.icio.us/popular/httpclient" rel="tag"&gt;httpclient&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10269256" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNetWebAPI/">AspNetWebAPI</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HttpClient/">HttpClient</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/HTTP/">HTTP</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/AspNet/">AspNet</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/REST/">REST</category><category domain="http://blogs.msdn.com/b/henrikn/archive/tags/WebAPI/">WebAPI</category></item></channel></rss>