<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Youssef M's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/youssefm/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/youssefm/feed.xml</link>
    <description>Helping computers make friends since 2008</description>
    <lastBuildDate>Thu, 09 Apr 2015 22:49:31 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Paging with ASP.NET Web API OData</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/paging-with-asp-net-web-api-odata</link>
      <pubDate>Tue, 19 Feb 2013 13:38:56 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2013/02/19/paging-with-asp-net-web-api-odata/</guid>
      <description><![CDATA[A common requirement for web applications is to expose partial results from a larger set of data....]]></description>
      <content:encoded><![CDATA[<p>A common requirement for web applications is to expose partial results from a larger set of data. Maybe you want your users to be able to browse through a collection of movies that they can stream. But you don't want to display all of the thousands of movie titles you have available, just the first twenty titles in the category the user is browsing through. This avoids overloading your users with information and avoids the significant performance and bandwidth costs associated with sending large chunks of data.</p>  <p>Now paging can be implemented in one of two ways:</p>  <ul>   <li>     <p>Client-driven paging:&#160; The client decides how big of a page it wants to display and asks the server for a page of that size. So in our previous example, the client would be saying &quot;Give me twenty comedies&quot;.</p>   </li>    <li>     <p>Server-driven paging: The client asks for a collection of entities, and the server sends back partial results as well as a link to use to retrieve more results. In our example, the client would be saying &quot;Give me comedies&quot; and the server would respond with &quot;Here are twenty comedies and here's how to get more of them&quot;.</p>   </li> </ul>  <p>The good news is that the OData support we're adding to Web API adds built-in support for both of these options.</p>  <h3>Client-driven paging</h3>  <p>The way to implement client-driven paging with Web API is to take advantage of OData's query syntax and the $top query option. $top lets a client ask for a particular number of entities. So all the client would have to do is turn on Web API query support with this attribute on your action:</p>  <div id="codeSnippetWrapper">   <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">     <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> [Queryable]</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> IQueryable&lt;Movie&gt; GetMovies</pre>
<!--CRLF--></div>
</div>

<p>To get the first twenty comedies, you could then make a GET request for the following URI:</p>

<p><a href="https://server/Movies?$filter=Genre%20eq%20'Comedy'&amp;$top=20">https://server/Movies?$filter=Genre eq 'Comedy'&amp;$top=20</a></p>

<p>The $filter query option is narrowing down our query to only consider movies that have a category . Since we're not specifying an ordering on the movies, the server will infer a stable ordering based on the entity key so the results would be ordered by the movie ID in this case.</p>

<p>Now this only gets us the first page of comedies. If we want the next page of comedies, we can use the $skip query option to ignore the comedies we've already displayed. So:</p>

<p><a href="https://server/Movies?$filter=Genre eq 'Comedy'&amp;$skip=20&amp;$top=20">https://server/Movies?$filter=Genre eq 'Comedy'&amp;$skip=20&amp;$top=20</a></p>

<p>Would display comedies 21-40, the next page we need to display.</p>

<p>A word of caution here: using $skip works great if your movie data isn't changing. But if you're inserting new movies into your database, it can cause movies to appear twice in your results. And if you're deleting movies, it can cause movies not to appear at all. If this is an issue for you, you should consider getting subsequent pages in a different way. You can use the properties you're ordering by and the value of these properties in the last entity of the current page to create a request that gets the next page. Let's demonstrate with an example. We've been ordering our movies by ID so far. So let's say we get the first page of comedies and the last comedy we get back has ID equal to 86. We could request the next page of comedies with a request for the following URI:</p>

<p><a href="https://server/Movies?$filter=Genre%20eq%20'Comedy'&amp;$top=20">https://server/Movies?$filter=Genre eq 'Comedy' and ID gt 86&amp;$top=20</a></p>

<p>This retrieves the first twenty comedies with an ID greater than 86, which is exactly what we need to display our second page. And even if new movies are inserted or movies are deleted, we'll avoid displaying the same movie twice or missing a movie.</p>

<h3>Server-driven paging</h3>

<p>In our previous examples, the client always needed to send &quot;$top=20&quot; to let the server know that it shouldn't send back more than twenty movies. But you can also choose to let the server control paging instead. You'll just need to slightly tweak your [Queryable] attribute like this:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> [Queryable(PageSize=20)]</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> IQueryable&lt;Movie&gt; GetMovies</pre>
<!--CRLF--></div>
</div>

<p>This limits the number of movies to send back to the client to 20. If the query for this action yields fewer than or exactly twenty results, then nothing happens and the results are sent as if there were no paging. But if the query yields more than twenty results, then the server will only send back the first twenty results and add a next page link to the response body to give the client a way to get the next page of links. So for a request to this URI:</p>

<p><a href="https://server/Movies?$filter=Genre eq 'Comedy'">https://server/Movies?$filter=Genre eq 'Comedy'</a></p>

<p>Here's what the response body might look like:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>   <span style="color: #006080">&quot;odata.metadata&quot;</span>:<span style="color: #006080">&quot;https://localhost:23645/api/$metadata#Movies&quot;</span>,<span style="color: #006080">&quot;value&quot;</span>:[</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>     {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>       <span style="color: #006080">&quot;ID&quot;</span>:17,<span style="color: #006080">&quot;Title&quot;</span>:<span style="color: #006080">&quot;Six Days Seven Nights&quot;</span>,<span style="color: #006080">&quot;ReleaseYear&quot;</span>:1998,<span style="color: #006080">&quot;Genre&quot;</span>:<span style="color: #006080">&quot;Comedy&quot;</span>,<span style="color: #006080">&quot;Rating&quot;</span>:2,<span style="color: #006080">&quot;Popularity&quot;</span>:6</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     },</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     ...</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>       <span style="color: #006080">&quot;ID&quot;</span>:57,<span style="color: #006080">&quot;Title&quot;</span>:<span style="color: #006080">&quot;Army of Darkness&quot;</span>,<span style="color: #006080">&quot;ReleaseYear&quot;</span>:1992,<span style="color: #006080">&quot;Genre&quot;</span>:<span style="color: #006080">&quot;Comedy&quot;</span>,<span style="color: #006080">&quot;Rating&quot;</span>:9,<span style="color: #006080">&quot;Popularity&quot;</span>:9</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>     }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>   ],<span style="color: #006080">&quot;odata.nextLink&quot;</span>:<span style="color: #006080">&quot;https://localhost:23645/api/Movies?$filter=Genre%20eq%20'Comedy'&amp;$skip=20&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum11" style="color: #606060">  11:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Notice that the next link that you see generated is based on $skip and is therefore subject to the same limitations as discussed earlier. The client can always choose to ignore this next page link and create one based on ordering instead.</p>

<h3>Using the $inlinecount query option</h3>

<p>So far, we've shown how clients can display pages of results in two different ways. It's fairly easy for clients to navigate to the next page by using the next page link or by generating one. And it's also fairly easy for clients to navigate to previous pages just be remembering the URI associated with the previous pages. But there is one additional piece of information that is very useful for paging in a web application: how many pages are there anyways?</p>

<p>This is where the $inlinecount query option comes in. $inlinecount can be applied to any query to get the server to send back the total number of entities matching the request. Let's see an example in action. For a request to this URI:</p>

<p><a href="https://server/Movies?$filter=Genre eq 'Comedy'&amp;$inlinecount=allpages">https://server/Movies?$filter=Genre eq 'Comedy'&amp;$inlinecount=allpages</a></p>

<p>We'd get back the following response body if we had a page size limit on the server:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span>   <span style="color: #006080">&quot;odata.metadata&quot;</span>:<span style="color: #006080">&quot;https://localhost:23645/api/$metadata#Movies&quot;</span>,<span style="color: #006080">&quot;odata.count&quot;</span>:<span style="color: #006080">&quot;799&quot;</span>,<span style="color: #006080">&quot;value&quot;</span>:[</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>     {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>       <span style="color: #006080">&quot;ID&quot;</span>:17,<span style="color: #006080">&quot;Title&quot;</span>:<span style="color: #006080">&quot;Six Days Seven Nights&quot;</span>,<span style="color: #006080">&quot;ReleaseYear&quot;</span>:1998,<span style="color: #006080">&quot;Genre&quot;</span>:<span style="color: #006080">&quot;Comedy&quot;</span>,<span style="color: #006080">&quot;Rating&quot;</span>:2,<span style="color: #006080">&quot;Popularity&quot;</span>:6</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     },</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     ...</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>       <span style="color: #006080">&quot;ID&quot;</span>:57,<span style="color: #006080">&quot;Title&quot;</span>:<span style="color: #006080">&quot;Army of Darkness&quot;</span>,<span style="color: #006080">&quot;ReleaseYear&quot;</span>:1992,<span style="color: #006080">&quot;Genre&quot;</span>:<span style="color: #006080">&quot;Comedy&quot;</span>,<span style="color: #006080">&quot;Rating&quot;</span>:9,<span style="color: #006080">&quot;Popularity&quot;</span>:9</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>     }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>   ],<span style="color: #006080">&quot;odata.nextLink&quot;</span>:<span style="color: #006080">&quot;https://localhost:23645/api/Movies?$filter=Genre%20eq%20'Comedy'&amp;$inlinecount=allpages&amp;$skip=20&quot;</span></pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum11" style="color: #606060">  11:</span> }</pre>
<!--CRLF--></div>
</div>

<p>We now have a count in our response body. This count represents the total number of comedies in the server's database. The client can use this information to infer the number of pages that can be displayed, like this for example:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> var numberOfPages = Math.ceiling(count / pageSize);</pre>
<!--CRLF--></div>
</div>

<div>In this case, we’d compute that since there are 799 comedies in our database and since we’re displaying 20 comedies per page, we’ll have 40 pages.</div>

<div>&#160;</div>

<div>Note that server-driven paging only works by default with the OData format. Marking a Queryable action with the PageSize attribute will still limit the results for vanilla XML and JSON formatters, but it won’t add a next page link or a count. It’s possible to use the PageResult&lt;T&gt; class to add that information for other formats as well. You can even implement an action filter that converts a response into a PageResult to automatically enable similar functionality in other formatters. Look out for a future blog post detailing how to do that.</div>

<div>&#160;</div>

<div>For more information about server-driven paging, take a look at <a href="https://aspnet.codeplex.com/SourceControl/changeset/view/83539ccd1c06#Samples/WebApi/ODataPagingSample/ReadMe.txt">this sample</a>. It demonstrates implementing server-driven paging for a collection of movies with Web API’s OData support. If you’re new to writing OData services with Web API, I’ve posted <a href="https://blogs.msdn.com/b/webdev/archive/2013/01/29/getting-started-with-asp-net-webapi-odata-in-3-simple-steps.aspx">a getting started guide over on the webdev blog</a> to help get you up and running.</div>]]></content:encoded>
    </item>
    <item>
      <title>Writing tests for an ASP.NET Web API service</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/writing-tests-for-an-asp-net-web-api-service</link>
      <pubDate>Mon, 28 Jan 2013 15:17:00 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2013/01/28/writing-tests-for-an-asp-net-web-api-service/</guid>
      <description><![CDATA[It's important to test any service you write to make sure that it's behaving the way you expect it...]]></description>
      <content:encoded><![CDATA[<p>It's important to test any service you write to make sure that it's behaving the way you expect it to. In this blog post, I'll go through the main ways of testing a Web API service, exploring the benefits and drawbacks of each option so that you can test your service effectively.</p>  <p>Web API testing can be broadly categorized into one of three groups:</p>  <ul>   <li>Unit testing a controller in isolation </li>    <li>Submitting a request to an in-memory HttpServer and testing the response you get back </li>    <li>Submitting a request to a running server over the network and testing the response you get back </li> </ul>  <h3>Unit Testing Controllers</h3>  <p>The first and simplest way of testing a Web API service is to unit test individual controllers. This means you'll first create an instance of the controller. And then call the Web API action you want to test with the parameters you want. Finally, you'll test that the action did what it was supposed to do, like updating a database for example and that it returned the expected value.</p>  <p>To illustrate the different ways of testing Web API services, let's use a simple example. Let's say you have an action that gets a movie by its ID. The action signature might look like this:</p>  <div id="codeSnippetWrapper">   <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">     <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> MoviesController : ApiController</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum3" style="color: #606060">   3:</span>     <span style="color: #0000ff">public</span> Movie GetMovie(<span style="color: #0000ff">int</span> id);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span> }</pre>
<!--CRLF--></div>
</div>

<p>Let's give this method the following contract. If the movie ID exists in our database, it should return the corresponding movie instance. But if there isn't a movie with a matching ID, it should return a response with a 404 Not Found status code. An example of a unit test for this action might look like this:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> [Fact]</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> GetMovie_ThrowsNotFound_WhenMovieNotFound()</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     var emptyDatabase = <span style="color: #0000ff">new</span> EmptyMoviesDbContext();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     var controller = <span style="color: #0000ff">new</span> MoviesController(emptyDatabase);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     HttpResponseException responseException = Assert.Throws&lt;HttpResponseException&gt;(() =&gt; controller.GetMovie(1));</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     Assert.Equal(HttpStatusCode.NotFound, responseException.Response.StatusCode);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span> }</pre>
<!--CRLF--></div>
</div>

<p>As a general principle, you should always try to test as little as possible and unit testing controllers is as simple as it gets.</p>

<h3>Submitting requests against an in-memory HttpServer</h3>

<p>Unit testing controllers is great, and you should be trying to do so whenever you can. But it does have its limitations. First off, Web API sets up state on the controller like the Request or the Configuration properties that may be needed for your action to function properly. It also sets properties on the request that are used by certain methods. Commonly used methods in the framework like Request.CreateResponse work fine in a normal Web API pipeline, but will not work when unit testing a controller unless you configure some additional properties.</p>

<p>Secondly, unit testing a controller doesn't cover everything else that might go wrong with your service. If you're using custom message handlers, routing, filters, parameter binders, or formatters, none of that is accounted for when unit testing. And even if you're using all the defaults, the request might never make it to your action or might result in your action being called with the wrong parameters. Unit testing doesn't help at all with this kind of issue.</p>

<p>And thirdly, unit testing doesn't always help you figure out what the HTTP response looks like. Maybe you really care about a certain HTTP header being set on the response or maybe you care about your response sending back the right status code to the client. If your action returns an HttpResponseMessage or throws an HttpResponseException like our example above, then you may be able to inspect and test the response. But otherwise, you won't get any insight into what response will actually be received by the client.</p>

<p>The recommended way to deal with all these issues is to set up an HttpServer, create a request you want to test, and submit it to the server. You can then test the response you get back and make sure it matches your expectations. One of the advantages of Web API's architecture is that you can do this without ever having to use the network. You can create an in-memory HttpServer and simply pass requests to it. It will simulate the processing of the request and return the same response you would have gotten if it were a live server.</p>

<p>Here's what the same unit test we wrote earlier would look like:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> [Fact]</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> GetMovie_ReturnsNotFound_WhenMovieNotFound()</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     HttpConfiguration config = <span style="color: #0000ff">new</span> HttpConfiguration();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     config.Routes.MapHttpRoute(<span style="color: #006080">&quot;Default&quot;</span>, <span style="color: #006080">&quot;{controller}/{id}&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     HttpServer server = <span style="color: #0000ff">new</span> HttpServer(config);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #0000ff">using</span> (HttpMessageInvoker client = <span style="color: #0000ff">new</span> HttpMessageInvoker(server))</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>     {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>         <span style="color: #0000ff">using</span> (HttpRequestMessage request = <span style="color: #0000ff">new</span> HttpRequestMessage(HttpMethod.Get, <span style="color: #006080">&quot;https://localhost/Movies/-1&quot;</span>))</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>         <span style="color: #0000ff">using</span> (HttpResponseMessage response = client.SendAsync(request, CancellationToken.None).Result)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>         {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>             Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>         }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>     };</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum15" style="color: #606060">  15:</span> }</pre>
<!--CRLF--></div>
</div>

<p>If you wanted to test the response body instead, you could use these lines:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> ObjectContent content = Assert.IsType&lt;ObjectContent&gt;(response.Content);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> Assert.Equal(expectedValue, content.Value);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> Assert.Equal(expectedFormatter, content.Formatter);</pre>
<!--CRLF--></div>
</div>

<h3>Submitting requests against a running HttpServer</h3>

<p>The last way to write a Web API test is to start a running server that's listening to a network port and send a request to that server. Usually, that involves starting up WebAPI's self-host server like this:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> [Fact]</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum2" style="color: #606060">   2:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> GetMovie_ReturnsNotFound_WhenMovieNotFound()</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum3" style="color: #606060">   3:</span> {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum4" style="color: #606060">   4:</span>     HttpSelfHostConfiguration config = <span style="color: #0000ff">new</span> HttpSelfHostConfiguration(<span style="color: #006080">&quot;https://localhost/&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum5" style="color: #606060">   5:</span>     config.Routes.MapHttpRoute(<span style="color: #006080">&quot;Default&quot;</span>, <span style="color: #006080">&quot;{controller}/{id}&quot;</span>);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum6" style="color: #606060">   6:</span>     <span style="color: #0000ff">using</span> (HttpSelfHostServer server = <span style="color: #0000ff">new</span> HttpSelfHostServer(config))</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum7" style="color: #606060">   7:</span>     <span style="color: #0000ff">using</span> (HttpClient client = <span style="color: #0000ff">new</span> HttpClient())</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum8" style="color: #606060">   8:</span>     {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum9" style="color: #606060">   9:</span>         server.OpenAsync().Wait();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum10" style="color: #606060">  10:</span>         <span style="color: #0000ff">using</span> (HttpRequestMessage request = <span style="color: #0000ff">new</span> HttpRequestMessage(HttpMethod.Get, <span style="color: #006080">&quot;https://localhost/Movies/-1&quot;</span>))</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum11" style="color: #606060">  11:</span>         <span style="color: #0000ff">using</span> (HttpResponseMessage response = client.SendAsync(request).Result)</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum12" style="color: #606060">  12:</span>         {</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum13" style="color: #606060">  13:</span>             Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum14" style="color: #606060">  14:</span>         }</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum15" style="color: #606060">  15:</span>         server.CloseAsync().Wait();</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4"><span id="lnum16" style="color: #606060">  16:</span>     };</pre>
<!--CRLF-->

    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum17" style="color: #606060">  17:</span> }</pre>
<!--CRLF--></div>
</div>

<p>To test the response body instead, you could write:</p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">
    <pre style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: &#39;Courier New&#39;, courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><span id="lnum1" style="color: #606060">   1:</span> Assert.Equal(expectedResponseBody, response.Content.ReadAsStringAsync().Result);</pre>
<!--CRLF--></div>
</div>

<p>If at all possible, you should try avoiding writing these kinds of tests. Instead of just testing the service, you're testing a whole lot more - you're testing the client, you're testing the operating system's networking stack, and you're testing the host for your service. Whenever you test more than you have to, you expose yourself to potential issues at other layers that can make test maintenance and debugging a nightmare. For example, you might now have to run your tests with administrator privileges for the self host server to open successfully.</p>

<p>Now with all that said, there may be cases where this kind of test is the most appropriate. If you need to test that a client and a server can communicate, it's usually better to test the client and the server individually. You can test that the client is sending the request you expect it to send, and then you can test that the server returns the expected response given that request. But there may be cases where the hosting actually matters and you need to make sure that the client request actually makes it to the Web API server correctly. The best example that comes to mind is if you're using SSL/TLS and you want to make sure that the connection is working. You might then write one test against a running server to check that the connection is working, and write the rest of your tests as unit tests or against an in-memory server to check that the service is handling requests the way you'd expect it to.</p>]]></content:encoded>
    </item>
    <item>
      <title>Building Real-time Web Apps with ASP.NET WebAPI and WebSockets</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/building-real-time-web-apps-with-asp-net-webapi-and-websockets</link>
      <pubDate>Tue, 17 Jul 2012 18:12:49 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2012/07/17/building-real-time-web-apps-with-asp-net-webapi-and-websockets/</guid>
      <description><![CDATA[WebSocket is a recent technology that provides two-way communication over a TCP connection. This...]]></description>
      <content:encoded><![CDATA[<p><font size="3" face="Calibri">WebSocket is a recent technology that provides two-way communication over a TCP connection. This allows us to create real-time web apps where servers can push data to clients. In this blog post, I’ll demonstrate how this can be done by building a simple chat app using ASP.NET WebAPI and ASP.NET’s new support for WebSockets in .NET 4.5.</font></p>  <p><font size="3" face="Calibri">Before we get started, there are a few requirements for using WebSockets. It must be supported by both the browser and the web server. The WebSocket protocol is currently supported in Chrome, Firefox, and Safari and will be supported in the upcoming Internet Explorer 10 release. On the server side of things, you will need Windows 8 (or Windows Server 2012) to support WebSockets. Now you may not always be able to guarantee that your client browser and your web server support WebSockets. If that’s your case, I highly recommend you take a look at <a href="https://signalr.net/">SignalR</a>. SignalR provides you with the abstraction of a real-time, persistent connection without having to worry about how the data is being sent back and forth between the browser and the server.</font></p>  <p><font size="3" face="Calibri">Now once you’ve met the requirements, you’ll need to enable support for WebSockets on IIS. You can do so by going through Control Panel &gt; Programs &gt; Turn Windows features on or off. You’ll then need to make sure the following boxes are checked:</font></p>  <ul>   <li><font size="3" face="Calibri">Internet Information Services &gt; World Wide Web Services &gt; Application Development Features &gt; ASP.NET 4.5</font></li>    <li><font size="3" face="Calibri">Internet Information Services &gt; World Wide Web Services &gt; Application Development Features &gt; WebSocket Protocol</font></li>    <li><font size="3" face="Calibri">.NET Framework 4.5 Advanced Services &gt; ASP.NET 4.5</font></li> </ul>  <p><font size="3" face="Calibri">Next, it’s time to write our app. Start by creating a new Empty ASP.NET MVC 4 App in Visual Studio 2012. Create a new HTML page called “chat.htm” with this in the body:</font></p>  <div id="codeSnippetWrapper">   <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">     <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">form</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;chatform&quot;</span> <span style="color: rgb(255, 0, 0);">action</span><span style="color: rgb(0, 0, 255);">=&quot;&quot;</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">input</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;inputbox&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">form</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span> <span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">=&quot;messages&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF--></div>
</div>
<font size="3" face="Calibri">
  <p>The HTML here is just a simple chat field to enter messages and a &lt;div&gt; to display our broadcast messages at. Next, let’s implement our client-side WebSocket functionality:</p>

  <p id="codeSnippetWrapper"></p>

  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> $(document).ready(<span style="color: rgb(0, 0, 255);">function</span> () {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">var</span> username = prompt(<span style="color: rgb(0, 96, 128);">'Please enter a username:'</span>);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>     <span style="color: rgb(0, 0, 255);">var</span> uri = <span style="color: rgb(0, 96, 128);">'ws://'</span> + window.location.hostname + window.location.pathname.replace(<span style="color: rgb(0, 96, 128);">'chat.htm'</span>, <span style="color: rgb(0, 96, 128);">'api/Chat'</span>) + <span style="color: rgb(0, 96, 128);">'?username='</span> + username;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>     websocket = <span style="color: rgb(0, 0, 255);">new</span> WebSocket(uri);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>     websocket.onopen = <span style="color: rgb(0, 0, 255);">function</span> () {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>         $(<span style="color: rgb(0, 96, 128);">'#messages'</span>).prepend(<span style="color: rgb(0, 96, 128);">'&lt;div&gt;Connected.&lt;/div&gt;'</span>);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span>         $(<span style="color: rgb(0, 96, 128);">'#chatform'</span>).submit(<span style="color: rgb(0, 0, 255);">function</span> (event) {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span>             websocket.send($(<span style="color: rgb(0, 96, 128);">'#inputbox'</span>).val());</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: rgb(96, 96, 96);">  13:</span>             $(<span style="color: rgb(0, 96, 128);">'#inputbox'</span>).val(<span style="color: rgb(0, 96, 128);">''</span>);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum14" style="color: rgb(96, 96, 96);">  14:</span>             event.preventDefault();</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: rgb(96, 96, 96);">  15:</span>         });</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum16" style="color: rgb(96, 96, 96);">  16:</span>     };</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: rgb(96, 96, 96);">  17:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum18" style="color: rgb(96, 96, 96);">  18:</span>     websocket.onerror = <span style="color: rgb(0, 0, 255);">function</span> (event) {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: rgb(96, 96, 96);">  19:</span>         $(<span style="color: rgb(0, 96, 128);">'#messages'</span>).prepend(<span style="color: rgb(0, 96, 128);">'&lt;div&gt;ERROR&lt;/div&gt;'</span>);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum20" style="color: rgb(96, 96, 96);">  20:</span>     };</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: rgb(96, 96, 96);">  21:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum22" style="color: rgb(96, 96, 96);">  22:</span>     websocket.onmessage = <span style="color: rgb(0, 0, 255);">function</span> (event) {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: rgb(96, 96, 96);">  23:</span>         $(<span style="color: rgb(0, 96, 128);">'#messages'</span>).prepend(<span style="color: rgb(0, 96, 128);">'&lt;div&gt;'</span> + event.data + <span style="color: rgb(0, 96, 128);">'&lt;/div&gt;'</span>);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum24" style="color: rgb(96, 96, 96);">  24:</span>     };</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: rgb(96, 96, 96);">  25:</span> });</pre>
<!--CRLF--></div>

  
</font>

<p><font size="3" face="Calibri">This JavaScript depends on the JQuery library. Note how we’re sending a username in the query string for our initial web socket, and note how we’re sending messages over the websocket whenever a message is submitted, and that we display messages received over the websocket as well. Now it’s time to implement our server-side WebSocket handler.</font></p>

<p><font size="3" face="Calibri">First, let’s make sure that the right route is configured for WebAPI to receive the WebSocket upgrade request. You’ll need to run this command in your Application_Start method:</font></p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> routes.MapHttpRoute(</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>     name: <span style="color: rgb(0, 96, 128);">&quot;DefaultApi&quot;</span>,</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     routeTemplate: <span style="color: rgb(0, 96, 128);">&quot;api/{controller}/{id}&quot;</span>,</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     defaults: <span style="color: rgb(0, 0, 255);">new</span> { id = RouteParameter.Optional }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span> );</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">If you’re using an empty MVC project template, this should already be there for you in RouteConfig.cs. Next, let’s implement our WebAPI controller:</font></p>

<div id="codeSnippetWrapper"></div>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> ChatController : ApiController</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">public</span> HttpResponseMessage Get(<span style="color: rgb(0, 0, 255);">string</span> username)</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>         HttpContext.Current.AcceptWebSocketRequest(<span style="color: rgb(0, 0, 255);">new</span> ChatWebSocketHandler(username));</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>         <span style="color: rgb(0, 0, 255);">return</span> Request.CreateResponse(HttpStatusCode.SwitchingProtocols);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>     }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>     <span style="color: rgb(0, 0, 255);">class</span> ChatWebSocketHandler : WebSocketHandler</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span>     {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum11" style="color: rgb(96, 96, 96);">  11:</span>         <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">static</span> WebSocketCollection _chatClients = <span style="color: rgb(0, 0, 255);">new</span> WebSocketCollection();</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum12" style="color: rgb(96, 96, 96);">  12:</span>         <span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">string</span> _username;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum13" style="color: rgb(96, 96, 96);">  13:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum14" style="color: rgb(96, 96, 96);">  14:</span>         <span style="color: rgb(0, 0, 255);">public</span> ChatWebSocketHandler(<span style="color: rgb(0, 0, 255);">string</span> username)</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum15" style="color: rgb(96, 96, 96);">  15:</span>         {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum16" style="color: rgb(96, 96, 96);">  16:</span>             _username = username;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum17" style="color: rgb(96, 96, 96);">  17:</span>         }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum18" style="color: rgb(96, 96, 96);">  18:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum19" style="color: rgb(96, 96, 96);">  19:</span>         <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">void</span> OnOpen()</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum20" style="color: rgb(96, 96, 96);">  20:</span>         {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum21" style="color: rgb(96, 96, 96);">  21:</span>             _chatClients.Add(<span style="color: rgb(0, 0, 255);">this</span>);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum22" style="color: rgb(96, 96, 96);">  22:</span>         }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum23" style="color: rgb(96, 96, 96);">  23:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum24" style="color: rgb(96, 96, 96);">  24:</span>         <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">void</span> OnMessage(<span style="color: rgb(0, 0, 255);">string</span> message)</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum25" style="color: rgb(96, 96, 96);">  25:</span>         {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum26" style="color: rgb(96, 96, 96);">  26:</span>             _chatClients.Broadcast(_username + <span style="color: rgb(0, 96, 128);">&quot;: &quot;</span> + message);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum27" style="color: rgb(96, 96, 96);">  27:</span>         }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum28" style="color: rgb(96, 96, 96);">  28:</span>     }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum29" style="color: rgb(96, 96, 96);">  29:</span> }</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">Our controller has just one method, Get, which listens for WebSocket upgrade requests. Since the initial upgrade handshake for WebSockets looks just like an HTTP request/response, this allows us to go through the entire WebAPI pipeline just as if it were any other HTTP request/response. This means for example that message handlers will run, action filters get called, and model binding lets us bind the request to action parameters. In the example above, we’ve bound the username from the query string as an action parameter. The Get action then does two things. It first accepts the web socket request and sets up a WebSocketHandler to manage the connection. It then sends back a response with HTTP status code 101, notifying the client that is has in fact agreed to switch to the WebSocket protocol. The ChatWebSocketHandler then just takes care of managing a list of chat clients and broadcasting the message to all clients when it receives a message. So we’re able to have WebAPI handle the initial WebSocket upgrade request and create a web socket handler to manage the lifetime of the connection.</font></p>

<p><font size="3" face="Calibri">You’ll need the <a href="https://nuget.org/packages/Microsoft.WebSockets">Microsoft.WebSockets NuGet package</a> to be able to build the controller above. </font><font size="3" face="Calibri">Note that because of limitations of the WebSocket feature, you’ll need to deploy the app to IIS or IIS Express. This won’t work in the Visual Studio Development Server. Finally, you’ll need this in your Web.config to get WebSockets working:</font></p>

<div id="codeSnippetWrapper">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">configuration</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span>   <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">appSettings</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">add</span> <span style="color: rgb(255, 0, 0);">key</span><span style="color: rgb(0, 0, 255);">=&quot;aspnet:UseTaskFriendlySynchronizationContext&quot;</span> <span style="color: rgb(255, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">=&quot;true&quot;</span> <span style="color: rgb(0, 0, 255);">/&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>   <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">appSettings</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span> <span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">configuration</span><span style="color: rgb(0, 0, 255);">&gt;</span></pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">And there you go, you should be able to deploy your app to IIS and test your chat app. You can try opening multiple browser windows to see chat messages broadcast in real-time to all the chat clients.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Error Handling in ASP.NET WebAPI</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/error-handling-in-asp-net-webapi</link>
      <pubDate>Thu, 28 Jun 2012 13:38:28 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2012/06/28/error-handling-in-asp-net-webapi/</guid>
      <description><![CDATA[WebAPI is a brand new framework that makes it easy to build HTTP services. As such, it provides...]]></description>
      <content:encoded><![CDATA[<p><font size="3" face="Calibri">WebAPI is a brand new framework that makes it easy to build HTTP services. As such, it provides several features that make it easy to send back useful and informative error messages in a variety of cases. In this post, I’ll go over some of these capabilities.</font></p>  <p><font size="3" face="Calibri">Note: Not all of the features I mention below are part of the ASP.NET MVC 4 RC build. You may have to use our nightly Nuget packages to get access to our latest bits. You can find more information about how to do so here: </font><a title="https://aspnetwebstack.codeplex.com/discussions/353867" href="https://aspnetwebstack.codeplex.com/discussions/353867"><font size="3" face="Calibri">https://aspnetwebstack.codeplex.com/discussions/353867</font></a><font size="3" face="Calibri">.</font></p>  <p><font size="3" face="Calibri">Now that’s out of the way, let’s take a look at what a typical WebAPI error’s HTTP content looks like:</font></p>  <p><font size="2" face="Consolas">{      <br />&#160; &quot;Message&quot;: &quot;No HTTP resource was found that matches the request URI 'https://localhost/Foo'.&quot;,       <br />&#160; &quot;MessageDetail&quot;: &quot;No type was found that matches the controller named 'Foo'.&quot;       <br /> }</font></p>  <p><font size="3" face="Calibri">So the error is actually just a collection of key-value pairs that provide information about what went wrong. This collection of key-value pairs is then sent back to the client in whatever content type it asked for through HTTP content negotiation. In the example above, the content is actually JSON.</font></p>  <p><font size="3" face="Calibri">But if you had “text/xml” in your request’s Accept header for example, you might get this response instead:</font></p>  <p><font size="2"><font face="Consolas">&lt;Error&gt;        <br />&#160; &lt;Message&gt;No HTTP resource was found that matches the request URI '</font><font face="Consolas">https://local</font></font><font size="2" face="Consolas">host/Foo'.&lt;/Message&gt;      <br />&#160; &lt;MessageDetail&gt;No type was found that matches the controller named 'Foo'.&lt;/MessageDetail&gt;</font><font size="2" face="Consolas">      <br />&lt; /Error&gt;</font></p>  <p><font size="3" face="Calibri">This simple format makes it easy for clients to understand what went wrong or to extract relevant error information for error logging or reporting.</font></p>  <h2><font size="4" face="Calibri">HttpError</font></h2>  <p><font face="Calibri"><font size="3">What you just saw above is actually an instance of an HttpError being serialized to the wire by Json.NET and DataContractSerializer respectively.</font></font></p>  <p><font face="Calibri"><font size="3">The HttpError type defines a consistent and extensible way for representing error information across the framework. Effectively, it’s just a Dictionary&lt;string, object&gt; that provides some helpers for creating errors that contain error messages, exceptions, or invalid model states. HttpError defines the following public constructors:</font></font></p>  <div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">   <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">     <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">public</span> HttpError();</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> <span style="color: rgb(0, 0, 255);">public</span> HttpError(<span style="color: rgb(0, 0, 255);">string</span> message);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span> <span style="color: rgb(0, 0, 255);">public</span> HttpError(Exception exception, <span style="color: rgb(0, 0, 255);">bool</span> includeErrorDetail);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span> <span style="color: rgb(0, 0, 255);">public</span> HttpError(ModelStateDictionary modelState, <span style="color: rgb(0, 0, 255);">bool</span> includeErrorDetail);</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">Here’s what HttpErrors for Exceptions look like in JSON:</font></p>

<p><font size="2" face="Consolas">{ 
    <br />&#160; &quot;Message&quot;: &quot;An error has occurred.&quot;, 

    <br />&#160; &quot;ExceptionMessage&quot;: &quot;Index was outside the bounds of the array.&quot;, 

    <br />&#160; &quot;ExceptionType&quot;: &quot;System.IndexOutOfRangeException&quot;, 

    <br />&#160; &quot;StackTrace&quot;: &quot;&#160;&#160; at WebApiTest.TestController.Post(Uri uri) in c:\\Temp\\WebApiTest\\WebApiTest\\TestController.cs:line 18\r\n&#160;&#160; at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;&gt;c__DisplayClassf.&lt;GetExecutor&gt;b__9(Object instance, Object[] methodParameters)\r\n&#160;&#160; at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n&#160;&#160; at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)&quot; 

    <br />}</font></p>

<p><font size="3" face="Calibri">And for invalid ModelStates:</font></p>

<p><font size="2" face="Consolas">{ 
    <br />&#160; &quot;Message&quot;: &quot;The request is invalid.&quot;, 

    <br />&#160; &quot;ModelState&quot;: { 

    <br />&#160;&#160;&#160; &quot;s&quot;: [ 

    <br />&#160;&#160;&#160;&#160;&#160; &quot;Required property 's' not found in JSON. Path '', line 1, position 2.&quot; 

    <br />&#160;&#160;&#160; ] 

    <br />&#160; } 

    <br /> }</font></p>

<p><font size="3" face="Consolas"><font face="Calibri">But it’s also important to note that you can create your own custom HttpErrors with your own custom error information. Here’s an example:</font></font></p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">public</span> HttpResponseMessage Get()</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     HttpError myCustomError = <span style="color: rgb(0, 0, 255);">new</span> HttpError(<span style="color: rgb(0, 96, 128);">&quot;My custom error message&quot;</span>) { { <span style="color: rgb(0, 96, 128);">&quot;CustomErrorCode&quot;</span>, 37 } };</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     <span style="color: rgb(0, 0, 255);">return</span> Request.CreateErrorResponse(HttpStatusCode.BadRequest, myCustomError);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span> }</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">This results in the following response:</font></p>

<p><font size="2" face="Consolas">{ 
    <br />&#160; &quot;Message&quot;: &quot;My custom error message&quot;, 

    <br />&#160; &quot;CustomErrorCode&quot;: 37 

    <br /> }</font></p>

<p><font size="3" face="Calibri">This is the first example where you’ve actually seen an action implemented that returns an error. Notice that we’re using Request.CreateErrorResponse to create an HttpResponseMessage that wraps our custom error. This is the recommended way to create response messages for errors. The following extension methods are provided to make it easy to return errors from your own code as well:</font></p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> HttpResponseMessage CreateErrorResponse(<span style="color: rgb(0, 0, 255);">this</span> HttpRequestMessage request, HttpStatusCode statusCode, Exception exception);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> HttpResponseMessage CreateErrorResponse(<span style="color: rgb(0, 0, 255);">this</span> HttpRequestMessage request, HttpStatusCode statusCode, HttpError error);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> HttpResponseMessage CreateErrorResponse(<span style="color: rgb(0, 0, 255);">this</span> HttpRequestMessage request, HttpStatusCode statusCode, ModelStateDictionary modelState);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> HttpResponseMessage CreateErrorResponse(<span style="color: rgb(0, 0, 255);">this</span> HttpRequestMessage request, HttpStatusCode statusCode, <span style="color: rgb(0, 0, 255);">string</span> message);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> HttpResponseMessage CreateErrorResponse(<span style="color: rgb(0, 0, 255);">this</span> HttpRequestMessage request, HttpStatusCode statusCode, <span style="color: rgb(0, 0, 255);">string</span> message, Exception exception);</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">You can also choose to just throw any exception from your action. WebAPI will automatically catch the exception and convert it into an error response with status code 500 (Internal Server Error) in exactly the same format as an error response that you would have created for an exception in your own code.</font></p>

<h2><font size="4" face="Calibri">HttpResponseException</font></h2>

<p><font size="3" face="Calibri">Now you may be wondering: how do I return an error if my action returns a different type instead of HttpResponseMessage? This is where HttpResponseException comes in. HttpResponseException is an exception type defined for WebAPI that serves two purposes:</font></p>

<ol>
  <li><font size="3" face="Calibri">It allows you to return a specific HTTP response from actions with return types that aren’t HttpResponseMessage.</font></li>

  <li><font size="3" face="Calibri">It allows you to short-circuit the WebAPI pipeline pretty much anywhere and return a response immediately.</font></li>
</ol>

<p><font size="3" face="Calibri">Technically, HttpResponseException can be used for any kind of HTTP response, but it’s especially useful in error cases. It allows us to implement actions like this:</font></p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">public</span> Person Get(<span style="color: rgb(0, 0, 255);">int</span> id)</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">if</span> (!_contacts.ContainsKey(id))</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>         <span style="color: rgb(0, 0, 255);">throw</span> <span style="color: rgb(0, 0, 255);">new</span> HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, String.Format(<span style="color: rgb(0, 96, 128);">&quot;Contact {0} not found.&quot;</span>, id)));</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>     }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>&#160; </pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>     <span style="color: rgb(0, 0, 255);">return</span> _contacts[id];</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span> }</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">Notice how even though the action is declared to return a Person, we’re able to return a custom error back to the client in error cases.</font></p>

<h2><font size="4" face="Calibri">Error Detail</font></h2>

<p><font size="3" face="Calibri">You may have noticed the “includeErrorDetail” parameter earlier in this post on the HttpError constructor. This is because typically, servers want to send different error information depending on whether the client is just consuming the service or whether the client needs additional debugging information to understand what went wrong on the server. By default, WebAPI will not send error details to remote clients and will provide these additional error details to clients on the local machine. Returning to our first example, whereas a local client would see this:</font></p>
<font size="2" face="Consolas">{ 
  <br />&#160; &quot;Message&quot;: &quot;No HTTP resource was found that matches the request URI 'https://localhost/Foo'.&quot;, 

  <br />&#160; &quot;MessageDetail&quot;: &quot;No type was found that matches the controller named 'Foo'.&quot; 

  <br /> }</font> 

<p><font size="3" face="Calibri">A remote client would only see this:</font></p>
<font size="2" face="Consolas">{ 
  <br />&#160; &quot;Message&quot;: &quot;No HTTP resource was found that matches the request URI 'https://localhost/Foo'.&quot; 

  <br />}</font> 

<p><font size="3" face="Calibri">The difference between Message and MessageDetail above is that MessageDetail contains error information that is WebAPI-specific that remote clients should not have to see in most cases. The exact meaning of error detail depends on the case. For exceptions, error detail includes the exception message, exception type, the stack trace, and the inner exceptions. Only a vague “An error has occurred.” message is sent back to remote clients for exceptions by default. For model states, any model error messages are sent to remote clients. Model error exceptions, however, are considered detail and will not get sent to remote clients by default.</font></p>

<p><font size="3" face="Calibri">You can choose to override when the error detail gets sent back to clients directly on your HttpConfiguration object:</font></p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.LocalOnly;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span> config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never;</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">As mentioned above, the default is LocalOnly.</font></p>

<h2><font size="4" face="Calibri">Applying Error Handling to Handle Invalid ModelStates</font></h2>

<p><font size="3" face="Calibri">One especially common use of WebAPI’s error handling is to immediately return an error if the model state is invalid. This can be done fairly easily by implementing the following action filter:</font></p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> ValidationFilterAttribute : ActionFilterAttribute</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum2" style="color: rgb(96, 96, 96);">   2:</span> {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum3" style="color: rgb(96, 96, 96);">   3:</span>     <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">override</span> <span style="color: rgb(0, 0, 255);">void</span> OnActionExecuting(HttpActionContext actionContext)</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum4" style="color: rgb(96, 96, 96);">   4:</span>     {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum5" style="color: rgb(96, 96, 96);">   5:</span>         <span style="color: rgb(0, 0, 255);">if</span> (!actionContext.ModelState.IsValid)</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum6" style="color: rgb(96, 96, 96);">   6:</span>         {</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum7" style="color: rgb(96, 96, 96);">   7:</span>             actionContext.Response = actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, actionContext.ModelState);</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum8" style="color: rgb(96, 96, 96);">   8:</span>         }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum9" style="color: rgb(96, 96, 96);">   9:</span>     }</pre>
<!--CRLF-->

    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);"><span id="lnum10" style="color: rgb(96, 96, 96);">  10:</span> }</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">You can then either mark your action with this attribute, or register the action filer globally like this:</font></p>

<div id="codeSnippetWrapper" style="margin: 20px 0px 10px; padding: 4px; border: 1px solid silver; width: 97.5%; text-align: left; line-height: 12pt; overflow: auto; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; cursor: text; direction: ltr; max-height: 200px; background-color: rgb(244, 244, 244);">
  <div id="codeSnippet" style="padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: rgb(244, 244, 244);">
    <pre style="margin: 0em; padding: 0px; width: 100%; text-align: left; color: black; line-height: 12pt; overflow: visible; font-family: &quot;Courier New&quot;, courier, monospace; font-size: 8pt; direction: ltr; background-color: white;"><span id="lnum1" style="color: rgb(96, 96, 96);">   1:</span> config.Filters.Add(<span style="color: rgb(0, 0, 255);">new</span> ValidationFilterAttribute());</pre>
<!--CRLF--></div>
</div>

<p><font size="3" face="Calibri">This allows you to short-circuit the processing of the request and immediately return an error for the invalid model state back to the client.</font></p>

<p><font size="3" face="Calibri">As always, you can learn more about ASP.NET WebAPI here: <a href="https://www.asp.net/web-api">https://www.asp.net/web-api</a>.</font></p>]]></content:encoded>
    </item>
    <item>
      <title>Writing a Lightweight Web Service using WebApi Building Blocks</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/writing-a-lightweight-web-service-using-webapi-building-blocks</link>
      <pubDate>Fri, 24 Feb 2012 18:21:00 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2012/02/24/writing-a-lightweight-web-service-using-webapi-building-blocks/</guid>
      <description><![CDATA[Don&rsquo;t you wish you could write a web service this...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;">Don&rsquo;t you wish you could write a web service this easily:<o:p></o:p></span></p>
<div class="WordSection1">
<p style="tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;" class="MsoNormal"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: green;"><o:p>&nbsp;</o:p></span></p>
<p style="tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;" class="MsoNormal"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">LiteWebServer</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">&nbsp;server&nbsp;=&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue;">new</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af;">LiteWebServer</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">(</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515;">"https://localhost"</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">);<o:p></o:p></span></p>
<p style="tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;" class="MsoNormal"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">server.Get(</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515; background: yellow; mso-highlight: yellow;">"/Hello"</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">,&nbsp;(r)&nbsp;=&gt;&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue; background: yellow; mso-highlight: yellow;">new</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af; background: yellow; mso-highlight: yellow;">HttpResponseMessage</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">()&nbsp;{&nbsp;Content&nbsp;=&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue; background: yellow; mso-highlight: yellow;">new</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af; background: yellow; mso-highlight: yellow;">StringContent</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">(</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515; background: yellow; mso-highlight: yellow;">"Hello&nbsp;World!"</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">)&nbsp;});<o:p></o:p></span></p>
<p style="tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;" class="MsoNormal"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">server.Post(</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #a31515; background: yellow; mso-highlight: yellow;">"/Echo"</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">,&nbsp;(r)&nbsp;=&gt;&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue; background: yellow; mso-highlight: yellow;">new</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af; background: yellow; mso-highlight: yellow;">HttpResponseMessage</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">()&nbsp;{&nbsp;Content&nbsp;=&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: blue; background: yellow; mso-highlight: yellow;">new</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">&nbsp;</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: #2b91af; background: yellow; mso-highlight: yellow;">StringContent</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black; background: yellow; mso-highlight: yellow;">(r.Content.ReadAsStringAsync().Result)&nbsp;});</span><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;"><o:p></o:p></span></p>
<p style="tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt; background: white;" class="MsoNormal"><span style="font-size: 10.0pt; font-family: Consolas; mso-fareast-font-family: 'Times New Roman'; color: black;">server.Open();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;">Well, with last week&rsquo;s release of the Web API beta bits, now you can. Web API is a brand new framework that makes it easy to build HTTP services. You can learn more about Web API here: <a href="https://www.asp.net/web-api">https://www.asp.net/web-api</a>.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;">One of the goals when designing the framework was to completely decouple how messages were received from how they were being dispatched. This allows you to plug in your own custom dispatching for requests very easily. In this post, I&rsquo;ll show you how you can leverage this extensibility to have messages dispatched to your own lambda callbacks.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;">The key thing we&rsquo;ll be using is an HttpMessageHandler. HttpMessageHandlers have the following contract:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></p>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;Summary:</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;base&nbsp;type&nbsp;for&nbsp;HTTP&nbsp;message&nbsp;handlers.</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: blue;">public</span><span style="font-family: Consolas; color: black;">&nbsp;</span><span style="font-family: Consolas; color: blue;">abstract</span><span style="font-family: Consolas; color: black;">&nbsp;</span><span style="font-family: Consolas; color: blue;">class</span><span style="font-family: Consolas; color: black;">&nbsp;</span><span style="font-family: Consolas; color: #2b91af;">HttpMessageHandler</span><span style="font-family: Consolas; color: black;">&nbsp;:&nbsp;</span><span style="font-family: Consolas; color: #2b91af;">IDisposable</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;Summary:</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Send&nbsp;an&nbsp;HTTP&nbsp;request&nbsp;as&nbsp;an&nbsp;asynchronous&nbsp;operation.</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;Parameters:</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;&nbsp;&nbsp;request:</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;HTTP&nbsp;request&nbsp;message&nbsp;to&nbsp;send.</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;&nbsp;&nbsp;cancellationToken:</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;cancellation&nbsp;token&nbsp;to&nbsp;cancel&nbsp;operation.</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;Returns:</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns&nbsp;System.Threading.Tasks.Task&lt;TResult&gt;.The&nbsp;task&nbsp;object&nbsp;representing</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: green;">//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;the&nbsp;asynchronous&nbsp;operation.</span><span style="font-family: Consolas; color: black;"><o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Consolas; color: blue;">protected</span><span style="font-family: Consolas; color: black;">&nbsp;</span><span style="font-family: Consolas; color: blue;">internal</span><span style="font-family: Consolas; color: black;">&nbsp;</span><span style="font-family: Consolas; color: blue;">abstract</span><span style="font-family: Consolas; color: black;">&nbsp;</span><span style="font-family: Consolas; color: #2b91af;">Task</span><span style="font-family: Consolas; color: black;">&lt;</span><span style="font-family: Consolas; color: #2b91af;">HttpResponseMessage</span><span style="font-family: Consolas; color: black;">&gt;&nbsp;SendAsync(</span><span style="font-family: Consolas; color: #2b91af;">HttpRequestMessage</span><span style="font-family: Consolas; color: black;">&nbsp;request,&nbsp;</span><span style="font-family: Consolas; color: #2b91af;">CancellationToken</span><span style="font-family: Consolas; color: black;">&nbsp;cancellationToken);<o:p></o:p></span></pre>
<pre style="background: white;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></pre>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;">Send<a name="_MailAutoSig"></a>Async here allows you to asynchronously handle a request, and return a Task that may eventually complete with a response. Now all we need is something to actually call our message handlers. In Web API, these are called HttpServers. They&rsquo;re in charge of listening for requests and pumping them through the HttpMessageHandler when they receive them. Notice how LiteWebServer below delegates to its inner HttpSelfHostServer.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-bookmark: _MailAutoSig;"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></span></p>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">delegate</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpResponseMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpRequestMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;request);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">class</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteWebServer</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpSelfHostServer</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;server;<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpSelfHostConfiguration</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;configuration;<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteWebMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;messageHandler&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteWebMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;LiteWebServer(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">string</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;baseAddress)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;configuration&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpSelfHostConfiguration</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(baseAddress);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background: yellow; mso-highlight: yellow;">server&nbsp;=&nbsp;</span></span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue; background: yellow; mso-highlight: yellow;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af; background: yellow; mso-highlight: yellow;">HttpSelfHostServer</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">(configuration,&nbsp;messageHandler);</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">void</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;Get(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">string</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;subPath,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;handler)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegisterHandler(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Get,&nbsp;subPath,&nbsp;handler);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">void</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;Put(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">string</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;subPath,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;handler)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegisterHandler(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Put,&nbsp;subPath,&nbsp;handler);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">void</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;Post(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">string</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;subPath,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;handler)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegisterHandler(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Post,&nbsp;subPath,&nbsp;handler);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">void</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;Delete(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">string</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;subPath,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;handler)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RegisterHandler(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Delete,&nbsp;subPath,&nbsp;handler);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">private</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">void</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;RegisterHandler(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;method,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">string</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;subPath,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;handler)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;messageHandler.Handlers[method].Add(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Uri</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(configuration.BaseAddress,&nbsp;subPath).ToString(),&nbsp;handler);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">void</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;Open()<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server.OpenAsync().Wait();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">void</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;Close()<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server.CloseAsync().Wait();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">private</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">class</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteWebMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;:&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">public</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Dictionary</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&lt;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&gt;&nbsp;Handlers&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Dictionary</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&lt;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&gt;()<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Delete,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Get,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Head,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Options,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Post,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Put,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Trace,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">protected</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">override</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Task</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&lt;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpResponseMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&gt;&nbsp;SendAsync(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpRequestMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;request,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">CancellationToken</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;cancellationToken)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;handler;<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;routingMap&nbsp;=&nbsp;Handlers[request.Method];<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af; background: yellow; mso-highlight: yellow;">HttpResponseMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">&nbsp;response&nbsp;=&nbsp;routingMap.TryGetValue(request.RequestUri.AbsoluteUri,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue; background: yellow; mso-highlight: yellow;">out</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">&nbsp;handler)&nbsp;?<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;handler(request)&nbsp;:<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue; background: yellow; mso-highlight: yellow;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af; background: yellow; mso-highlight: yellow;">HttpResponseMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af; background: yellow; mso-highlight: yellow;">HttpStatusCode</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black; background: yellow; mso-highlight: yellow;">.NotFound);</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">return</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;FromResult(response);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">private</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">static</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Task</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&lt;T&gt;&nbsp;FromResult&lt;T&gt;(T&nbsp;t)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">TaskCompletionSource</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&lt;T&gt;&nbsp;tcs&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">TaskCompletionSource</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&lt;T&gt;();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tcs.SetResult(t);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">return</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;tcs.Task;<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">private</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">class</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">RoutingMap</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;:&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Dictionary</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&lt;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">string</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteMessageHandler</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&gt;<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;&nbsp;&nbsp;&nbsp;}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">}<o:p></o:p></span></span></pre>
<p class="MsoNormal"><span style="mso-bookmark: _MailAutoSig;"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></span></p>
<p class="MsoNormal"><span style="mso-bookmark: _MailAutoSig;"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;">And that lets us write our web service in just a few lines of code:<o:p></o:p></span></span></p>
<p class="MsoNormal"><span style="mso-bookmark: _MailAutoSig;"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></span></p>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: green;">//&nbsp;Set&nbsp;up&nbsp;server</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteWebServer</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;server&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">LiteWebServer</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #a31515;">"https://localhost"</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">server.Get(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #a31515;">"/Hello"</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">,&nbsp;(r)&nbsp;=&gt;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpResponseMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;{&nbsp;Content&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">StringContent</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #a31515;">"Hello&nbsp;World!"</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">)&nbsp;});<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">server.Post(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #a31515;">"/Echo"</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">,&nbsp;(r)&nbsp;=&gt;&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpResponseMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">()&nbsp;{&nbsp;Content&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">StringContent</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(r.Content.ReadAsStringAsync().Result)&nbsp;});<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">server.Open();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: green;">//&nbsp;Client&nbsp;call&nbsp;-&nbsp;Hello&nbsp;World</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpRequestMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;request&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpRequestMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Get,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #a31515;">"https://localhost/Hello"</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpResponseMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;response&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpClient</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">().SendAsync(request).Result;<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Console</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.WriteLine(response);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Console</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.WriteLine(response.Content.ReadAsStringAsync().Result);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Console</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.WriteLine(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #a31515;">"------------------"</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: green;">//&nbsp;Client&nbsp;call&nbsp;-&nbsp;Echo</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">request&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpRequestMessage</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpMethod</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.Post,&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #a31515;">"https://localhost/Echo"</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">)&nbsp;{&nbsp;Content&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">StringContent</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">(</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #a31515;">"This&nbsp;is&nbsp;pretty&nbsp;neat!"</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">)&nbsp;};<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">response&nbsp;=&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: blue;">new</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">&nbsp;</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">HttpClient</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">().SendAsync(request).Result;<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Console</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.WriteLine(response);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: #2b91af;">Console</span></span><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">.WriteLine(response.Content.ReadAsStringAsync().Result);<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-family: Consolas; color: black;">server.Close();<o:p></o:p></span></span></pre>
<p class="MsoNormal"><span style="mso-bookmark: _MailAutoSig;"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></span></p>
<p class="MsoNormal"><span style="mso-bookmark: _MailAutoSig;"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;">There are plenty more things you can do with Web API. I&rsquo;ll be repurposing this blog to discuss more about how Web API works and how it can help you write HTTP services.<o:p></o:p></span></span></p>
<span style="mso-bookmark: _MailAutoSig;"></span>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size: 12.0pt; mso-bidi-font-size: 11.0pt; color: #002060;">In the meantime, I encourage you to download the bits today!<o:p></o:p></span></p>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Using the [ContractNamespace] attribute to customize the namespace for POCO types</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/using-the-contractnamespace-attribute-to-customize-the-namespace-for-poco-types</link>
      <pubDate>Thu, 30 Jun 2011 12:21:00 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2011/06/30/using-the-contractnamespace-attribute-to-customize-the-namespace-for-poco-types/</guid>
      <description><![CDATA[In .NET 3.5 SP1, DataContractSerializer was enhanced to support POCO types that weren&rsquo;t marked...]]></description>
      <content:encoded><![CDATA[<p>In .NET 3.5 SP1, DataContractSerializer was enhanced to support POCO types that weren&rsquo;t marked with any serialization attributes at all. You can find my previous post about serializing POCO types <a href="https://blogs.msdn.com/b/youssefm/archive/2009/08/10/serializing-plain-old-clr-objects-poco-types-with-datacontractserializer.aspx">here</a>. But in some cases, you may want to customize the XML namespace of your POCO types without necessarily having to fall back to the [DataContract]/[DataMember] model. The way to do this is by using an assembly-level attribute called [ContractNamespace]. This attribute allows you to either set an XML namespace for DataContractSerializer for all the types in your assembly, or to set an XML namespace for specific CLR namespaces within your assembly.</p>
<div class="WordSection1">
<p class="MsoNormal">So for example, the following POCO type:</p>
<pre style="background: white; color: black; font-family: Consolas;"><span style="color: blue;">namespace</span>&nbsp;MyNs
{
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">class</span>&nbsp;<span style="color: #2b91af;">POCO</span>
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">string</span>&nbsp;Data&nbsp;{&nbsp;<span style="color: blue;">get</span>;&nbsp;<span style="color: blue;">set</span>;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
}</pre>
<p class="MsoNormal">Would traditionally get serialized with a default XML namespace:</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;">&lt;POCO xmlns="<span style="background: yellow; mso-highlight: yellow;">https://schemas.datacontract.org/2004/07/MyNs</span>" xmlns:i="https://www.w3.org/2001/XMLSchema-instance"&gt;</span></p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;"><span style="mso-spacerun: yes;">&nbsp; </span>&lt;Data i:nil="true" /&gt;</span></p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;">&lt;/POCO&gt;</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">But if you happen to have the assembly level attribute:</p>
<p class="MsoNormal"><br />[<span style="color: blue;">assembly</span>:<span style="color: #2b91af;">ContractNamespace</span>(<span style="color: #a31515;">"https://myXmlNamespace"</span>)]</p>
<p class="MsoNormal">Or:</p>
<p class="MsoNormal">[<span style="color: blue;">assembly</span>:<span style="color: #2b91af;">ContractNamespace</span>(<span style="color: #a31515;">"https://myXmlNamespace"</span>,&nbsp;ClrNamespace=<span style="color: #a31515;">"MyNs"</span>)]</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">, then "https://myXmlNamespace"&nbsp;will be used for the POCO type&rsquo;s serialization:</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;">&lt;POCO xmlns="<span style="background: yellow; mso-highlight: yellow;">https://myXmlNamespace</span>" xmlns:i="https://www.w3.org/2001/XMLSchema-instance"&gt;</span></p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;"><span style="mso-spacerun: yes;">&nbsp; </span>&lt;Data i:nil="true" /&gt;</span></p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;">&lt;/POCO&gt;</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">So the ContractNamespaceAttribute allows you to either choose a default XML namespace for the entire assembly, or map the types in a specific CLR namespace to the XML namespace of your choosing.</p>
<p class="MsoNormal">Note that ContractNamespaceAttribute applies not only to POCO types, but to all other serializable types as well. So,</p>
<pre style="background: white; color: black; font-family: Consolas;"><span style="color: blue;">namespace</span>&nbsp;MyNs
{
&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: #2b91af;">DataContract</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">class</span>&nbsp;<span style="color: #2b91af;">POCO</span>
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: #2b91af;">DataMember</span>]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">string</span>&nbsp;Data&nbsp;{&nbsp;<span style="color: blue;">get</span>;&nbsp;<span style="color: blue;">set</span>;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
}</pre>
<pre style="background: white;"><span style="color: black; font-family: consolas;"></span></pre>
<p class="MsoNormal">Would also be serialized as:</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;">&lt;POCO xmlns="<span style="background: yellow; mso-highlight: yellow;">https://myXmlNamespace</span>" xmlns:i="https://www.w3.org/2001/XMLSchema-instance"&gt;</span></p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;"><span style="mso-spacerun: yes;">&nbsp; </span>&lt;Data i:nil="true" /&gt;</span></p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;">&lt;/POCO&gt;</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">If the [ContractNamespace] attribute were present. However, DataContracts can override the ContractNamespace default by setting their own namespace on the type itself. So,</p>
<pre style="background: white; color: black; font-family: Consolas;"><span style="color: blue;">namespace</span>&nbsp;MyNs
{
&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: #2b91af;">DataContract</span>(<span style="background-color: #ffff99;"><span style="background-color: #ffff00;">Namespace=<span style="color: #a31515;">"https://POCONamespace"</span></span><span style="background-color: #ffffff;">)]</span></span>
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">class</span>&nbsp;<span style="color: #2b91af;">POCO</span>
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<span style="color: #2b91af;">DataMember</span>]
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: blue;">public</span>&nbsp;<span style="color: blue;">string</span>&nbsp;Data&nbsp;{&nbsp;<span style="color: blue;">get</span>;&nbsp;<span style="color: blue;">set</span>;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
}</pre>
<pre style="background: white;"><span style="color: black; font-family: consolas;"></span></pre>
<p class="MsoNormal">Would get serialized as:</p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal"><span style="font-family: 'Courier New'; font-size: 10pt;">&lt;POCO xmlns="<span style="background-color: #ffff00;"><span style="background-color: #ffff00;">https://POCONamespace</span></span>" xmlns:i="https://www.w3.org/2001/XMLSchema-instance"&gt;<br />&nbsp; &lt;Data i:nil="true" /&gt;<br />&lt;/POCO&gt;</span></p>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">Regardless of any [ContractNamespace] attributes.</p>
</div>]]></content:encoded>
    </item>
    <item>
      <title>Loading WCF Client Configuration from Different Files with ConfigurationChannelFactory</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/loading-wcf-client-configuration-from-different-files-with-configurationchannelfactory</link>
      <pubDate>Thu, 02 Sep 2010 16:59:00 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2010/09/02/loading-wcf-client-configuration-from-different-files-with-configurationchannelfactory/</guid>
      <description><![CDATA[One
 pain point with configuration that WCF developers have run into in 
previous versions of the...]]></description>
      <content:encoded><![CDATA[<p><span style="font-size: small; font-family: arial,helvetica,sans-serif;">One
 pain point with configuration that WCF developers have run into in 
previous versions of the framework is the limitation that WCF clients 
can only use the hosting executable&rsquo;s configuration file. This can be 
problematic for clients that need to call multiple services because the 
configuration for all of these services would have to be mashed together
 in one big configuration file. This can also be a problem for client 
libraries: since libraries don&rsquo;t have configuration files, every 
executable that uses the library needs to provide it with the right 
configuration in its own configuration file.</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="font-family: Calibri;">Fortunately, this restriction has been lifted in WCF 4.0 with the introduction of </span><a href="https://msdn.microsoft.com/en-us/library/dd575311.aspx"><span style="font-family: Calibri;">ConfigurationChannelFactory</span></a><span style="font-family: Calibri;"><span style="font-size: small;">. This new class allows you to create clients that can take in any Configuration object to co<span style="font-family: arial,helvetica,sans-serif;">nfigure your client.</span><span style="font-family: arial,helvetica,sans-serif;"></span></span><span style="mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-no-proof: yes;"><span style="font-size: small;"><span style="font-family: arial,helvetica,sans-serif;"> This means that you&rsquo;re no longer limited to using the App.config for your executable. To demonstrate this new class, let&rsquo;s say you have a client that needs to call out to a web service that re</span>turns stock information and another web service that returns weather information.</span><o:p></o:p></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-no-proof: yes;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-no-proof: yes;"><span style="font-size: small;"><span style="font-family: Calibri;">In WCF 4.0, you can do this:<o:p></o:p></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-no-proof: yes;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">Configuration</span><span style="font-family: Consolas; font-size: 9.5pt;"> stockConfiguration = <span style="color: #2b91af;">ConfigurationManager</span>.OpenMappedExeConfiguration(<span style="color: blue;">new</span> <span style="color: #2b91af;">ExeConfigurationFileMap</span> { ExeConfigFilename = <span style="color: #a31515;">@"C:\Temp\StockClient.config"</span>}, <span style="color: #2b91af;">ConfigurationUserLevel</span>.None);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">ConfigurationChannelFactory</span><span style="font-family: Consolas; font-size: 9.5pt;">&lt;<span style="color: #2b91af;">StockQuoteSoap</span>&gt; stockChannelFactory = <span style="background: yellow; color: blue; mso-highlight: yellow;">new</span><span style="background: yellow; mso-highlight: yellow;"> <span style="color: #2b91af;">ConfigurationChannelFactory</span>&lt;<span style="color: #2b91af;">StockQuoteSoap</span>&gt;(<span style="color: #a31515;">"StockQuoteSoap"</span>, stockConfiguration, <span style="color: blue;">null</span>);</span><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">StockQuoteSoap</span><span style="font-family: Consolas; font-size: 9.5pt;"> stockClient = stockChannelFactory.CreateChannel();<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">GetQuoteResponse</span><span style="font-family: Consolas; font-size: 9.5pt;"> stockResponse = stockClient.GetQuote(<span style="color: blue;">new</span> <span style="color: #2b91af;">GetQuoteRequest</span> { Body = <span style="color: blue;">new</span> <span style="color: #2b91af;">GetQuoteRequestBody</span> { symbol = <span style="color: #a31515;">"MSFT"</span> } });<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">Console</span><span style="font-family: Consolas; font-size: 9.5pt;">.WriteLine(stockResponse.Body.GetQuoteResult);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; font-size: 9.5pt;">stockChannelFactory.Close();<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; font-size: 9.5pt;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">Configuration</span><span style="font-family: Consolas; font-size: 9.5pt;"> weatherConfiguration = <span style="color: #2b91af;">ConfigurationManager</span>.OpenMappedExeConfiguration(<span style="color: blue;">new</span> <span style="color: #2b91af;">ExeConfigurationFileMap</span> { ExeConfigFilename = <span style="color: #a31515;">@"C:\Temp\WeatherClient.config"</span> }, <span style="color: #2b91af;">ConfigurationUserLevel</span>.None);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">ConfigurationChannelFactory</span><span style="font-family: Consolas; font-size: 9.5pt;">&lt;<span style="color: #2b91af;">GlobalWeatherSoap</span>&gt; weatherChannelFactory = <span style="background: yellow; color: blue; mso-highlight: yellow;">new</span><span style="background: yellow; mso-highlight: yellow;"> <span style="color: #2b91af;">ConfigurationChannelFactory</span>&lt;<span style="color: #2b91af;">GlobalWeatherSoap</span>&gt;(<span style="color: #a31515;">"GlobalWeatherSoap"</span>, weatherConfiguration, <span style="color: blue;">null</span>);</span><o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">GlobalWeatherSoap</span><span style="font-family: Consolas; font-size: 9.5pt;"> weatherClient = weatherChannelFactory.CreateChannel();<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">GetWeatherResponse</span><span style="font-family: Consolas; font-size: 9.5pt;"> weatherResponse = weatherClient.GetWeather(<span style="color: blue;">new</span> <span style="color: #2b91af;">GetWeatherRequest</span> { Body = <span style="color: blue;">new</span> <span style="color: #2b91af;">GetWeatherRequestBody</span> { CityName = <span style="color: #a31515;">"Paris"</span>, CountryName = <span style="color: #a31515;">"France"</span> } });<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; color: #2b91af; font-size: 9.5pt;">Console</span><span style="font-family: Consolas; font-size: 9.5pt;">.WriteLine(weatherResponse.Body.GetWeatherResult);<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none;"><span style="font-family: Consolas; font-size: 9.5pt;">weatherChannelFactory.Close();<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-no-proof: yes;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="mso-fareast-font-family: 'Times New Roman'; mso-fareast-theme-font: minor-fareast; mso-no-proof: yes;"><span style="font-size: small;"><span style="font-family: Calibri;">In this example, two separate client configuration files are located at C:\Temp\StockClient.config and C:\Temp\WeatherClient.config and we&rsquo;re able to use both in the very same method! For each service, we first load up a configuration object, then pass that configuration object to the constructor for ConfigurationChannelFactory, and finally call the service and print out the results. It's that easy.</span></span></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Turning XML into XmlSerializer CLR Types with xsd.exe</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/turning-xml-into-xmlserializer-clr-types-with-xsd-exe</link>
      <pubDate>Tue, 01 Jun 2010 15:22:00 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2010/06/01/turning-xml-into-xmlserializer-clr-types-with-xsd-exe/</guid>
      <description><![CDATA[Here&rsquo;s a common dilemma .NET developers encounter when working with XML: I have some XML that...]]></description>
      <content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 0pt;"><a name="_MailAutoSig"><span style="font-size: small;"><span style="font-family: Calibri;">Here&rsquo;s a common dilemma .NET developers encounter when working with XML: I have some XML that I want to represent in a strongly typed way, but I don&rsquo;t have any XSDs to represent that XML. How do I turn that XML into CLR types that I can serialize?<o:p></o:p></span></span></a></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="mso-bookmark: _MailAutoSig;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="mso-bookmark: _MailAutoSig;"><span style="font-size: small;"><span style="font-family: Calibri;">Of course, I could go about manually creating XmlSerializer types that match the way the XML looks, but that&rsquo;s usually unnecessary and always tedious. You could also look into the &ldquo;Paste XML as Types&rdquo; feature that&rsquo;s part of the WCF REST starter kit as a Visual Studio add-in. But if you want to just get the job done from the command line without downloading or installing anything, this blog post is for you. We&rsquo;ll make use of xsd.exe, which is part of the SDK for the .NET framework.<o:p></o:p></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="font-family: Calibri;"></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="font-family: Calibri;">Suppose we&rsquo;re starting out with the following snippet of XML:<o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;">&lt;Library xmlns:i="https://www.w3.org/2001/XMLSchema-instance"&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp; </span>&lt;Books&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>&lt;Book Rating="4"&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;Author&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;FirstName&gt;Kurt&lt;/FirstName&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;LastName&gt;Vonnegut&lt;/LastName&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;MiddleName i:nil="true" /&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/Author&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;Title&gt;Welcome to the Monkey House&lt;/Title&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;Year&gt;1968&lt;/Year&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>&lt;/Book&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>&lt;Book Rating="5"&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;Author&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;FirstName&gt;Orson&lt;/FirstName&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;LastName&gt;Card&lt;/LastName&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;MiddleName&gt;Scott&lt;/MiddleName&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/Author&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;Title&gt;Ender's Game&lt;/Title&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;Year&gt;1985&lt;/Year&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>&lt;/Book&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp; </span>&lt;/Books&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp; </span>&lt;Name&gt;Library Of Congress&lt;/Name&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;">&lt;/Library&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><span style="font-size: small;">That we want to turn into XmlSerializer types. First, copy this bit of XML into a file named library.xml and run the following command:<o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New';"><span style="font-size: small;">xsd.exe library.xml<o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New';"><o:p><span style="font-size: small;">&nbsp;</span></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-size: small;"><span style="font-family: Calibri;">This should generate an XSD for the XML we started out with. If you open library.xsd, you&rsquo;ll find the following schema:<o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp; </span>&lt;xs:element name="Library"&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>&lt;xs:complexType&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:sequence&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="Name" type="xs:string" minOccurs="0" /&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="Books" minOccurs="0" maxOccurs="unbounded"&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:complexType&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:sequence&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="Book" minOccurs="0" maxOccurs="unbounded"&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:complexType&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:sequence&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="Title" type="xs:string" minOccurs="0" msdata:Ordinal="1" /&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="Year" type="xs:string" minOccurs="0" msdata:Ordinal="2" /&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="Author" minOccurs="0" maxOccurs="unbounded"&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:complexType&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:sequence&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="FirstName" type="xs:string" minOccurs="0" /&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="LastName" type="xs:string" minOccurs="0" /&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:element name="MiddleName" type="xs:string" minOccurs="0" /&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:sequence&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:complexType&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:element&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:sequence&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;xs:attribute name="Rating" type="xs:string" /&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:complexType&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:element&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:sequence&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:complexType&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:element&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&lt;/xs:sequence&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;&nbsp;&nbsp; </span>&lt;/xs:complexType&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 9pt;"><span style="mso-spacerun: yes;">&nbsp;</span><span style="mso-spacerun: yes;">&nbsp;</span>&lt;/xs:element&gt;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New'; font-size: 10pt;"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><span style="font-size: small;">Which matches our original XML perfectly. Now, we just need to generate types based off the XSD, using xsd.exe again:<o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New';"><span style="font-size: small;">xsd.exe /classes library.xsd<o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: 'Courier New';"><o:p><span style="font-size: small;">&nbsp;</span></o:p></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><span style="font-size: small;">This will generate a C# file called library.cs which contains the XmlSerializer types for your XML. And at this point, <span style="color: black; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-family: Calibri;">all you have to&nbsp;do is to compile the classes and to&nbsp;start deserializing instances of XML into your newly generated types or create instances of these types and serialize them out.</span><o:p></o:p></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><o:p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></o:p></p>
<p class="MsoNormal" style="margin: 0in 0in 0pt;"><span style="font-family: Calibri;"><span style="font-size: small;">A couple notes:<o:p></o:p></span></span></p>
<p class="MsoListParagraph" style="text-indent: -0.25in; margin: 0in 0in 0pt 0.25in; mso-list: l0 level1 lfo1;"><span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;"><span style="font-size: small;">&middot;</span><span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: Calibri;"><span style="font-size: small;">The names of the types won&rsquo;t quite look natural. This happens because all of the types in the XSD are anonymous. I suggest renaming these to suit your needs.<o:p></o:p></span></span></p>
<p class="MsoListParagraph" style="text-indent: -0.25in; margin: 0in 0in 0pt 0.25in; mso-list: l0 level1 lfo1;"><span style="font-family: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol;"><span style="mso-list: Ignore;"><span style="font-size: small;">&middot;</span><span style="font: 7pt 'Times New Roman';">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-size: small;"><span style="font-family: Calibri;">You should also get a &ldquo;NewDataSet&rdquo; class generated. This is an artifact of the way xsd.exe generates a schema for the XML. You can safely delete the class.</span></span></p>]]></content:encoded>
    </item>
    <item>
      <title>Using XML Schema Import and Export for XmlSerializer</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/using-xml-schema-import-and-export-for-xmlserializer</link>
      <pubDate>Thu, 13 May 2010 13:51:00 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2010/05/13/using-xml-schema-import-and-export-for-xmlserializer/</guid>
      <description><![CDATA[In a previous post, I outlined how you could import and export the XML schema for a type that you’re...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3 face=Calibri>In a </FONT><A href="https://blogs.msdn.com/youssefm/archive/2009/04/29/using-xml-schema-import-and-export-for-datacontractserializer.aspx"><FONT size=3 face=Calibri>previous</FONT></A><FONT size=3><FONT face=Calibri> post, I outlined how you could import and export the XML schema for a type that you’re serializing with DataContractSerializer. Here’s how to do the same thing if you’re serializing objects with XmlSerializer:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9.5pt">static</SPAN><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> <SPAN style="COLOR: blue">void</SPAN> RoundTripXmlMetadata(<SPAN style="COLOR: #2b91af">Type</SPAN> type)<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">{<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">XmlSchemas</SPAN> schemas = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">XmlSchemas</SPAN>();<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">XmlSchemaExporter</SPAN> exporter = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">XmlSchemaExporter</SPAN>(schemas);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//Import the type as an XML mapping</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">XmlTypeMapping</SPAN> mapping = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">XmlReflectionImporter</SPAN>().ImportTypeMapping(type);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//Export the XML mapping into schemas</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>exporter.ExportTypeMapping(mapping);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//Print out the schemas</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">foreach</SPAN> (<SPAN style="COLOR: blue">object</SPAN> schema <SPAN style="COLOR: blue">in</SPAN> schemas)<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>{<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>((<SPAN style="COLOR: #2b91af">XmlSchema</SPAN>)schema).Write(<SPAN style="COLOR: #2b91af">Console</SPAN>.Out);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">Console</SPAN>.WriteLine(<SPAN style="COLOR: #a31515">"\n"</SPAN>);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">Console</SPAN>.WriteLine(<SPAN style="COLOR: #a31515">"-------------------------------------------"</SPAN>);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//Compile the schemas into one logical schema</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>schemas.Compile((o, args) =&gt; <SPAN style="COLOR: #2b91af">Console</SPAN>.WriteLine(args.Message), <SPAN style="COLOR: blue">true</SPAN>);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">XmlSchemaImporter</SPAN> importer = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">XmlSchemaImporter</SPAN>(schemas);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//Import the schema element back into an XML mapping</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>mapping = importer.ImportTypeMapping(<SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">XmlQualifiedName</SPAN>(mapping.ElementName, mapping.Namespace));<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//Create a CompileUnit and CodeNamespace to contain the generated code</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">CodeCompileUnit</SPAN> compileUnit = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">CodeCompileUnit</SPAN>();<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">CodeNamespace</SPAN> compileNs = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">CodeNamespace</SPAN>();<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>compileUnit.Namespaces.Add(compileNs);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">XmlCodeExporter</SPAN> codeGenerator = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">XmlCodeExporter</SPAN>(compileNs);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//Export the XML mapping into code</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>codeGenerator.ExportTypeMapping(mapping);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: green">//Generate C# code for the compile unit and print it out</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #2b91af">CSharpCodeProvider</SPAN> provider = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">CSharpCodeProvider</SPAN>();<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>provider.GenerateCodeFromCompileUnit(compileUnit, <SPAN style="COLOR: #2b91af">Console</SPAN>.Out, <SPAN style="COLOR: blue">null</SPAN>);<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>I’ve tried to add comments to explain what’s happening. Essentially, we go through the following process when generating the schemas:<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>CLR type =&gt; XML mapping =&gt; Xml Schemas<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>and the following process when generating code:<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>Xml Schemas =&gt; XML mapping =&gt; C# code<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>And when we try running the type Dog defined below<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN>public</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: #2b91af">Animal<o:p></o:p></SPAN></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN>{<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">int</SPAN> age = 4;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">string</SPAN> name = <SPAN style="COLOR: #a31515">"Rusty"</SPAN>;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN>public</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: #2b91af">Dog</SPAN> : <SPAN style="COLOR: #2b91af">Animal<o:p></o:p></SPAN></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN>{<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: #2b91af">DogBreed</SPAN> breed = <SPAN style="COLOR: #2b91af">DogBreed</SPAN>.LabradorRetriever;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN>public</SPAN><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN> <SPAN style="COLOR: blue">enum</SPAN> <SPAN style="COLOR: #2b91af">DogBreed</SPAN> {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>GermanShepherd,<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>LabradorRetriever<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-no-proof: yes; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN" lang=EN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>Through the method, we get the following output:<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">&lt;?xml version="1.0" encoding="IBM437"?&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">&lt;xs:schema elementFormDefault="qualified" xmlns:xs="https://www.w3.org/2001/XMLSc<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">hema"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;xs:element name="Dog" nillable="true" type="Dog" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;xs:complexType name="Dog"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:complexContent mixed="false"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:extension base="Animal"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:sequence&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:element minOccurs="1" maxOccurs="1" name="breed" type="DogBreed" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;/xs:sequence&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;/xs:extension&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;/xs:complexContent&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;/xs:complexType&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;xs:complexType name="Animal"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:sequence&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:element minOccurs="1" maxOccurs="1" name="age" type="xs:int" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:element minOccurs="0" maxOccurs="1" name="name" type="xs:string" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;/xs:sequence&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;/xs:complexType&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;xs:simpleType name="DogBreed"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:restriction base="xs:string"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:enumeration value="GermanShepherd" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:enumeration value="LabradorRetriever" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;/xs:restriction&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;/xs:simpleType&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">&lt;/xs:schema&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">-------------------------------------------<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">//------------------------------------------------------------------------------<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">// &lt;auto-generated&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">//<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>This code was generated by a tool.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">//<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Runtime Version:4.0.30319.1<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">//<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">//<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>Changes to this file may cause incorrect behavior and will be lost if<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">//<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>the code is regenerated.<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">// &lt;/auto-generated&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">//------------------------------------------------------------------------------<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">/// &lt;remarks/&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.CodeDom.Compiler.GeneratedCodeAttribute("Serialization", "0.0.0.0")]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.SerializableAttribute()]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.Diagnostics.DebuggerStepThroughAttribute()]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.ComponentModel.DesignerCategoryAttribute("code")]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=true)]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">public partial class Dog : Animal {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>private DogBreed breedField;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>/// &lt;remarks/&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>public DogBreed breed {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>get {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return this.breedField;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>set {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>this.breedField = value;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">/// &lt;remarks/&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.CodeDom.Compiler.GeneratedCodeAttribute("Serialization", "0.0.0.0")]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.SerializableAttribute()]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">public enum DogBreed {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>/// &lt;remarks/&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>GermanShepherd,<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>/// &lt;remarks/&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>LabradorRetriever,<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">/// &lt;remarks/&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.Xml.Serialization.XmlIncludeAttribute(typeof(Dog))]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.CodeDom.Compiler.GeneratedCodeAttribute("Serialization", "0.0.0.0")]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.SerializableAttribute()]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.Diagnostics.DebuggerStepThroughAttribute()]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">[System.ComponentModel.DesignerCategoryAttribute("code")]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">public partial class Animal {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>private int ageField;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>private string nameField;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>/// &lt;remarks/&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>public int age {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>get {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN>return this.ageField;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>set {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>this.ageField = value;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>/// &lt;remarks/&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>public string name {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>get {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>return this.nameField;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>set {<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>this.nameField = value;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt">}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>Notice that the generated types look very similar to the types we started out with. In fact, as far as XmlSerializer is concerned, those types are equivalent. If you create an instance of your original class and an instance of the roundtripped class with the same values, you’ll get exactly the same XML output on the wire. That’s the guarantee that metadata roundtrips provide.<o:p></o:p></FONT></FONT></P>]]></content:encoded>
    </item>
    <item>
      <title>How to get minOccurs = 0 in the schema for XmlSerializer struct members</title>
      <link>https://docs.microsoft.com/archive/blogs/youssefm/how-to-get-minoccurs-0-in-the-schema-for-xmlserializer-struct-members</link>
      <pubDate>Mon, 22 Mar 2010 16:52:00 GMT</pubDate>
      <dc:creator><![CDATA[Youssef Moussaoui - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/youssefm/2010/03/22/how-to-get-minoccurs-0-in-the-schema-for-xmlserializer-struct-members/</guid>
      <description><![CDATA[If you try exporting the following type into an XML schema:
&nbsp;
public class...]]></description>
      <content:encoded><![CDATA[<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>If you try exporting the following type into an XML schema:<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9.5pt">public</SPAN><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: #2b91af">Employee</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">{<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: #2b91af">DateTime</SPAN> BirthDate { <SPAN style="COLOR: blue">get</SPAN>; <SPAN style="COLOR: blue">set</SPAN>; }<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>And you happen to be using XmlSerializer, you may be surprised to find that the schema gets exposed like this:<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt">&lt;xs:schema elementFormDefault="qualified" xmlns:xs="https://www.w3.org/2001/XMLSchema"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;xs:element name="Employee" nillable="true" type="Employee" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;xs:complexType name="Employee"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:sequence&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:element <SPAN style="BACKGROUND: yellow; mso-highlight: yellow">minOccurs="1"</SPAN> maxOccurs="1" name="BirthDate" type="xs:dateTime" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;/xs:sequence&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;/xs:complexType&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt">&lt;/xs:schema&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P><FONT face=Calibri>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-bidi-font-family: Calibri"><FONT size=3>Notice that minOccurs gets set to 1. This means that every Employee should have a BirthDate. The reason XmlSerializer does this is because structs cannot be set to null. They must have a value. So XmlSerializer tries to represent this by always setting minOccurs to 1 by default. This prevents miscommunication if the serializer and deserializer have different defaults for a certain type. For example, DateTime’s default constructor set its value to January 1st, Year 1. If a different stack used the Year 2000 as the default value for DateTimes, how would XmlSerializer know how to interpret the value of an Employee that doesn’t have a BirthDate? The serializer would think it was sending a DateTime for Year 2000, and the deserializer would think it was reading a DateTime for Year 1. And XmlSerializer can’t set DateTime to null to indicate that it wasn’t specified. With that said, you may want to force XmlSerializer to emit minOccurs = 0 if you know for a fact that the serializer and deserializer have the same defaults for that type.<o:p></o:p></FONT></SPAN></P><o:p></o:p></FONT>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>Here’s how to do it:<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9.5pt">public</SPAN><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: #2b91af">Employee</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">{<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: #2b91af">DateTime</SPAN> BirthDate { <SPAN style="COLOR: blue">get</SPAN>; <SPAN style="COLOR: blue">set</SPAN>; }<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="BACKGROUND: yellow; mso-highlight: yellow">[<SPAN style="COLOR: #2b91af">XmlIgnore</SPAN>]<o:p></o:p></SPAN></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; BACKGROUND: yellow; FONT-SIZE: 9.5pt; mso-highlight: yellow"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">bool</SPAN> BirthDateSpecified { <SPAN style="COLOR: blue">get</SPAN>; <SPAN style="COLOR: blue">set</SPAN>; }</SPAN><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">}<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>The BirthDateSpecified property tells XmlSerializer whether the BirthDate is specified or not. If you exported the schema for this type, you’d get:<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt">&lt;xs:schema elementFormDefault="qualified" xmlns:xs="https://www.w3.org/2001/XMLSchema"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;xs:element name="Employee" nillable="true" type="Employee" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;xs:complexType name="Employee"&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:sequence&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>&lt;xs:element <SPAN style="BACKGROUND: yellow; mso-highlight: yellow">minOccurs="0"</SPAN> maxOccurs="1" name="BirthDate" type="xs:dateTime" /&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>&lt;/xs:sequence&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN>&lt;/xs:complexType&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><SPAN style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 9pt">&lt;/xs:schema&gt;<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>So you essentially create a public field or property with a Boolean type and the name of the struct member plus the string “Specified”. You should also mark it as [XmlIgnore] to make sure that this new member doesn’t get serialized out. The Boolean member then tells the serializer whether the struct member is specified or not. If the Boolean member is false, then XmlSerializer will not serialize out the struct member. So, for example, if you tried serializing this object:<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><o:p>&nbsp;</o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">o = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">Employee</SPAN>() { BirthDate = <SPAN style="COLOR: blue">new</SPAN> <SPAN style="COLOR: #2b91af">DateTime</SPAN>(1986, 11, 1), BirthDateSpecified = <SPAN style="COLOR: blue">false</SPAN> };<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><FONT size=3><FONT face=Calibri>BirthDate would not get serialized out, even though you’ve assigned it a value. A helpful tip in this kind of situation is to have BirthDateSpecified’s getter check BirthDate’s value. This way you can avoid serializing out BirthDate only if it corresponds to a certain default value. Or use Nullable&lt;T&gt; in this kind of pattern:<o:p></o:p></FONT></FONT></P>
<P style="MARGIN: 0in 0in 0pt" class=MsoNormal><o:p><FONT size=3 face=Calibri>&nbsp;</FONT></o:p></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; COLOR: blue; FONT-SIZE: 9.5pt">public</SPAN><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"> <SPAN style="COLOR: blue">class</SPAN> <SPAN style="COLOR: #2b91af">Employee</SPAN><o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">{<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="BACKGROUND: yellow; COLOR: #2b91af; mso-highlight: yellow">DateTime</SPAN><SPAN style="BACKGROUND: yellow; mso-highlight: yellow">?</SPAN> BirthDate { <SPAN style="COLOR: blue">get</SPAN>; <SPAN style="COLOR: blue">set</SPAN>; }<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN>[<SPAN style="COLOR: #2b91af">XmlIgnore</SPAN>]<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: blue">public</SPAN> <SPAN style="COLOR: blue">bool</SPAN> BirthDateSpecified { <SPAN style="COLOR: blue">get</SPAN> { <SPAN style="BACKGROUND: yellow; COLOR: blue; mso-highlight: yellow">return</SPAN><SPAN style="BACKGROUND: yellow; mso-highlight: yellow"> BirthDate != <SPAN style="COLOR: blue">null</SPAN>;</SPAN> } }<o:p></o:p></SPAN></P>
<P style="MARGIN: 0in 0in 0pt; mso-layout-grid-align: none" class=MsoNormal><SPAN style="FONT-FAMILY: Consolas; FONT-SIZE: 9.5pt">}<o:p></o:p></SPAN></P>]]></content:encoded>
    </item>
  </channel>
</rss>