<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Chris Tacke</title>
    <link>http://blog.opennetcf.com/ctacke/</link>
    <description>Bringing Managed Code to the Embedded World</description>
    <copyright>Chris Tacke</copyright>
    <lastBuildDate>Fri, 05 Feb 2010 22:51:01 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.8.5223.2</generator>
    <managingEditor>ctacke@opennetcf.com</managingEditor>
    <webMaster>ctacke@opennetcf.com</webMaster>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=6f37f2f3-804d-4da0-bc7c-289e9cf83fbd</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,6f37f2f3-804d-4da0-bc7c-289e9cf83fbd.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,6f37f2f3-804d-4da0-bc7c-289e9cf83fbd.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=6f37f2f3-804d-4da0-bc7c-289e9cf83fbd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      In <a href="http://blog.opennetcf.com/ctacke/2010/02/05/HostingRESTfulWebServicesInWindowsCEPartI.aspx">the
      last article</a> we looked at setting up <a href="http://opennetcf.com/padarn.ocf">Padarn</a> for
      using custom HttpHandlers.  In this article we'll look at exactly how we use
      a custom handler to get data.
   </p>
        <p>
          <strong>
            <u>The GET Service</u>
          </strong>
        </p>
        <p>
      Probably the most common HTTP method is the GET method.  It's what your browser
      used to pull the content of this page, and it's what our REST service will use to
      get back a list of all Books in our database.
   </p>
        <p>
      First, I create an entity that defines a Book.  This code file will actually
      get shared between the device and desktop projects to make things simple.
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> Book<br />
      {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> ID
      { get; set; }<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> Title
      { get; set; }<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> Author
      { get; set; }<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span>?
      Pages { get; set; }<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">static</span> Book
      FromXml(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> xml)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>{<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span>//
      omitted for brevity</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>}<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> AsXml()<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>{<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span>//
      omitted for brevity</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>}<br />
      }<br /></span>
        </p>
        <p>
      I've left out the XML serialization/deserialization routines because they take up
      a lot of space and aren't really that interesting.  They're in the example source
      (I'll post it when I get these articles up - be patient) if you want to see them.
   </p>
        <p>
      So next I need a way to get a list of these from my Database.  To encapsulate
      all of this logic, I created a DatabaseConnector singleton class that resides
      in the same assembly as the HttpHandlers.  Remember, these handlers are stateless
      and get created and called every time a URL is requested, so it would be pointless
      to put a connector instance in the handler itself.
   </p>
        <p>
      The DatabaseConnector exposes a GetAllBooks method:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span> Book[]
      GetAllBooks()<br />
      {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      string</span> sql <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"SELECT
      BookID, Title, Author, Pages FROM Books"</span>;<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>List&lt;Book&gt;
      books <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> List&lt;Book&gt;();<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>using</span>(SqlCeCommand
      cmd <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> SqlCeCommand(sql,
      Connection))<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>using</span>(var
      resultset <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> cmd.ExecuteResultSet(ResultSetOptions.Scrollable))<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>{<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span>if</span> (resultset.HasRows)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span>{<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span></span>while</span> (resultset.Read())<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span></span>{<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span></span></span>books.Add(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> Book<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span></span></span>{<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">    </span></span></span></span>ID <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> resultset.GetInt32(0),<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">    </span></span></span></span>Title <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> resultset.GetString(1),<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">    </span></span></span></span>Author <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> resultset.GetString(2),<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">    </span></span></span></span>Pages <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> resultset.IsDBNull(3)
      ? <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">null</span> :
      (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span>?)resultset.GetInt32(3)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span></span></span>});<br />
            }<br />
          }<br />
        }<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      return</span> books.ToArray();<br />
      }<br /></span>
        </p>
        <p>
      Now all that I need to do is call this from my GetHandler like so:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> GetHandler
      : BaseHandler<br />
      {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">override</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> ProcessRequest(HttpContext
      context)<br />
      {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      string</span> entity <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> GetEntityName(context.Request.Path);<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>//
      the only entity we support is "Books"</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>if</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Compare(entity, <span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"books"</span>, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">true</span>)
      !<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 0)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>{<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span>throw</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> HttpException(HttpErrorCode.NotFound, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Format(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"Entity
      '{0}' not supported"</span>, entity));<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>}<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>Book[]
      books <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> DataConnector.GetInstance().GetAllBooks();<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>StringBuilder
      sb <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> StringBuilder(XML_HEADER);<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>sb.Append(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"&lt;books&gt;"</span>);<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>foreach</span> (var
      b <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">in</span> books)<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>{<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span></span>sb.Append(b.AsXml());<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>}<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>sb.Append(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"&lt;/books&gt;"</span>);<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>context.Response.Write(sb.ToString());<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>context.Response.Flush();<br />
      }<br /><br /></span>
        </p>
        <p>
      That's all there is to it.  We now have implemented a REST service to get all
      Books from our Windows CE device.  When the Padarn server sees a GET request
      at <a href="http://%3cip/">http://&lt;ip</a> address&gt;/books/ it will return an
      XML stream of all of the books in the database.  Here's an example of the output:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">&lt;?xml
      version=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"1.0"</span> encoding=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"UTF-8"</span>?&gt;<br />
      &lt;books&gt;<br />
        &lt;book&gt;<br />
          &lt;id&gt;1&lt;/id&gt;<br />
          &lt;title&gt;The Count of Monte Cristo&lt;/title&gt;<br />
          &lt;author&gt;Alexandre Dumas&lt;/author&gt;<br />
          &lt;pages&gt;1573&lt;/pages&gt;<br />
        &lt;/book&gt;<br />
        &lt;book&gt;<br />
          &lt;id&gt;2&lt;/id&gt;<br />
          &lt;title&gt;Programming WCF Services&lt;/title&gt;<br />
          &lt;author&gt;Juval Loewy&lt;/author&gt;<br />
          &lt;pages&gt;610&lt;/pages&gt;<br />
        &lt;/book&gt;<br />
      &lt;/books&gt;</span>
        </p>
        <p>
          <strong>
            <u>The GET Client</u>
          </strong>
        </p>
        <p>
      Now let's look at how a non-browser client (i.e. a desktop application) might make
      use of this service.
   </p>
        <p>
      First, since I like abstraction and encapsulation, I created a class named RestConnector
      that handles all communications for REST services and a class named BookClient
      who's job is to handle nothing but interactions with the Books service.  RestConnector
      handles any GET requirements through the following methods:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> Get(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> directory)<br />
      {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      string</span> page <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span>.Format(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"http://{0}/{1}"</span>,
      DeviceAddress, directory);<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>StringBuilder
      sb <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> StringBuilder();<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>byte</span>[]
      buf <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">byte</span>[8192];<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>HttpWebRequest
      request <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (HttpWebRequest)WebRequest.Create(page);<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>HttpWebResponse
      response <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (HttpWebResponse)request.GetResponse();<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">  </span>return</span> GetResponseData(response);<br />
      }</span>
        </p>
        <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
          <p>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
              <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">private</span>
              <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">string</span> GetResponseData(HttpWebResponse
      response)<br />
      {<br />
        StringBuilder sb <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> StringBuilder();<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">  </font>byte</span>[]
      buf <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">byte</span>[8192];<br /><br />
        Stream stream <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> response.GetResponseStream();<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">  </font>string</span> result <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">null</span>;<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">  </font>int</span> count <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 0;<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">  </font>do</span><br />
        {<br />
          count <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> stream.Read(buf,
      0, buf.Length);<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">    </font>if</span> (count
      !<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> 0)<br />
          {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"><font color="#000000">      </font>//
      look for a UTF8 header</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">      </font>if</span> ((buf[0]
      == 0xEF) &amp;&amp; (buf[1] == 0xBB) &amp;&amp; (buf[2] == 0xBF))<br />
            {<br />
              result <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> Encoding.UTF8.GetString(buf,
      3, count <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">-</span> 3);<br />
            }<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">      </font>else</span><br />
            {<br />
              result <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> Encoding.UTF8.GetString(buf,
      0, count);<br />
            }<br />
            sb.Append(result);<br />
          }<br />
        } <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">while</span> (count
      &gt; 0);<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">  </font>return</span> sb.ToString();<br />
      }<br /></span>
          </p>
        </span>
        <p>
      The BookClient uses the Get method to retrieve the XML for a list of books from the
      service and then deserializes that XML like this:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span> Book[]
      GetAllBooks()<br />
      {<br />
        List&lt;Book&gt; books <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> List&lt;Book&gt;();<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">  </font>string</span> xml <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> Connector.Get(ENTITY_NAME);<br /><br />
          XmlDocument doc <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">new</span> XmlDocument();<br />
        doc.LoadXml(xml);<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">  </font>foreach</span> (XmlNode
      node <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">in</span> doc.SelectNodes(<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"books/book"</span>))<br />
        {<br />
          books.Add(Book.FromXml(node.OuterXml));<br />
        }<br /><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">  </font>return</span> books.ToArray();<br />
      }<br /></span>
        </p>
        <p>
      It's really that simple.  At this point we have a simple array of Book instances
      passed from our service to our desktop client so we can do whatever we'd like with
      them (I'm just displaying them).
   </p>
        <p>
          <img border="0" src="http://blog.opennetcf.com/ctacke/content/binary/booklist.PNG" />
        </p>
        <p>
      Up next: Using POST to add a new entity
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=6f37f2f3-804d-4da0-bc7c-289e9cf83fbd" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Hosting RESTful Web Services in Windows CE - Part II</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,6f37f2f3-804d-4da0-bc7c-289e9cf83fbd.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2010/02/05/HostingRESTfulWebServicesInWindowsCEPartII.aspx</link>
      <pubDate>Fri, 05 Feb 2010 22:51:01 GMT</pubDate>
      <description>&lt;p&gt;
   In &lt;a href="http://blog.opennetcf.com/ctacke/2010/02/05/HostingRESTfulWebServicesInWindowsCEPartI.aspx"&gt;the
   last article&lt;/a&gt; we looked at setting up &lt;a href="http://opennetcf.com/padarn.ocf"&gt;Padarn&lt;/a&gt; for
   using custom HttpHandlers.&amp;nbsp; In this article we'll look at exactly how we use
   a custom handler to get data.
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;&lt;u&gt;The GET Service&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   Probably the most common HTTP method is the GET method.&amp;nbsp; It's what your browser
   used to pull the content of this page, and it's what our REST service will use to
   get back a list of all Books in our database.
&lt;/p&gt;
&lt;p&gt;
   First, I create an entity that defines a Book.&amp;nbsp; This code file will actually
   get shared between the device and desktop projects to make things simple.
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; Book&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; ID
   { get; set; }&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; Title
   { get; set; }&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; Author
   { get; set; }&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt;?
   Pages { get; set; }&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;static&lt;/span&gt; Book
   FromXml(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; xml)&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;{&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;//
   omitted for brevity&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; AsXml()&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;{&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;//
   omitted for brevity&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
   }&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   I've left out the XML serialization/deserialization routines because they take up
   a lot of space and aren't really that interesting.&amp;nbsp; They're in the example source
   (I'll post it when I get these articles up - be patient) if you want to see them.
&lt;/p&gt;
&lt;p&gt;
   So next I need a way to get a list of these from my Database.&amp;nbsp; To encapsulate
   all of this logic, I created a DatabaseConnector singleton class that&amp;nbsp;resides
   in the same assembly as the HttpHandlers.&amp;nbsp; Remember, these handlers are stateless
   and get created and called every time a URL is requested, so it would be pointless
   to put&amp;nbsp;a connector instance in the handler itself.
&lt;/p&gt;
&lt;p&gt;
   The DatabaseConnector exposes a GetAllBooks method:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; Book[]
   GetAllBooks()&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   string&lt;/span&gt; sql &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"SELECT
   BookID, Title, Author, Pages FROM Books"&lt;/span&gt;;&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;List&amp;lt;Book&amp;gt;
   books &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; List&amp;lt;Book&amp;gt;();&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;using&lt;/span&gt;(SqlCeCommand
   cmd &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; SqlCeCommand(sql,
   Connection))&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;using&lt;/span&gt;(var
   resultset &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; cmd.ExecuteResultSet(ResultSetOptions.Scrollable))&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;{&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;if&lt;/span&gt; (resultset.HasRows)&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;{&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;while&lt;/span&gt; (resultset.Read())&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;{&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;books.Add(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; Book&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;{&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;ID &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; resultset.GetInt32(0),&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Title &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; resultset.GetString(1),&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Author &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; resultset.GetString(2),&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Pages &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; resultset.IsDBNull(3)
   ? &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;null&lt;/span&gt; :
   (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt;?)resultset.GetInt32(3)&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;});&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; }&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
   &amp;nbsp; }&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   return&lt;/span&gt; books.ToArray();&lt;br&gt;
   }&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   Now all that I need to do is call this from my GetHandler like so:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; GetHandler
   : BaseHandler&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;override&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; ProcessRequest(HttpContext
   context)&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   string&lt;/span&gt; entity &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; GetEntityName(context.Request.Path);&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;//
   the only entity we support is "Books"&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;if&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Compare(entity, &lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"books"&lt;/span&gt;, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;true&lt;/span&gt;)
   !&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 0)&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;{&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;throw&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; HttpException(HttpErrorCode.NotFound, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Format(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"Entity
   '{0}' not supported"&lt;/span&gt;, entity));&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;Book[]
   books &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; DataConnector.GetInstance().GetAllBooks();&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;StringBuilder
   sb &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; StringBuilder(XML_HEADER);&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;sb.Append(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"&amp;lt;books&amp;gt;"&lt;/span&gt;);&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;foreach&lt;/span&gt; (var
   b &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;in&lt;/span&gt; books)&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;{&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;sb.Append(b.AsXml());&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;}&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;sb.Append(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"&amp;lt;/books&amp;gt;"&lt;/span&gt;);&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;context.Response.Write(sb.ToString());&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;context.Response.Flush();&lt;br&gt;
   }&lt;br&gt;
   &lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   That's all there is to it.&amp;nbsp; We now have implemented a REST service to get all
   Books from our Windows CE device.&amp;nbsp; When the Padarn server sees a GET request
   at &lt;a href="http://%3cip/"&gt;http://&amp;lt;ip&lt;/a&gt; address&amp;gt;/books/ it will return an
   XML stream of all of the books in the database.&amp;nbsp; Here's an example of the output:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;lt;?xml
   version=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"1.0"&lt;/span&gt; encoding=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"UTF-8"&lt;/span&gt;?&amp;gt;&lt;br&gt;
   &amp;lt;books&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;book&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;id&amp;gt;1&amp;lt;/id&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;title&amp;gt;The Count of Monte Cristo&amp;lt;/title&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;author&amp;gt;Alexandre Dumas&amp;lt;/author&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;pages&amp;gt;1573&amp;lt;/pages&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;/book&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;book&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;id&amp;gt;2&amp;lt;/id&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;title&amp;gt;Programming WCF Services&amp;lt;/title&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;author&amp;gt;Juval Loewy&amp;lt;/author&amp;gt;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;pages&amp;gt;610&amp;lt;/pages&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;/book&amp;gt;&lt;br&gt;
   &amp;lt;/books&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;&lt;u&gt;The GET Client&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   Now let's look at how a non-browser client (i.e. a desktop application) might make
   use of this service.
&lt;/p&gt;
&lt;p&gt;
   First, since I like abstraction and encapsulation, I created a class named RestConnector
   that handles all communications for REST services and a class&amp;nbsp;named BookClient
   who's job is to handle nothing but interactions with the Books service.&amp;nbsp; RestConnector
   handles any GET requirements through the following methods:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; Get(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; directory)&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   string&lt;/span&gt; page &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt;.Format(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"http://{0}/{1}"&lt;/span&gt;,
   DeviceAddress, directory);&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;StringBuilder
   sb &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; StringBuilder();&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;byte&lt;/span&gt;[]
   buf &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;byte&lt;/span&gt;[8192];&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;HttpWebRequest
   request &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (HttpWebRequest)WebRequest.Create(page);&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;HttpWebResponse
   response &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (HttpWebResponse)request.GetResponse();&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp; &lt;/span&gt;return&lt;/span&gt; GetResponseData(response);&lt;br&gt;
   }&lt;/span&gt;
&lt;/p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; 
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;private&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;string&lt;/span&gt; GetResponseData(HttpWebResponse
   response)&lt;br&gt;
   {&lt;br&gt;
   &amp;nbsp; StringBuilder sb &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; StringBuilder();&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp; &lt;/font&gt;byte&lt;/span&gt;[]
   buf &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;byte&lt;/span&gt;[8192];&lt;br&gt;
   &lt;br&gt;
   &amp;nbsp; Stream stream &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; response.GetResponseStream();&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp; &lt;/font&gt;string&lt;/span&gt; result &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;null&lt;/span&gt;;&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp; &lt;/font&gt;int&lt;/span&gt; count &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 0;&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp; &lt;/font&gt;do&lt;/span&gt;
   &lt;br&gt;
   &amp;nbsp; {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; count &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; stream.Read(buf,
   0, buf.Length);&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/span&gt; (count
   !&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; 0)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;//
   look for a UTF8 header&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;if&lt;/span&gt; ((buf[0]
   == 0xEF) &amp;amp;&amp;amp; (buf[1] == 0xBB) &amp;amp;&amp;amp; (buf[2] == 0xBF))&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; Encoding.UTF8.GetString(buf,
   3, count &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;-&lt;/span&gt; 3);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;else&lt;/span&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; Encoding.UTF8.GetString(buf,
   0, count);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sb.Append(result);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
   &amp;nbsp; } &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;while&lt;/span&gt; (count
   &amp;gt; 0);&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp; &lt;/font&gt;return&lt;/span&gt; sb.ToString();&lt;br&gt;
   }&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;/span&gt; 
&lt;p&gt;
   The BookClient uses the Get method to retrieve the XML for a list of books from the
   service and then deserializes that XML like this:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; Book[]
   GetAllBooks()&lt;br&gt;
   {&lt;br&gt;
   &amp;nbsp; List&amp;lt;Book&amp;gt; books &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; List&amp;lt;Book&amp;gt;();&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp; &lt;/font&gt;string&lt;/span&gt; xml &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; Connector.Get(ENTITY_NAME);&lt;br&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; XmlDocument doc &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;new&lt;/span&gt; XmlDocument();&lt;br&gt;
   &amp;nbsp; doc.LoadXml(xml);&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp; &lt;/font&gt;foreach&lt;/span&gt; (XmlNode
   node &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;in&lt;/span&gt; doc.SelectNodes(&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"books/book"&lt;/span&gt;))&lt;br&gt;
   &amp;nbsp; {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; books.Add(Book.FromXml(node.OuterXml));&lt;br&gt;
   &amp;nbsp; }&lt;br&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp; &lt;/font&gt;return&lt;/span&gt; books.ToArray();&lt;br&gt;
   }&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   It's really that simple.&amp;nbsp; At this point we have a simple array of Book instances
   passed from our service to our desktop client so we can do whatever we'd like with
   them (I'm just displaying them).
&lt;/p&gt;
&lt;p&gt;
   &lt;img border=0 src="http://blog.opennetcf.com/ctacke/content/binary/booklist.PNG"&gt;
&lt;/p&gt;
&lt;p&gt;
   Up next:&amp;nbsp;Using POST to add a new entity
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=6f37f2f3-804d-4da0-bc7c-289e9cf83fbd" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,6f37f2f3-804d-4da0-bc7c-289e9cf83fbd.aspx</comments>
      <category>OpenNETCF;Padarn</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=3bb711da-456e-4914-84f1-29882db0740a</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,3bb711da-456e-4914-84f1-29882db0740a.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,3bb711da-456e-4914-84f1-29882db0740a.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=3bb711da-456e-4914-84f1-29882db0740a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I've spent a bit of time lately adding <a href="http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx">HttpHandler</a> support
      to our <a href="http://opennetcf.com/padarn.ocf">Padarn Web Server for Windows CE</a>,
      and today I just wrapped up the code for a pretty in-depth example for using it to
      host <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">RESTful
      Web Services</a>.  I'm going to give some highlights on how it works here in
      my blog as well, because while it's remarkably easy to get working, there's still
      a lot going on.
   </p>
        <p>
          <strong>
            <u>Background</u>
          </strong>
        </p>
        <p>
      The general idea is to have a database on a Windows CE device and a client application
      on the desktop that could access that database via a Web Service hosted on the device. 
      I want to be able to do all of the <a href="http://en.wikipedia.org/wiki/CRUD">CRUD
      operations</a> through the service, and nicely these to the <a href="http://en.wikipedia.org/wiki/HTTP#Request_methods">HTTP
      methods</a>:
   </p>
        <blockquote style="MARGIN-RIGHT: 0px" dir="ltr">
          <p>
      POST - Create a new entity in the database<br />
      PUT - Update an existing entity in the database<br />
      GET - Read an entity (or list of entities) from the database<br />
      DELETE - Delete an entity from the database
   </p>
        </blockquote>
        <p>
      To make things simple, I created a very simple database that contains only one table. 
      The simple data model isn't real-world, but if you can make it work for one table,
      making it work for your entire database is really just an extension of the code base.
   </p>
        <p>
          <img border="0" src="http://blog.opennetcf.com/ctacke/content/binary/booksdb.PNG" />
        </p>
        <p>
          <strong>
            <u>Setting Up Padarn</u>
          </strong>
        </p>
        <p>
      I'm going to use custom HttpHandlers to act as the service entry points.  HttpHandlers
      in Padarn look and work just like they do under IIS, the only difference is how they
      get "installed:. For Padarn, the handlers are configured, like everything else,
      in Padarn's configuration file.  To make my life simpler, and the code easier
      to read, I'll create a separate handler for each separate HTTP method, so one for
      GET, one for POST and so on.  This is how they get registered with the server:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">&lt;httpHandlers&gt;<br />
        &lt;assembly&gt;SampleSite.dll&lt;/assembly&gt;<br />
        &lt;add verb=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"GET"</span> path=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"/*"</span> type=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"SampleSite.Handlers.GetHandler,
      SampleSite"</span>/&gt;<br />
        &lt;add verb=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"PUT"</span> path=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"/*"</span> type=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"SampleSite.Handlers.PutHandler,
      SampleSite"</span>/&gt;<br />
        &lt;add verb=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"POST"</span> path=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"/*"</span> type=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"SampleSite.Handlers.PostHandler,
      SampleSite"</span>/&gt;<br />
        &lt;add verb=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"DELETE"</span> path=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"/*"</span> type=<span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px">"SampleSite.Handlers.DeleteHandler,
      SampleSite"</span>/&gt;<br />
      &lt;/httpHandlers&gt;</span>
        </p>
        <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
        </span>
        <p>
      Pretty simple. the "add" nodes simply say what method/verb in any given server path
      maps to a given class.  Padarn uses regex to parse the path, so the first add
      line basically says "for GET methods to any path on the server, call into an instance
      of a GetHandler class".  Since the GetHandler is in a separate assembly from
      my hosting executable, Padarn needs to know about that assembly so it can load it
      at run time.  The assembly node simply tells Padarn to load up that assembly
      before it tries creating any custom handler class instances.
   </p>
        <p>
      Once this is configured, the only thing left to do is to implement the handlers. 
      An HttpHandler is really simple - it contains a single overriden method that gets
      called when a page is requested.  Here's what the GetHandler stub looks like:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">namespace</span> SampleSite.Handlers<br />
      {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">class</span> GetHandler
      : BaseHandler<br />
        {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">   
      public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">override</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> ProcessRequest(HttpContext
      context)<br />
          {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">     
      // do stuff here</span><br />
          }<br />
        }<br />
      }<br /></span>
        </p>
        <p>
      I get in an <a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx">HttpContext</a>,
      which has both the <a href="http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx">HttpRequest</a> and <a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.response.aspx">HttpResponse</a> objects.
      Note how we're trying very hard to mirror the object model Microsoft uses to make
      the learning curve much easier and to make your code more portable.  The HttpRequest
      contains, among other things, the incoming path and data.  The HttpResponse
      is where we write back out our data.  
   </p>
        <p>
      SImple enough so far, right?  Next up: <a href="http://blog.opennetcf.com/ctacke/2010/02/05/HostingRESTfulWebServicesInWindowsCEPartII.aspx">getting
      data from our RESTful service</a>.<br />
       
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=3bb711da-456e-4914-84f1-29882db0740a" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Hosting RESTful Web Services in Windows CE - Part I</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,3bb711da-456e-4914-84f1-29882db0740a.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2010/02/05/HostingRESTfulWebServicesInWindowsCEPartI.aspx</link>
      <pubDate>Fri, 05 Feb 2010 22:18:58 GMT</pubDate>
      <description>&lt;p&gt;
   I've spent a bit of time lately adding &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ihttphandler.aspx"&gt;HttpHandler&lt;/a&gt; support
   to our &lt;a href="http://opennetcf.com/padarn.ocf"&gt;Padarn Web Server for Windows CE&lt;/a&gt;,
   and today I just wrapped up the code for a pretty in-depth example for using it to
   host &lt;a href="http://en.wikipedia.org/wiki/Representational_State_Transfer"&gt;RESTful
   Web Services&lt;/a&gt;.&amp;nbsp; I'm going to give some highlights on how it works here in
   my blog as well, because while it's remarkably easy to get working, there's still
   a lot going on.
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;&lt;u&gt;Background&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   The general idea&amp;nbsp;is to have a database on a Windows CE device and a client application
   on the desktop that could access that database via a Web Service hosted on the device.&amp;nbsp;
   I want to be able to do all of the &lt;a href="http://en.wikipedia.org/wiki/CRUD"&gt;CRUD
   operations&lt;/a&gt; through the service, and nicely these to the &lt;a href="http://en.wikipedia.org/wiki/HTTP#Request_methods"&gt;HTTP
   methods&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote style="MARGIN-RIGHT: 0px" dir=ltr&gt; 
&lt;p&gt;
   POST - Create a new entity in the database&lt;br&gt;
   PUT&amp;nbsp;- Update an existing entity in the database&lt;br&gt;
   GET - Read an entity (or list of entities) from the database&lt;br&gt;
   DELETE - Delete an entity from the database
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
   To make things simple, I created a very simple database that contains only one table.&amp;nbsp;
   The simple data model isn't real-world, but if you can make it work for one table,
   making it work for your entire database is really just an extension of the code base.
&lt;/p&gt;
&lt;p&gt;
   &lt;img border=0 src="http://blog.opennetcf.com/ctacke/content/binary/booksdb.PNG"&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;strong&gt;&lt;u&gt;Setting Up Padarn&lt;/u&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
   I'm going to use custom HttpHandlers to act as the service entry points.&amp;nbsp; HttpHandlers
   in Padarn look and work just like they do under IIS, the only difference is how they
   get "installed:.&amp;nbsp;For Padarn, the handlers are configured, like everything else,
   in&amp;nbsp;Padarn's configuration file.&amp;nbsp; To make my life simpler, and the code easier
   to read, I'll create a separate handler for each separate HTTP method, so one for
   GET, one for POST and so on.&amp;nbsp; This is how they get registered with the server:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&amp;lt;httpHandlers&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;assembly&amp;gt;SampleSite.dll&amp;lt;/assembly&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;add verb=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"GET"&lt;/span&gt; path=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"/*"&lt;/span&gt; type=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"SampleSite.Handlers.GetHandler,
   SampleSite"&lt;/span&gt;/&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;add verb=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"PUT"&lt;/span&gt; path=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"/*"&lt;/span&gt; type=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"SampleSite.Handlers.PutHandler,
   SampleSite"&lt;/span&gt;/&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;add verb=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"POST"&lt;/span&gt; path=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"/*"&lt;/span&gt; type=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"SampleSite.Handlers.PostHandler,
   SampleSite"&lt;/span&gt;/&amp;gt;&lt;br&gt;
   &amp;nbsp; &amp;lt;add verb=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"DELETE"&lt;/span&gt; path=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"/*"&lt;/span&gt; type=&lt;span style="BACKGROUND-COLOR: #e4e4e4; FONT-FAMILY: Courier New; COLOR: #666666; FONT-SIZE: 11px"&gt;"SampleSite.Handlers.DeleteHandler,
   SampleSite"&lt;/span&gt;/&amp;gt;&lt;br&gt;
   &amp;lt;/httpHandlers&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;/span&gt; 
&lt;p&gt;
   Pretty simple. the "add" nodes simply say what method/verb in any given server path
   maps to a given class.&amp;nbsp; Padarn uses regex to parse the path, so the first add
   line basically says "for GET methods to any path on the server, call into an instance
   of a GetHandler class".&amp;nbsp; Since the GetHandler is in a separate assembly from
   my hosting executable, Padarn needs to know about that assembly so it can load it
   at run time.&amp;nbsp; The assembly node simply tells Padarn to load up that assembly
   before it tries creating any custom handler class instances.
&lt;/p&gt;
&lt;p&gt;
   Once this is configured, the only thing left to do is to implement the handlers.&amp;nbsp;
   An HttpHandler is really simple - it contains a single overriden method that gets
   called when a page is requested.&amp;nbsp; Here's what the GetHandler stub looks like:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;namespace&lt;/span&gt; SampleSite.Handlers&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;class&lt;/span&gt; GetHandler
   : BaseHandler&lt;br&gt;
   &amp;nbsp; {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
   public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;override&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; ProcessRequest(HttpContext
   context)&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
   // do stuff here&lt;/span&gt;
   &lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
   &amp;nbsp; }&lt;br&gt;
   }&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   I get in an &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.aspx"&gt;HttpContext&lt;/a&gt;,
   which has both the &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx"&gt;HttpRequest&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.httpcontext.response.aspx"&gt;HttpResponse&lt;/a&gt; objects.
   Note how we're trying very hard to mirror the object model Microsoft uses to make
   the learning curve much easier and to make your code more portable.&amp;nbsp; The HttpRequest
   contains, among other things,&amp;nbsp;the incoming path and data.&amp;nbsp; The HttpResponse
   is where&amp;nbsp;we write back out our data.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
   SImple enough so far, right?&amp;nbsp; Next up: &lt;a href="http://blog.opennetcf.com/ctacke/2010/02/05/HostingRESTfulWebServicesInWindowsCEPartII.aspx"&gt;getting
   data from our RESTful service&lt;/a&gt;.&lt;br&gt;
   &amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=3bb711da-456e-4914-84f1-29882db0740a" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,3bb711da-456e-4914-84f1-29882db0740a.aspx</comments>
      <category>OpenNETCF;Padarn</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=70057e9f-88d3-40e1-a015-27aff427d7a1</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,70057e9f-88d3-40e1-a015-27aff427d7a1.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,70057e9f-88d3-40e1-a015-27aff427d7a1.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=70057e9f-88d3-40e1-a015-27aff427d7a1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Well I blew the VB cobwebs out of my brain this morning and wrote a very basic example
      of getting AP info like signal strength using the SDF.  It took me nearly 2 hours
      and a whole lot of search engine work to remind me of syntax to crank out a simple
      70-line application (I actually had to find a machine with VB installed first, as
      it's no longer in my "default" install of Studio).  Hard to believe I was once
      fluent enough in the language to have written a book.
   </p>
        <p>
      At any rate, here's the sample: <a href="http://blog.opennetcf.com/ctacke/content/binary/BasicWiFiSample.rar">BasicWiFiSample.rar
      (532.46 KB)</a></p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=70057e9f-88d3-40e1-a015-27aff427d7a1" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Getting Access Point information from Visual Basic</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,70057e9f-88d3-40e1-a015-27aff427d7a1.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2010/01/13/GettingAccessPointInformationFromVisualBasic.aspx</link>
      <pubDate>Wed, 13 Jan 2010 18:26:21 GMT</pubDate>
      <description>&lt;p&gt;
   Well I blew the VB cobwebs out of my brain this morning and wrote a very basic example
   of getting AP info like signal strength using the SDF.&amp;nbsp; It took me nearly 2 hours
   and a whole lot of search engine work to remind me of syntax to crank out a simple
   70-line application (I actually had to find a machine with VB installed first, as
   it's no longer in my "default" install of Studio).&amp;nbsp; Hard to believe I was once
   fluent enough in the language to have written a book.
&lt;/p&gt;
&lt;p&gt;
   At any rate, here's the sample: &lt;a href="http://blog.opennetcf.com/ctacke/content/binary/BasicWiFiSample.rar"&gt;BasicWiFiSample.rar
   (532.46 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=70057e9f-88d3-40e1-a015-27aff427d7a1" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,70057e9f-88d3-40e1-a015-27aff427d7a1.aspx</comments>
      <category>Compact Framework Code;OpenNETCF;SDF Samples</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=d803c6b4-0681-471e-a314-c6c97e87c0cd</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,d803c6b4-0681-471e-a314-c6c97e87c0cd.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,d803c6b4-0681-471e-a314-c6c97e87c0cd.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=d803c6b4-0681-471e-a314-c6c97e87c0cd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      For those following the <a href="http://ioc.codeplex.com">OpenNETCF IoC Framework</a>,
      I've checked in <a href="http://ioc.codeplex.com/SourceControl/list/changesets">another
      set of fixes</a>.  So yes, it's still an active project.
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=d803c6b4-0681-471e-a314-c6c97e87c0cd" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>OpenNETCF IoC Framework updates</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,d803c6b4-0681-471e-a314-c6c97e87c0cd.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2010/01/06/OpenNETCFIoCFrameworkUpdates.aspx</link>
      <pubDate>Wed, 06 Jan 2010 18:42:12 GMT</pubDate>
      <description>&lt;p&gt;
   For those following the &lt;a href="http://ioc.codeplex.com"&gt;OpenNETCF IoC Framework&lt;/a&gt;,
   I've checked in &lt;a href="http://ioc.codeplex.com/SourceControl/list/changesets"&gt;another
   set of fixes&lt;/a&gt;.&amp;nbsp; So yes, it's still an active project.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=d803c6b4-0681-471e-a314-c6c97e87c0cd" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,d803c6b4-0681-471e-a314-c6c97e87c0cd.aspx</comments>
      <category>.NET Compact Framework;Dependency Injection;OpenNETCF;OpenNETCF.IoC</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=8fdfe95f-9e0f-4f6a-9287-790c59e9b88d</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,8fdfe95f-9e0f-4f6a-9287-790c59e9b88d.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,8fdfe95f-9e0f-4f6a-9287-790c59e9b88d.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=8fdfe95f-9e0f-4f6a-9287-790c59e9b88d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Ages ago I did a science project where I was <a href="http://blog.opennetcf.com/ctacke/2004/11/10/DirectHardwareAccessFromTheCFSure.aspx">reading
      and writing registers from managed code</a>.  It worked well and there is absolutely
      no reason that you shouldn't be able to do this kind of thing.  Windows CE is
      an embedded platform, and affecting hardware is what we do in the embedded world.
   </p>
        <p>
      Well, as with any code posted on the web (and in fact this got rolled into the Smart
      Device Framework), it got used in some actual shipping products.  Great! 
      i'm not the only one who thinks we should be able to do this stuff.
   </p>
        <p>
      Well, over the past 6 months or so I had a few different people contact me saying
      that the code either didn't work, or did work on their earlier hardware, but was now
      giving strange behavior.
   </p>
        <p>
      Most telling was that if you hooked up a scope to the memory, you would see 4 write
      pulses when writing to a register.  Furthermore, all 4 bytes in the register
      ended up getting set to the last byte in the array you wanted to write.  For
      example, if you wrote 0x12345678 to a register, it would actually get set to 0x56565656.
   </p>
        <p>
      Now I know that this code originally worked.  I wrote it using actual hardware
      (PXA255) so the behavior was new.  The fact that there were 4 strobes on the
      memory strongly suggested that the code was actually doing 4 individual
      writes for the 4 bytes, not a single, atomic 4-byte write.
   </p>
        <p>
      I looked at the code and it couldn't be more simple.  A write boiled down to
      this:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> WriteInt32(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> data)<br />
      {<br />
         Marshal.WriteInt32(m_addressPointer, data);<br />
      }</span>
        </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">A
      bit more investigation found that the behavior was fine under CF 1.0, but started
      failing in CF 2.0.  What that means is that Microsoft changed the underlying
      implementation of the Marshal class, and in a bad way.  Why would they do such
      a stupid, stupid thing?  The new mechanism is going to not only cause a break
      for the writes we're looking at, but it's also a lot slower.</span>
        </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">Since
      I don't know who did this, I can only guess as to what happened.  If you write
      a 4-byte value to an address that is not DWORD aligned (i.e. not evenly divisible
      by 4) then an ARM processor with throw a fault and puke on you (x86 throws, but handles
      it internally).  My bet is that some edge case got reported that the CF was throwing
      an unaligned exception, and some idiot developer decided that the heavy-handed solution
      of changing the write to happen byte-by-byte would be the solution.  Yes, it
      prevents the error, but it causes bugs and is bad, bad form.  Personally I'd
      like to slap the persone who made the change and the person who reviewed the change
      and thought it was ok.</span>
        </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">So
      how do you get around this?  Well by doing what the CF itself should have done. 
      Instead of using Marshal, you use unsafe code and pointers, and check address alignnment
      before writing.  Something like this:</span>
        </p>
        <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
          <p>
            <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">
              <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span>
              <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">unsafe</span>
              <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> WriteInt32(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> data, <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">int</span> offset)<br />
      {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      int</span> baseAddr <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (m_addressPointer.ToInt32() <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">+</span> offset);<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      if</span> (baseAddr <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">%</span> 4
      == 0)<br />
        {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px">   
      // dword aligned</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">   
      uint</span>* pDest <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">uint</span>*)(baseAddr);<br />
          *pDest <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">uint</span>)data;<br />
        }<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      else</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">if</span> (baseAddr <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">%</span> 2
      == 0)<br />
        {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"><font color="#000000">    </font>//
      word aligned</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">    </font>ushort</span>*
      pDest <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ushort</span>*)(baseAddr);<br />
          *pDest <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ushort</span>)(data
      &gt;&gt; 0x10);<br />
          pDest += 2;<br />
          *pDest <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">ushort</span>)(data
      &amp; 0xFFFF);<br />
        }<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"> 
      else</span><br />
        {<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"><font color="#000000">    </font>//
      byte aligned</span><br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">    </font>byte</span>*
      pDest <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">byte</span>*)(baseAddr);<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"><font color="#000000">    </font>foreach</span> (<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">byte</span> b <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">in</span> BitConverter.GetBytes(data))<br />
          {<br />
            *pDest <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px">=</span> b;<br />
            pDest++;<br />
          }<br />
        }<br />
      }<br /></span>
          </p>
          <p>
      This is a classic case of someone not understanding the problem they are solving. 
      This logic should have been done well below us - that's the whole point of using managed
      code, right?  To simplify things.  Unfortunately it also allows many
      developers to write code without understanding what it's really doing, and in my mind
      that's crazy risky.  
   </p>
          <p>
      Testing also shows that the Read and Copy methods are similarly broken and all of
      these bugs still exist in CF 3.5, and I strongly suspect it will remain broken
      in future versions.  So beware, if you're using Marshal for moving data, you
      could probably get 4x performance improvement by using a pointer instead.<br /></p>
        </span>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=8fdfe95f-9e0f-4f6a-9287-790c59e9b88d" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Marshal.Copy/Write is no longer atomic?</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,8fdfe95f-9e0f-4f6a-9287-790c59e9b88d.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2010/01/05/MarshalCopyWriteIsNoLongerAtomic.aspx</link>
      <pubDate>Tue, 05 Jan 2010 17:53:28 GMT</pubDate>
      <description>&lt;p&gt;
   Ages ago I did a science project where I was &lt;a href="http://blog.opennetcf.com/ctacke/2004/11/10/DirectHardwareAccessFromTheCFSure.aspx"&gt;reading
   and writing registers from managed code&lt;/a&gt;.&amp;nbsp; It worked well and there is absolutely
   no reason that you shouldn't be able to do this kind of thing.&amp;nbsp; Windows CE is
   an embedded platform, and affecting hardware is what we do in the embedded world.
&lt;/p&gt;
&lt;p&gt;
   Well, as with any code posted on the web (and in fact this got rolled into the Smart
   Device Framework), it got used in some actual shipping products.&amp;nbsp; Great!&amp;nbsp;
   i'm not the only one who thinks we should be able to do this stuff.
&lt;/p&gt;
&lt;p&gt;
   Well, over the past 6 months or so I had a few different people contact me saying
   that the code either didn't work, or did work on their earlier hardware, but was now
   giving strange behavior.
&lt;/p&gt;
&lt;p&gt;
   Most telling was that if you hooked up a scope to the memory, you would see 4 write
   pulses when&amp;nbsp;writing to a register.&amp;nbsp; Furthermore, all 4 bytes in the register
   ended up getting set to the last byte in the array you wanted to write.&amp;nbsp; For
   example, if you wrote 0x12345678 to a register, it would actually get set to 0x56565656.
&lt;/p&gt;
&lt;p&gt;
   Now I know that this code originally worked.&amp;nbsp; I wrote it using actual hardware
   (PXA255) so the behavior was new.&amp;nbsp; The fact that there were 4 strobes on the
   memory&amp;nbsp;strongly suggested&amp;nbsp;that the code was actually doing 4 individual
   writes for the 4 bytes, not a single, atomic 4-byte write.
&lt;/p&gt;
&lt;p&gt;
   I looked at the code and it couldn't be more simple.&amp;nbsp; A write boiled down to
   this:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; WriteInt32(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; data)&lt;br&gt;
   {&lt;br&gt;
   &amp;nbsp;&amp;nbsp; Marshal.WriteInt32(m_addressPointer, data);&lt;br&gt;
   }&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;A
   bit more investigation found that the behavior was fine under CF 1.0, but started
   failing in CF 2.0.&amp;nbsp; What that means is that Microsoft changed the underlying
   implementation of the Marshal class, and in a bad way.&amp;nbsp; Why would they do such
   a stupid, stupid thing?&amp;nbsp; The new mechanism is going to not only cause a break
   for the writes we're looking at, but it's also a lot slower.&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;Since
   I don't know who did this, I can only guess as to what happened.&amp;nbsp; If you write
   a 4-byte value to an address that is not DWORD aligned (i.e. not evenly divisible
   by 4) then an ARM processor with throw a fault and puke on you (x86 throws, but handles
   it internally).&amp;nbsp; My bet is that some edge case got reported that the CF was throwing
   an unaligned exception, and some idiot developer decided that the heavy-handed solution
   of changing the write to happen byte-by-byte would be the solution.&amp;nbsp; Yes, it
   prevents the error, but it causes bugs and is bad, bad form.&amp;nbsp; Personally I'd
   like to slap the persone who made the change and the person who reviewed the change
   and thought it was ok.&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;So
   how do you get around this?&amp;nbsp; Well by doing what the CF itself should have done.&amp;nbsp;
   Instead of using Marshal, you use unsafe code and pointers, and check address alignnment
   before writing.&amp;nbsp; Something like this:&lt;/span&gt;
&lt;/p&gt;
&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt; 
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;unsafe&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; WriteInt32(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; data, &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;int&lt;/span&gt; offset)&lt;br&gt;
   {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   int&lt;/span&gt; baseAddr &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (m_addressPointer.ToInt32() &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;+&lt;/span&gt; offset);&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   if&lt;/span&gt; (baseAddr &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;%&lt;/span&gt; 4
   == 0)&lt;br&gt;
   &amp;nbsp; {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
   // dword aligned&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
   uint&lt;/span&gt;* pDest &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;uint&lt;/span&gt;*)(baseAddr);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; *pDest &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;uint&lt;/span&gt;)data;&lt;br&gt;
   &amp;nbsp; }&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   else&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;if&lt;/span&gt; (baseAddr &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;%&lt;/span&gt; 2
   == 0)&lt;br&gt;
   &amp;nbsp; {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;//
   word aligned&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;ushort&lt;/span&gt;*
   pDest &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ushort&lt;/span&gt;*)(baseAddr);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; *pDest &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ushort&lt;/span&gt;)(data
   &amp;gt;&amp;gt; 0x10);&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; pDest += 2;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; *pDest &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;ushort&lt;/span&gt;)(data
   &amp;amp; 0xFFFF);&lt;br&gt;
   &amp;nbsp; }&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&amp;nbsp;
   else&lt;/span&gt;
   &lt;br&gt;
   &amp;nbsp; {&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: green; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;//
   byte aligned&lt;/span&gt;
   &lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;byte&lt;/span&gt;*
   pDest &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;byte&lt;/span&gt;*)(baseAddr);&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;foreach&lt;/span&gt; (&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;byte&lt;/span&gt; b &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;in&lt;/span&gt; BitConverter.GetBytes(data))&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *pDest &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: red; FONT-SIZE: 11px"&gt;=&lt;/span&gt; b;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pDest++;&lt;br&gt;
   &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
   &amp;nbsp; }&lt;br&gt;
   }&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   This is a classic case of someone not understanding the problem they are solving.&amp;nbsp;
   This logic should have been done well below us - that's the whole point of using managed
   code, right?&amp;nbsp; To simplify things.&amp;nbsp;&amp;nbsp;Unfortunately it also allows many
   developers to write code without understanding what it's really doing, and in my mind
   that's crazy risky.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
   Testing also shows that the Read and Copy methods are similarly broken and all of
   these&amp;nbsp;bugs still exist in CF 3.5, and I strongly suspect it will remain broken
   in future versions.&amp;nbsp; So beware, if you're using Marshal for moving data, you
   could probably get 4x performance improvement by using a pointer instead.&lt;br&gt;
&lt;/p&gt;
&lt;/span&gt;&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=8fdfe95f-9e0f-4f6a-9287-790c59e9b88d" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,8fdfe95f-9e0f-4f6a-9287-790c59e9b88d.aspx</comments>
      <category>.NET Compact Framework;OpenNETCF</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=ada7e9f4-1fee-4083-9ad0-a2369c0d4240</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,ada7e9f4-1fee-4083-9ad0-a2369c0d4240.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,ada7e9f4-1fee-4083-9ad0-a2369c0d4240.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=ada7e9f4-1fee-4083-9ad0-a2369c0d4240</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Long, long ago I wrote <a href="http://msdn.microsoft.com/en-us/library/aa446546.aspx">an
      article for MSDN on creating a multi-Form CF application</a> that used a Form Stack. 
      Since we all tend to grow and learn as developers, we find different ways to do things
      (and generally we scoff at code we wrote years before as inferior crap).  
   </p>
        <p>
      Well Peter Nowak is giving a presentation of the <a href="http://ioc.codeplex.com/">OpenNETCF.IoC
      framework</a> next week and I decided that a sample of using the UI elements of the
      library (Workspaces, SmartParts, etc) might be handy and so I decided to rewrite the
      Form Stack following my latest thinking.  Basically the idea is to allow
      a user to navigate through Forms (actually Views - you are separating your Views from
      the Model, right?) like you would on a browser.  You can move forward and back
      as well as "adding" to the end or top of the stack.  We also don't want to be
      constantly creating new instances of the View classes because we like applications
      to perform well.
   </p>
        <p>
      Here's a look at the new application (yes, I know it's "developer ugly" but this is
      about architecture, not aesthetics):
   </p>
        <p>
          <img border="0" src="http://blog.opennetcf.com/ctacke/content/binary/FormStack.PNG" />
        </p>
        <p>
      You can see the stack in the list, and our current position is noted by the asterisk. 
      "Fwd" will move down to View B, "Back" will move up to Form A, or you can push a new
      A or B onto the stack at the current location, which will truncate everything currently
      above (after) the current position.  Again, think of how your browser works. 
      It's important to know, also, that there are only 3 total View instances created at
      this point (one of each specific type).
   </p>
        <p>
      The code for this application is in source control over at the<a href="http://ioc.codeplex.com/SourceControl/ListDownloadableCommits.aspx"> OpenNETCF.IoC
      Framework Codeplex site</a>.  You'll notice it's called FormStackCS, hinting
      that there may be a FormStackVB coming.  If you'd like to volunteer to do that
      port, by all means let me know (meaning don't hold your breath waiting for me to do
      it).
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=ada7e9f4-1fee-4083-9ad0-a2369c0d4240" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Revisiting the Form Stack</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,ada7e9f4-1fee-4083-9ad0-a2369c0d4240.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2009/11/25/RevisitingTheFormStack.aspx</link>
      <pubDate>Wed, 25 Nov 2009 17:21:11 GMT</pubDate>
      <description>&lt;p&gt;
   Long, long ago I wrote &lt;a href="http://msdn.microsoft.com/en-us/library/aa446546.aspx"&gt;an
   article for MSDN on creating a multi-Form CF application&lt;/a&gt; that used a Form Stack.&amp;nbsp;
   Since we all tend to grow and learn as developers, we find different ways to do things
   (and generally we scoff at code we wrote years before as inferior crap).&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
   Well Peter Nowak is giving a presentation of the &lt;a href="http://ioc.codeplex.com/"&gt;OpenNETCF.IoC
   framework&lt;/a&gt; next week and I decided that a sample of using the UI elements of the
   library (Workspaces, SmartParts, etc) might be handy and so I decided to rewrite the
   Form Stack&amp;nbsp;following my latest thinking.&amp;nbsp; Basically the idea is to allow
   a user to navigate through Forms (actually Views - you are separating your Views from
   the Model, right?) like you would on a browser.&amp;nbsp; You can move forward and back
   as well as "adding" to the end or top of the stack.&amp;nbsp; We also don't want to be
   constantly creating new instances of the View classes because we like applications
   to perform well.
&lt;/p&gt;
&lt;p&gt;
   Here's a look at the new application (yes, I know it's "developer ugly" but this is
   about architecture, not aesthetics):
&lt;/p&gt;
&lt;p&gt;
   &lt;img border=0 src="http://blog.opennetcf.com/ctacke/content/binary/FormStack.PNG"&gt;
&lt;/p&gt;
&lt;p&gt;
   You can see the stack in the list, and our current position is noted by the asterisk.&amp;nbsp;
   "Fwd" will move down to View B, "Back" will move up to Form A, or you can push a new
   A or B onto the stack at the current location, which will truncate everything currently
   above (after) the current position.&amp;nbsp; Again, think of how your browser works.&amp;nbsp;
   It's important to know, also, that there are only 3 total View instances created at
   this point (one of each specific type).
&lt;/p&gt;
&lt;p&gt;
   The code for this application is in source control over at the&lt;a href="http://ioc.codeplex.com/SourceControl/ListDownloadableCommits.aspx"&gt; OpenNETCF.IoC
   Framework Codeplex site&lt;/a&gt;.&amp;nbsp; You'll notice it's called FormStackCS, hinting
   that there may be a FormStackVB coming.&amp;nbsp; If you'd like to volunteer to do that
   port, by all means let me know (meaning don't hold your breath waiting for me to do
   it).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=ada7e9f4-1fee-4083-9ad0-a2369c0d4240" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,ada7e9f4-1fee-4083-9ad0-a2369c0d4240.aspx</comments>
      <category>Compact Framework Code;Dependency Injection;Inversion of Control;OpenNETCF;OpenNETCF.IoC;Patterns and Practices</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=35190b01-6d6f-43a5-a0dc-8ba85014f700</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,35190b01-6d6f-43a5-a0dc-8ba85014f700.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,35190b01-6d6f-43a5-a0dc-8ba85014f700.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=35190b01-6d6f-43a5-a0dc-8ba85014f700</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      If you've ever done mstest unit testing with a Smart Device project, then you're painfully
      aware of how badly Microsoft dropped the ball on this one.  Debugging a unit
      test requires making <a href="http://blogs.msdn.com/davidklinems/archive/2007/11/12/quick-tip-debugging-smart-device-unit-tests.aspx">device
      registry modifications</a>, adding a call to Debugger.Break in your code, then telling
      Studio to Attach to Remote Process once the breakpoint has been hit.  Seriously,
      that's <a href="http://msdn.microsoft.com/en-us/library/bb513875.aspx">their officially
      published answer</a> to how you debug a Smart Device unit test!
   </p>
        <p>
      If you know anything about testing, you know that keeping the cycle time for a test
      to a minimum.  The longer it takes a developer to go from "start testing" to
      a break point where they can step, then the less productive they're going to be. 
      Even worse, if the process is painful, slow and convoluted (check, check and check
      for Microsoft's recommendation), they're likely to just skip writing tests altogether.
   </p>
        <p>
      Internally we get around this by using our own test runner which uses Reflection to
      load up and run tests.  I've decided to once again give back to the community
      and publish this gem as part of <a href="http://resistance.codeplex.com/">Project
      Resistance</a> (it will get checked in to <a href="http://ioc.codeplex.com/">the IoC
      Framework </a>as well).
   </p>
        <p>
      It does not support everything that mstest does, but it's got enough to get you going,
      and I think it's at least reasonably easy to modify if it doesn't meet your needs. 
      The currently supported attributes are:
   </p>
        <ul>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testclassattribute.aspx">TestClass</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testmethodattribute.aspx">TestMethod</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testinitializeattribute.aspx">TestInitialize</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcleanupattribute.aspx">TestCleanup</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.expectedexceptionattribute.aspx">ExpectedException</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.ignoreattribute.aspx">Ignore</a>
          </li>
        </ul>
        <p>
      It also might now be obvious how to set it up for your own app.  You need to
      add a reference to your test assemblies (so VS will deploy them - for some stupid
      reason you can't tell it to do so via the Configuration Manager) and make sure all
      projects are set to deploy to the same place.
   </p>
        <p>
      As usual, if you have feedback or updates, please let me know.  Submitting a
      patch right on one of the project portals is probably the easiest way (hint, hint).
   </p>
        <p>
      It's probably worth noting here that the code for this is the CFTestRunner project,
      and you have to pull it from the source tab on the project site (it's not
      in the release download yet).
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=35190b01-6d6f-43a5-a0dc-8ba85014f700" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Debugging Smart Device MSTEST Unit Tests</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,35190b01-6d6f-43a5-a0dc-8ba85014f700.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2009/11/20/DebuggingSmartDeviceMSTESTUnitTests.aspx</link>
      <pubDate>Fri, 20 Nov 2009 18:36:06 GMT</pubDate>
      <description>&lt;p&gt;
   If you've ever done mstest unit testing with a Smart Device project, then you're painfully
   aware of how badly Microsoft dropped the ball on this one.&amp;nbsp; Debugging a unit
   test requires making &lt;a href="http://blogs.msdn.com/davidklinems/archive/2007/11/12/quick-tip-debugging-smart-device-unit-tests.aspx"&gt;device
   registry modifications&lt;/a&gt;, adding a call to Debugger.Break in your code, then telling
   Studio to Attach to Remote Process once the breakpoint has been hit.&amp;nbsp; Seriously,
   that's &lt;a href="http://msdn.microsoft.com/en-us/library/bb513875.aspx"&gt;their officially
   published answer&lt;/a&gt; to how you debug a Smart Device unit test!
&lt;/p&gt;
&lt;p&gt;
   If you know anything about testing, you know that keeping the cycle time for a test
   to a minimum.&amp;nbsp; The longer it takes a developer to go from "start testing" to
   a break point where they can step, then the less productive they're going to be.&amp;nbsp;
   Even worse, if the process is painful, slow and convoluted (check, check and check
   for Microsoft's recommendation), they're likely to just skip writing tests altogether.
&lt;/p&gt;
&lt;p&gt;
   Internally we get around this by using our own test runner which uses Reflection to
   load up and run tests.&amp;nbsp; I've decided to once again give back to the community
   and publish this gem as part of &lt;a href="http://resistance.codeplex.com/"&gt;Project
   Resistance&lt;/a&gt; (it will get checked in to &lt;a href="http://ioc.codeplex.com/"&gt;the IoC
   Framework &lt;/a&gt;as well).
&lt;/p&gt;
&lt;p&gt;
   It does not support everything that mstest does, but it's got enough to get you going,
   and I think it's at least reasonably easy to modify if it doesn't meet your needs.&amp;nbsp;
   The currently supported attributes are:
&lt;/p&gt;
&lt;ul&gt;
   &lt;li&gt;
      &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testclassattribute.aspx"&gt;TestClass&lt;/a&gt; 
   &lt;li&gt;
      &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testmethodattribute.aspx"&gt;TestMethod&lt;/a&gt; 
   &lt;li&gt;
      &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testinitializeattribute.aspx"&gt;TestInitialize&lt;/a&gt; 
   &lt;li&gt;
      &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.testcleanupattribute.aspx"&gt;TestCleanup&lt;/a&gt; 
   &lt;li&gt;
      &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.expectedexceptionattribute.aspx"&gt;ExpectedException&lt;/a&gt; 
   &lt;li&gt;
      &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.ignoreattribute.aspx"&gt;Ignore&lt;/a&gt;
   &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
   It also might now be obvious how to set it up for your own app.&amp;nbsp; You need to
   add a reference to your test assemblies (so VS will deploy them - for some stupid
   reason you can't tell it to do so via the Configuration Manager) and make sure all
   projects are set to deploy to the same place.
&lt;/p&gt;
&lt;p&gt;
   As usual, if you have feedback or updates, please let me know.&amp;nbsp; Submitting a
   patch right on one of the project portals is probably the easiest way (hint, hint).
&lt;/p&gt;
&lt;p&gt;
   It's probably worth noting here that the code for this is the CFTestRunner project,
   and you have to pull it from the source&amp;nbsp;tab on the project site&amp;nbsp;(it's not
   in the release download yet).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=35190b01-6d6f-43a5-a0dc-8ba85014f700" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,35190b01-6d6f-43a5-a0dc-8ba85014f700.aspx</comments>
      <category>.NET Compact Framework;Compact Framework Code;OpenNETCF;OpenNETCF.IoC;Project Resistance;Windows CE Code</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=cd803996-5d0f-4cef-8075-327a33b8c023</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,cd803996-5d0f-4cef-8075-327a33b8c023.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,cd803996-5d0f-4cef-8075-327a33b8c023.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=cd803996-5d0f-4cef-8075-327a33b8c023</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      For those following <a href="http://resistance.codeplex.com/SourceControl/ListDownloadableCommits.aspx">Project
      Resistance</a>, this is probably going to be a week with little progress.  I've
      got a major milestone on another project that we're trying to prepare for followed
      by an on-site installation so my activity in the code base will be very, very limited. 
      I believe Alex is also on-site and swamped this week as well.  We will be back
      at it next week though, hopefully with some new graphics so we can hammer out the
      final details of the UI.
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=cd803996-5d0f-4cef-8075-327a33b8c023" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Project Resistance Note: This will be a slow week</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,cd803996-5d0f-4cef-8075-327a33b8c023.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2009/11/03/ProjectResistanceNoteThisWillBeASlowWeek.aspx</link>
      <pubDate>Tue, 03 Nov 2009 01:57:31 GMT</pubDate>
      <description>&lt;p&gt;
   For those following &lt;a href="http://resistance.codeplex.com/SourceControl/ListDownloadableCommits.aspx"&gt;Project
   Resistance&lt;/a&gt;, this is probably going to be a week with little progress.&amp;nbsp; I've
   got a major milestone on another project that we're trying to prepare for followed
   by an on-site installation so my activity in the code base will be very, very limited.&amp;nbsp;
   I believe Alex is also on-site and swamped this week as well.&amp;nbsp; We will be back
   at it next week though, hopefully with some new graphics so we can hammer out the
   final details of the UI.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=cd803996-5d0f-4cef-8075-327a33b8c023" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,cd803996-5d0f-4cef-8075-327a33b8c023.aspx</comments>
      <category>OpenNETCF;Project Resistance</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=a3da8e7f-35e0-4302-b7f2-380f83a3b390</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,a3da8e7f-35e0-4302-b7f2-380f83a3b390.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,a3da8e7f-35e0-4302-b7f2-380f83a3b390.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=a3da8e7f-35e0-4302-b7f2-380f83a3b390</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      So my final piece of functionality for the week in <a href="http://resistance.codeplex.com/">Project
      Resistance</a> was to add key handling to the code base.  The idea is that if
      you're running on a non-touch device (or for some reason want to use the D-Pad on
      a touch device) then you need some ability to "select" a resistance band to change. 
      I plumbed through events from the Form down to the ResistorController, and back up
      to the View so now you can move left or right to select a resistance band and then
      up or down will cycle the band just like a gesture will.  Of course there's nothing
      yet to *visually* show you what band is selected, but the code is in place for it.
   </p>
        <p>
      What's most interesting about the way this works is that I'm not using the standard
      old EventHandler subscription mechanism in code.  Instead I'm using a pattern
      called "event aggregation."  It's a bit odd, but I couldn't find a reasonable
      definition online of exactly what event aggregation is, so instead of a link, I'll
      actually have to provide a bit more information.  
   </p>
        <p>
      Event aggregation is the ability of a framework to automatically collect up (or aggregate)
      event information and wire publishers to subscribers.  The <a href="http://ioc.codeplex.com/">OpenNETCF.IoC
      framework</a>, which Project Resistance is using for Dependency Injection and as well
      as the UI framework, also provides Event Aggregation through simple Attributes. 
      Let's look at this key-handling as an example.
   </p>
        <p>
      In the normal old-school event handling way of thinking, if the ResistorController
      wanted to get events when a KeyDown happened on the Form, the controller would need
      a reference to the Form so it could do a form.KeyDown += new KeyEventHandler(Foo). 
      The problem with this is that to do this, the Controller now has to know about the
      Form, meaning that they get coupled together.  That's bad from a maintenance
      and extensibilty standpoint, and it really sucks from a test standpoint.
   </p>
        <p>
      Sure, I could interface the Form and then pass an interface reference in, but still,
      why does the Controller need to know anything about the Form?  Really it just
      wants to know when some other component wants to change the currently selected band
      or change the value of the selected band.
   </p>
        <p>
      Well this is a classic case of where Event Aggregation rocks.  In the OpenNETCF.IoC
      framework, we simply need to know the string name of the event (which is stored in
      a global constant so everyone can use it).
   </p>
        <p>
      The Form "publishes" the event with a simple attribute like this:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">[EventPublication(EventNames.DPadEvent)]<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">event</span> KeyEventHandler
      DPadKeyPressed;<br /></span>
        </p>
        <p>
      The anything that wants to receive the event simply uses an attribute to subscribe. 
      This is what it looks like in the ResistorController:
   </p>
        <p>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">[EventSubscription(EventNames.DPadEvent,
      ThreadOption.Caller)]<br /><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">public</span><span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">void</span> DPadHandler(<span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px">object</span> sender,
      KeyEventArgs e)<br />
      {<br /></span>
          <span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px">...<br />
      }</span>
        </p>
        <p>
      By the nature of the fact that these objects were inserted into one of the IoC framework's
      DI container collections, the two automagigically get paired up.  No references
      get passed around, no interfaces get unnecessarily polluted, and out objects stay
      nicely decoupled.  All that is required is that both attributes use the same
      string name for the event and that the handler method signature matches the expected
      publisher's delegate.
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=a3da8e7f-35e0-4302-b7f2-380f83a3b390" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Project Resistance: Event Aggregation with OpenNETCF.IoC</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,a3da8e7f-35e0-4302-b7f2-380f83a3b390.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2009/10/30/ProjectResistanceEventAggregationWithOpenNETCFIoC.aspx</link>
      <pubDate>Fri, 30 Oct 2009 19:51:57 GMT</pubDate>
      <description>&lt;p&gt;
   So my final piece of functionality for the week in &lt;a href="http://resistance.codeplex.com/"&gt;Project
   Resistance&lt;/a&gt; was to add key handling to the code base.&amp;nbsp; The idea is that if
   you're running on a non-touch device (or for some reason want to use the D-Pad on
   a touch device) then you need some ability to "select" a resistance band to change.&amp;nbsp;
   I plumbed through events from the Form down to the ResistorController, and back up
   to the View so now you can move left or right to select a resistance band and then
   up or down will cycle the band just like a gesture will.&amp;nbsp; Of course there's nothing
   yet to *visually* show you what band is selected, but the code is in place for it.
&lt;/p&gt;
&lt;p&gt;
   What's most interesting about the way this works is that I'm not using the standard
   old EventHandler subscription mechanism in code.&amp;nbsp; Instead I'm using a pattern
   called "event aggregation."&amp;nbsp; It's a bit odd, but I couldn't find a reasonable
   definition online of exactly what event aggregation is, so instead of a link, I'll
   actually have to provide a bit more information.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
   Event aggregation is the ability of a framework to automatically collect up (or aggregate)
   event information and wire publishers to subscribers.&amp;nbsp; The &lt;a href="http://ioc.codeplex.com/"&gt;OpenNETCF.IoC
   framework&lt;/a&gt;, which Project Resistance is using for Dependency Injection and as well
   as the UI framework, also provides Event Aggregation through simple Attributes.&amp;nbsp;
   Let's look at this key-handling as an example.
&lt;/p&gt;
&lt;p&gt;
   In the normal old-school event handling way of thinking, if the ResistorController
   wanted to get events when a KeyDown happened on the Form, the controller would need
   a reference to the Form so it could do a form.KeyDown += new KeyEventHandler(Foo).&amp;nbsp;
   The problem with this is that to do this, the Controller now has to know about the
   Form, meaning that they get coupled together.&amp;nbsp; That's bad from a maintenance
   and extensibilty standpoint, and it really sucks from a test standpoint.
&lt;/p&gt;
&lt;p&gt;
   Sure, I could interface the Form and then pass an interface reference in, but still,
   why does the Controller need to know anything about the Form?&amp;nbsp; Really it just
   wants to know when some other component wants to change the currently selected band
   or change the value of the selected band.
&lt;/p&gt;
&lt;p&gt;
   Well this is a classic case of where Event Aggregation rocks.&amp;nbsp; In the OpenNETCF.IoC
   framework, we simply need to know the string name of the event (which is stored in
   a global constant so everyone can use it).
&lt;/p&gt;
&lt;p&gt;
   The Form "publishes" the event with a simple attribute like this:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;[EventPublication(EventNames.DPadEvent)]&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;event&lt;/span&gt; KeyEventHandler
   DPadKeyPressed;&lt;br&gt;
   &lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   The anything that wants to receive the event simply uses an attribute to subscribe.&amp;nbsp;
   This is what it looks like in the ResistorController:
&lt;/p&gt;
&lt;p&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;[EventSubscription(EventNames.DPadEvent,
   ThreadOption.Caller)]&lt;br&gt;
   &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;public&lt;/span&gt; &lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;void&lt;/span&gt; DPadHandler(&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: blue; FONT-SIZE: 11px"&gt;object&lt;/span&gt; sender,
   KeyEventArgs e)&lt;br&gt;
   {&lt;br&gt;
   &lt;/span&gt;&lt;span style="BACKGROUND-COLOR: transparent; FONT-FAMILY: Courier New; COLOR: black; FONT-SIZE: 11px"&gt;...&lt;br&gt;
   }&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
   By the nature of the fact that these objects were inserted into one of the IoC framework's
   DI container collections, the two automagigically get paired up.&amp;nbsp; No references
   get passed around, no interfaces get unnecessarily polluted, and out objects stay
   nicely decoupled.&amp;nbsp; All that is required is that both attributes use the same
   string name for the event and that the handler method signature matches the expected
   publisher's delegate.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=a3da8e7f-35e0-4302-b7f2-380f83a3b390" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,a3da8e7f-35e0-4302-b7f2-380f83a3b390.aspx</comments>
      <category>OpenNETCF;Project Resistance</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=1b443472-cb6a-4e5f-8347-e658a2b1a7d0</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,1b443472-cb6a-4e5f-8347-e658a2b1a7d0.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,1b443472-cb6a-4e5f-8347-e658a2b1a7d0.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=1b443472-cb6a-4e5f-8347-e658a2b1a7d0</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      I didn't do much today with <a href="http://resistance.codeplex.com/">Project Resistance</a>,
      but that didn't stop progress. Alex got all of the background paionting ironed
      out today while I was screwing around with paying work.  It looks pretty nice
      (well, except for the lower workspace, which is awaiting artwork):
   </p>
        <p>
          <img border="0" src="http://blog.opennetcf.com/ctacke/content/binary/Resistance4.png" />
        </p>
        <p>
      I did do some thinking on the broader process of developing WinMo apps, though. 
      One thing that most Windows developers (as well as a great many devs for other OSes)
      have come to rely on is the good old WYSIWYG editor for Form/Screen/View layouts. 
      Generally speaking, they've been around for a good while now and not counting that
      major backslide called <a href="http://msdn.microsoft.com/en-us/library/aa244743(VS.60).aspx">Visual
      InterDev</a>, they've done a pretty good job of presenting a design time what you
      see at runtime.
   </p>
        <p>
      Well for everything except Smart Device projects.  We at OpenNETCF have been
      building controls and libraries for devices since before we were a company. 
      We've seen all the iterations of Microsoft's tools (all the way back to the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=81460842-47cc-4ff2-9a19-4db96e212d32&amp;displaylang=en">add-in
      for VB 6</a> in fact). Never has designing a Form in the tool been easy once you go
      past the basic Label, Textbox and Button UI.
   </p>
        <p>
      Since Studio '03, to get any form of custom control to render properly you had to
      do a <a href="http://msdn.microsoft.com/en-us/library/aa446500.aspx">whole load</a> of <a href="http://dvanderboom.wordpress.com/2008/03/14/compact-framework-creating-custom-controls-and-designers-part-1/">extra</a><a href="http://www.mooseworkssoftware.com/VS2005%20Control.htm">work</a>. 
      And to make matters worse, how you had to do it seems to have changed with every new
      release of Studio, meaning you have to re-do a lot of the work for existing controls
      to get the new tools to support them.  I think this is one of the reasons there
      are so few 3rd-party vendors doing nice controls (especially with any sort of designer
      support).  To make thigs even worse, trying to support just the current tool <a href="http://blog.opennetcf.com/ctacke/2008/11/26/Studio08sToolboxAndCompactFrameworkAssemblies.aspx">runs
      into bugs</a> almost immediately.
   </p>
        <p>
      So what do those of use who build these apps day-in and day-out do?  Well we
      live with a rectangle, or a series of them, in the designer and do all of the
      actual layout by iterating with a device or the emulator.  So the run-time view
      you see above looks like this in the designer:
   </p>
        <p>
          <img border="0" src="http://blog.opennetcf.com/ctacke/content/binary/designer1.png" />
        </p>
        <p>
      Fancy, eh?  And what, you ask, is the upper "DeckWorkspace"?  Well
      it's a container object from the <a href="http://ioc.codeplex.com/">OpenNETCF.IoC
      framework</a>.  It basically holds a UserControl, which is what that resistor
      image is.  It, similarly, gives you very little as design time:
   </p>
        <p>
          <img border="0" src="http://blog.opennetcf.com/ctacke/content/binary/designer2.png" />
        </p>
        <p>
      Yes, this is the state-of-the-art.  If you're coming to device development from
      the desktop, be prepared to be a bit frustrated.  Could we have added designer
      support for the resistor to this project?  Sure.  But I bet it would take
      more than twice the time we have already into the entire project just to get it to
      render, and even then it would come with caveats (like it would work with CF 3.5 but
      not 2.0 projects or similar silliness).
   </p>
        <p>
      So the moral of the story is that you just get used to it.  Unless you plan to
      be a control vendor don't bother wasting your time even trying to get designer support
      working.  You'll only end up frustrated, behind schedule, and with a load of
      convoluted code that you'll have to rewrite the next time Microsoft releases a new
      version of Studio.  Maybe things will change in <a href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx">VS10</a>,
      but based on the track record I seriously doubt it.
   </p>
        <p>
      Don't take all of this as being completely down on Studio though.  As far as
      a development tool it's still the best thing out there (well it's not so great for
      C++, but that's another diatribe - just do yourself a favor and get <a href="http://sourceinsight.com/">SourceInsight</a> for
      that).  I've used a lot of tools, and Studio, by far, is the most stable and
      feature-rich tool that I've ever used.  It's just that there's still a lot of
      room for improvement.
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=1b443472-cb6a-4e5f-8347-e658a2b1a7d0" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Project Resistance: Form Painting and Comments on the Studio Designer</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,1b443472-cb6a-4e5f-8347-e658a2b1a7d0.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2009/10/30/ProjectResistanceFormPaintingAndCommentsOnTheStudioDesigner.aspx</link>
      <pubDate>Fri, 30 Oct 2009 02:41:22 GMT</pubDate>
      <description>&lt;p&gt;
   I didn't do much today with &lt;a href="http://resistance.codeplex.com/"&gt;Project Resistance&lt;/a&gt;,
   but that didn't stop progress.&amp;nbsp;Alex got all of the background paionting ironed
   out today while I was screwing around with paying work.&amp;nbsp; It looks pretty nice
   (well, except for the lower workspace, which is awaiting artwork):
&lt;/p&gt;
&lt;p&gt;
   &lt;img border=0 src="http://blog.opennetcf.com/ctacke/content/binary/Resistance4.png"&gt;
&lt;/p&gt;
&lt;p&gt;
   I did do some thinking on the broader process of developing WinMo apps, though.&amp;nbsp;
   One thing that most Windows developers (as well as a great many devs for other OSes)
   have come to rely on is the good old WYSIWYG editor for Form/Screen/View layouts.&amp;nbsp;
   Generally speaking, they've been around for a good while now and not counting that
   major backslide called &lt;a href="http://msdn.microsoft.com/en-us/library/aa244743(VS.60).aspx"&gt;Visual
   InterDev&lt;/a&gt;, they've done a pretty good job of presenting a design time what you
   see at runtime.
&lt;/p&gt;
&lt;p&gt;
   Well for everything except Smart Device projects.&amp;nbsp; We at OpenNETCF have been
   building controls and libraries for devices since before we were a company.&amp;nbsp;
   We've seen all the iterations of Microsoft's tools (all the way back to the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=81460842-47cc-4ff2-9a19-4db96e212d32&amp;amp;displaylang=en"&gt;add-in
   for VB 6&lt;/a&gt; in fact). Never has designing a Form in the tool been easy once you go
   past the basic Label, Textbox and Button UI.
&lt;/p&gt;
&lt;p&gt;
   Since Studio '03, to get any form of custom control to render properly you had to
   do a &lt;a href="http://msdn.microsoft.com/en-us/library/aa446500.aspx"&gt;whole load&lt;/a&gt; of &lt;a href="http://dvanderboom.wordpress.com/2008/03/14/compact-framework-creating-custom-controls-and-designers-part-1/"&gt;extra&lt;/a&gt; &lt;a href="http://www.mooseworkssoftware.com/VS2005%20Control.htm"&gt;work&lt;/a&gt;.&amp;nbsp;
   And to make matters worse, how you had to do it seems to have changed with every new
   release of Studio, meaning you have to re-do a lot of the work for existing controls
   to get the new tools to support them.&amp;nbsp; I think this is one of the reasons there
   are so few 3rd-party vendors doing nice controls (especially with any sort of designer
   support).&amp;nbsp; To make thigs even worse, trying to support just the current tool &lt;a href="http://blog.opennetcf.com/ctacke/2008/11/26/Studio08sToolboxAndCompactFrameworkAssemblies.aspx"&gt;runs
   into bugs&lt;/a&gt; almost immediately.
&lt;/p&gt;
&lt;p&gt;
   So what do those of use who build these apps day-in and day-out do?&amp;nbsp; Well we
   live with a rectangle, or a series of them,&amp;nbsp;in the designer and do all of the
   actual layout by iterating with a device or the emulator.&amp;nbsp; So the run-time view
   you see above looks like this in the designer:
&lt;/p&gt;
&lt;p&gt;
   &lt;img border=0 src="http://blog.opennetcf.com/ctacke/content/binary/designer1.png"&gt;
&lt;/p&gt;
&lt;p&gt;
   Fancy, eh?&amp;nbsp; And what, you ask, is&amp;nbsp;the upper "DeckWorkspace"?&amp;nbsp; Well
   it's a container object from the &lt;a href="http://ioc.codeplex.com/"&gt;OpenNETCF.IoC
   framework&lt;/a&gt;.&amp;nbsp; It basically holds a UserControl, which is what that resistor
   image is.&amp;nbsp; It, similarly, gives you very little as design time:
&lt;/p&gt;
&lt;p&gt;
   &lt;img border=0 src="http://blog.opennetcf.com/ctacke/content/binary/designer2.png"&gt;
&lt;/p&gt;
&lt;p&gt;
   Yes, this is the state-of-the-art.&amp;nbsp; If you're coming to device development from
   the desktop, be prepared to be a bit frustrated.&amp;nbsp; Could we have added designer
   support for the resistor to this project?&amp;nbsp; Sure.&amp;nbsp; But I bet it would take
   more than twice the time we have already into the entire project just to get it to
   render, and even then it would come with caveats (like it would work with CF 3.5 but
   not 2.0 projects or similar silliness).
&lt;/p&gt;
&lt;p&gt;
   So the moral of the story is that you just get used to it.&amp;nbsp; Unless you plan to
   be a control vendor don't bother wasting your time even trying to get designer support
   working.&amp;nbsp; You'll only end up frustrated, behind schedule, and with a load of
   convoluted code that you'll have to rewrite the next time Microsoft releases a new
   version of Studio.&amp;nbsp; Maybe things will change in &lt;a href="http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx"&gt;VS10&lt;/a&gt;,
   but based on the track record I seriously doubt it.
&lt;/p&gt;
&lt;p&gt;
   Don't take all of this as being completely down on Studio though.&amp;nbsp; As far as
   a development tool it's still the best thing out there (well it's not so great for
   C++, but that's another diatribe - just do yourself a favor and get &lt;a href="http://sourceinsight.com/"&gt;SourceInsight&lt;/a&gt;&amp;nbsp;for
   that).&amp;nbsp; I've used a lot of tools, and Studio, by far, is the most stable and
   feature-rich tool that I've ever used.&amp;nbsp; It's just that there's still a lot of
   room for improvement.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=1b443472-cb6a-4e5f-8347-e658a2b1a7d0" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,1b443472-cb6a-4e5f-8347-e658a2b1a7d0.aspx</comments>
      <category>OpenNETCF;Project Resistance</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=b7eb05da-a2c1-4d95-bd7f-de4208552340</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,b7eb05da-a2c1-4d95-bd7f-de4208552340.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,b7eb05da-a2c1-4d95-bd7f-de4208552340.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=b7eb05da-a2c1-4d95-bd7f-de4208552340</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      We've made more today progress on <a href="http://resistance.codeplex.com/">Project
      Resistance</a>.  It turns out that the <a href="http://blog.opennetcf.com/ctacke/2009/10/26/ProjectResistanceTransparencyInTheCompactFrameworkSucks.aspx">earlier
      bug</a> was indeed due to the fact that in the Compact Framework Color.Transparent
      is not a transparent color.  How intuitive.  If you do Graphics.Clear(Color.Transparent)
      what actually occurs is that the underlying bitmap gets filled with white.  We
      (and by "we" I mean "Alex") had to create some utility functions to directly manipulate
      the HDC and do actual transparency.  
   </p>
        <p>
      Again, it's more than a little awkward, and how Microsoft might expect the vast majority
      of developers out there to get this right I'm not sure.  Even if everyone <u>could</u> write
      this code, I still think they shouldn't have to.  We should be focused on solving
      our business problems, not solving platform problems.
   </p>
        <p>
      At any rate, we got a fix into the code, and I added gesturing support for the resistance
      bands in the ResistorView as well.
   </p>
        <p>
       
   </p>
        <p>
          <img border="0" src="http://blog.opennetcf.com/ctacke/content/binary/Resistance3.png" />
        </p>
        <p>
      You can see that the background is not right, but that's an offset math issue (again
      due to the inability to draw transparent controls on a Form) that should be simple
      to fix.  Yes, the View for the numeric data at the bottom is hideous, but right
      now it's simply there to ensure that events get properly wired from the view above,
      down to the controller and back out.  Making it look good will require work from
      the graphic designer.
   </p>
        <p>
      As a side note, Alex seems to be having some difficulties using SVN as a CodePlex
      client and that's why the fix took so long to get published.  I'm not having
      any problems with the TFS client.
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=b7eb05da-a2c1-4d95-bd7f-de4208552340" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Project Resistance, Day 4: graphic fixes and more gesturing</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,b7eb05da-a2c1-4d95-bd7f-de4208552340.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2009/10/28/ProjectResistanceDay4GraphicFixesAndMoreGesturing.aspx</link>
      <pubDate>Wed, 28 Oct 2009 18:59:50 GMT</pubDate>
      <description>&lt;p&gt;
   We've made more today progress on &lt;a href="http://resistance.codeplex.com/"&gt;Project
   Resistance&lt;/a&gt;.&amp;nbsp; It turns out that the &lt;a href="http://blog.opennetcf.com/ctacke/2009/10/26/ProjectResistanceTransparencyInTheCompactFrameworkSucks.aspx"&gt;earlier
   bug&lt;/a&gt; was indeed due to the fact that in the Compact Framework Color.Transparent
   is not a transparent color.&amp;nbsp; How intuitive.&amp;nbsp; If you do Graphics.Clear(Color.Transparent)
   what actually occurs is that the underlying bitmap gets filled with white.&amp;nbsp; We
   (and by "we" I mean "Alex") had to create some utility functions to directly manipulate
   the HDC and do actual transparency.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
   Again, it's more than a little awkward, and how Microsoft might expect the vast majority
   of developers out there to get this right I'm not sure.&amp;nbsp; Even if everyone &lt;u&gt;could&lt;/u&gt; write
   this code, I still think they shouldn't have to.&amp;nbsp; We should be focused on solving
   our business problems, not solving platform problems.
&lt;/p&gt;
&lt;p&gt;
   At any rate, we got a fix into the code, and I added gesturing support for the resistance
   bands in the ResistorView as well.
&lt;/p&gt;
&lt;p&gt;
   &amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
   &lt;img border=0 src="http://blog.opennetcf.com/ctacke/content/binary/Resistance3.png"&gt;
&lt;/p&gt;
&lt;p&gt;
   You can see that the background is not right, but that's an offset math issue (again
   due to the inability to draw transparent controls on a Form) that should be simple
   to fix.&amp;nbsp; Yes, the View for the numeric data at the bottom is hideous, but right
   now it's simply there to ensure that events get properly wired from the view above,
   down to the controller and back out.&amp;nbsp; Making it look good will require work from
   the graphic designer.
&lt;/p&gt;
&lt;p&gt;
   As a side note, Alex seems to be having some difficulties using SVN as a CodePlex
   client and that's why the fix took so long to get published.&amp;nbsp; I'm not having
   any problems with the TFS client.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=b7eb05da-a2c1-4d95-bd7f-de4208552340" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,b7eb05da-a2c1-4d95-bd7f-de4208552340.aspx</comments>
      <category>OpenNETCF;Project Resistance</category>
    </item>
    <item>
      <trackback:ping>http://blog.opennetcf.com/ctacke/Trackback.aspx?guid=3ccdbb79-a038-47a9-be10-32db2f3e55cd</trackback:ping>
      <pingback:server>http://blog.opennetcf.com/ctacke/pingback.aspx</pingback:server>
      <pingback:target>http://blog.opennetcf.com/ctacke/PermaLink,guid,3ccdbb79-a038-47a9-be10-32db2f3e55cd.aspx</pingback:target>
      <dc:creator>
      </dc:creator>
      <wfw:comment>http://blog.opennetcf.com/ctacke/CommentView,guid,3ccdbb79-a038-47a9-be10-32db2f3e55cd.aspx</wfw:comment>
      <wfw:commentRss>http://blog.opennetcf.com/ctacke/SyndicationService.asmx/GetEntryCommentsRss?guid=3ccdbb79-a038-47a9-be10-32db2f3e55cd</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
      Today has been a slow day here for <a href="http://resistance.codeplex.com/">Project
      Resistance</a> because I'm neck deep in writing other code.  I did manage to
      get the gesture events for the Tolernace band on the ResistorView plumbed in so now
      you can swipe up/down with your finger and it actually changes the band color (though
      I noticed I need to fix a couple images) and it updates a second View with a text
      representation of the tolerance. Right now that view looks like an engineer created
      it, so no screen shot today - I'd rather not embarass myself.
   </p>
        <p>
      On another, more fun note, fellow MVP and <a href="http://www.manning.com/fairbairn/">iPhone
      development author</a> <a href="http://www.christec.co.nz/blog">Christopher Fairbairn</a> has started
      an <a href="http://github.com/ChrisTec/Project-Resistance/">iPhone port of Project
      Resistance</a>.  He's also <a href="http://www.christec.co.nz/blog/archives/815">started</a><a href="http://www.christec.co.nz/blog/archives/834">blogging</a><a href="http://www.christec.co.nz/blog/archives/851">about</a> his
      project.  Looking at his posts and how easy a time he's having so far makes me
      almost jealous.  If it weren't for the facts that you have to subject your eyes
      to the abomination known as Objective-C and you have to work on a Mac I just
      might be.  It should be interesting to see how the two projects track toward
      getting a product to market.  So far we're both just barely out of the gate.
   </p>
        <img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=3ccdbb79-a038-47a9-be10-32db2f3e55cd" />
        <br />
        <hr />
   Managed Code in the Embedded World</body>
      <title>Project Resistance: iPhone Edition</title>
      <guid>http://blog.opennetcf.com/ctacke/PermaLink,guid,3ccdbb79-a038-47a9-be10-32db2f3e55cd.aspx</guid>
      <link>http://blog.opennetcf.com/ctacke/2009/10/27/ProjectResistanceIPhoneEdition.aspx</link>
      <pubDate>Tue, 27 Oct 2009 23:35:35 GMT</pubDate>
      <description>&lt;p&gt;
   Today has been a slow day here for &lt;a href="http://resistance.codeplex.com/"&gt;Project
   Resistance&lt;/a&gt; because I'm neck deep in writing other code.&amp;nbsp; I did manage to
   get the gesture events for the Tolernace band on the ResistorView plumbed in so now
   you can swipe up/down with your finger and it actually changes the band color (though
   I noticed I need to fix a couple images) and it updates a second View with a text
   representation of the tolerance. Right now that view looks like an engineer created
   it, so no screen shot today - I'd rather not embarass myself.
&lt;/p&gt;
&lt;p&gt;
   On another, more fun note, fellow MVP&amp;nbsp;and &lt;a href="http://www.manning.com/fairbairn/"&gt;iPhone
   development author&lt;/a&gt;&amp;nbsp;&lt;a href="http://www.christec.co.nz/blog"&gt;Christopher Fairbairn&lt;/a&gt; has&amp;nbsp;started
   an &lt;a href="http://github.com/ChrisTec/Project-Resistance/"&gt;iPhone port of Project
   Resistance&lt;/a&gt;.&amp;nbsp; He's also &lt;a href="http://www.christec.co.nz/blog/archives/815"&gt;started&lt;/a&gt; &lt;a href="http://www.christec.co.nz/blog/archives/834"&gt;blogging&lt;/a&gt; &lt;a href="http://www.christec.co.nz/blog/archives/851"&gt;about&lt;/a&gt; his
   project.&amp;nbsp; Looking at his posts and how easy a time he's having so far makes me
   almost jealous.&amp;nbsp; If it weren't for the facts that you have to subject your eyes
   to the abomination known as Objective-C&amp;nbsp;and you have to work on a Mac I just
   might be.&amp;nbsp; It should be interesting to see how the two projects track toward
   getting a product to market.&amp;nbsp; So far we're both just barely out of the gate.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.opennetcf.com/ctacke/aggbug.ashx?id=3ccdbb79-a038-47a9-be10-32db2f3e55cd" /&gt;
&lt;br /&gt;
&lt;hr /&gt;Managed Code in the Embedded World</description>
      <comments>http://blog.opennetcf.com/ctacke/CommentView,guid,3ccdbb79-a038-47a9-be10-32db2f3e55cd.aspx</comments>
      <category>OpenNETCF;Project Resistance</category>
    </item>
  </channel>
</rss>