<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Infovark Underground &#187; REST</title>
	<atom:link href="http://underground.infovark.com/category/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://underground.infovark.com</link>
	<description>The Infovark technology blog</description>
	<lastBuildDate>Thu, 12 May 2011 16:32:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>REST: How to respond to an HTTP POST</title>
		<link>http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/</link>
		<comments>http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 13:54:29 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[RESTful]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=376</guid>
		<description><![CDATA[I ran into a problem yesterday. I&#8217;d sent a HTTP POST request to a collection of resources on our RESTful web service. Our server responded with an HTTP 201: Created status code and the URI of the new resource in the Location header. And then&#8230; nothing happened. This was not what I was expecting. I [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
<li><a href='http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/' rel='bookmark' title='Using WCF for REST, Part 3'>Using WCF for REST, Part 3</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I ran into a problem yesterday. I&#8217;d sent a HTTP POST request to a collection of resources on our RESTful web service. Our server responded with an <code>HTTP 201: Created</code> status code and the URI of the new resource in the <code>Location</code> header.</p>
<p>And then&#8230; nothing happened.</p>
<p>This was not what I was expecting. I expected my web browser to follow up with a GET request to the URI I&#8217;d provided. But Firefox 3 wasn&#8217;t biting. A problem with Firefox? I checked in IE8 and Google Chrome and got the same behavior.</p>
<p>Had I misread the HTTP spec? Did I misunderstand the REST pattern? I grabbed for my worn copy of <a href="http://oreilly.com/catalog/9780596529260/">RESTful Web Services</a>. Nope. <code>HTTP 201</code> seemed to be the right status for this situation.</p>
<p>Had I blundered into some common error? I checked Stefan Tilkov&#8217;s useful list of <a href="http://www.infoq.com/articles/rest-anti-patterns">REST Antipatterns</a>. But I couldn&#8217;t find anything that quite matched my situation.</p>
<p>I started Googling, but couldn&#8217;t find much apart from this <a href="http://stackoverflow.com/questions/420103/what-is-the-correct-response-to-an-http-post-request">question about HTTP Post on Stack Overflow</a>. There were some cryptic responses (to which I&#8217;ve added my own answer now).</p>
<p>Eventually, I discovered what I needed to know from Ben Ramsey&#8217;s article on <a href="http://benramsey.com/archives/http-status-redirection/">HTTP redirection</a>. It&#8217;s part of his <a href="http://benramsey.com/tag/rfc2616/">series discussing RFC 2616</a>, which describes the <a href="http://www.ietf.org/rfc/rfc2616.txt">HTTP/1.1 protocol</a>.</p>
<p>The answer is that while web service clients will often &#8220;take the hint&#8221; provided by a <code>HTTP 201: Created</code> response, web browsers won&#8217;t. If you actually want a web browser to go somewhere else, you need to send a status code in the 3xx series. In this situation, the status code you want is <code>HTTP 303: See Other</code>.</p>
<p>Once I changed the status code returned by the server, all the web browsers followed up the response with a GET to the new URI.</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
<li><a href='http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/' rel='bookmark' title='Using WCF for REST, Part 3'>Using WCF for REST, Part 3</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using WCF to return HTML</title>
		<link>http://underground.infovark.com/2009/02/18/using-wcf-to-return-html/</link>
		<comments>http://underground.infovark.com/2009/02/18/using-wcf-to-return-html/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 15:28:22 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=332</guid>
		<description><![CDATA[I just answered a WCF question on StackOverflow, and decided it was worth cross-posting here as well. The question was: What is the best / most flexible way to have WCF output XHTML? Here&#8217;s how we do it at Infovark. While I&#8217;m not sure that our approach is the best way, it does the job. [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2009/12/11/better-ways-to-encode-html-in-c/' rel='bookmark' title='Better ways to Encode HTML in C#'>Better ways to Encode HTML in C#</a></li>
<li><a href='http://underground.infovark.com/2009/12/01/looking-for-an-iis-alternative/' rel='bookmark' title='Looking for an IIS Alternative'>Looking for an IIS Alternative</a></li>
<li><a href='http://underground.infovark.com/2008/04/09/wcf-bad-request/' rel='bookmark' title='WCF Bad Request'>WCF Bad Request</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I just answered a <a href="http://en.wikipedia.org/wiki/Windows_Communication_Foundation">WCF</a> question on <a href="http://www.stackoverflow.com">StackOverflow</a>, and decided it was worth cross-posting here as well. </p>
<p>The question was: <a href="http://stackoverflow.com/questions/558515/what-is-the-best-most-flexible-way-to-have-wcf-output-xhtml">What is the best / most flexible way to have WCF output XHTML?</a></p>
<p>Here&#8217;s how we do it at Infovark. While I&#8217;m not sure that our approach is the <em>best</em> way, it does the job.</p>
<p>Our approach is to use the DataContractSerilizer to generate XML, then apply a Complied XSLT transform and return the result stream, which should now contain XHTML. Here&#8217;s a simplified version of our code:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> Stream GetItemAsHtml<span class="br0">&#40;</span><span class="kw4">string</span> id<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Item obj <span class="sy0">=</span> GetItem<span class="br0">&#40;</span>objectId<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; Stream xml <span class="sy0">=</span> GetXmlStream<span class="br0">&#40;</span>obj<span class="br0">&#41;</span>; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> TransformXmlStream<span class="br0">&#40;</span>xml, defaultTransform<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> Stream GetXmlStream<span class="br0">&#40;</span>IXmlSerializable item<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; MemoryStream stream <span class="sy0">=</span> <span class="kw3">new</span> MemoryStream<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">using</span> <span class="br0">&#40;</span>XmlWriter writer <span class="sy0">=</span> XmlWriter.<span class="me1">Create</span><span class="br0">&#40;</span>stream, <span class="kw3">new</span> XmlWriterSettings <span class="br0">&#123;</span> Encoding <span class="sy0">=</span> Encoding.<span class="me1">UTF8</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>writer <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DataContractSerializer dcs <span class="sy0">=</span> <span class="kw3">new</span> DataContractSerializer<span class="br0">&#40;</span>item.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dcs.<span class="me1">WriteObject</span><span class="br0">&#40;</span>writer, item<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span class="me1">Flush</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span class="me1">Close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; stream.<span class="me1">Seek</span><span class="br0">&#40;</span><span class="nu0">0</span>, SeekOrigin.<span class="me1">Begin</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> stream;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> Stream TransformXmlStream<span class="br0">&#40;</span>Stream xml, <span class="kw4">string</span> xsltFile<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; XmlReader reader <span class="sy0">=</span> XmlReader.<span class="me1">Create</span><span class="br0">&#40;</span>xml<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; XslCompiledTransform trans <span class="sy0">=</span> <span class="kw3">new</span> XslCompiledTransform<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; trans.<span class="me1">Load</span><span class="br0">&#40;</span>xsltFile<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; MemoryStream stream <span class="sy0">=</span> <span class="kw3">new</span> MemoryStream<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">using</span> <span class="br0">&#40;</span>XmlWriter writer <span class="sy0">=</span> XmlWriter.<span class="me1">Create</span><span class="br0">&#40;</span>stream, trans.<span class="me1">OutputSettings</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>writer <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trans.<span class="me1">Transform</span><span class="br0">&#40;</span>reader, writer<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span class="me1">Flush</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writer.<span class="me1">Close</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; stream.<span class="me1">Seek</span><span class="br0">&#40;</span><span class="nu0">0</span>, SeekOrigin.<span class="me1">Begin</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> stream;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>It works for us, but if you&#8217;ve got other, better ideas, please let me know! </p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2009/12/11/better-ways-to-encode-html-in-c/' rel='bookmark' title='Better ways to Encode HTML in C#'>Better ways to Encode HTML in C#</a></li>
<li><a href='http://underground.infovark.com/2009/12/01/looking-for-an-iis-alternative/' rel='bookmark' title='Looking for an IIS Alternative'>Looking for an IIS Alternative</a></li>
<li><a href='http://underground.infovark.com/2008/04/09/wcf-bad-request/' rel='bookmark' title='WCF Bad Request'>WCF Bad Request</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2009/02/18/using-wcf-to-return-html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Put the &#8220;Web&#8221; Back in Web Services</title>
		<link>http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/</link>
		<comments>http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 18:52:32 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=8</guid>
		<description><![CDATA[I know it&#8217;s possible to transmit Internet Protocol by carrier pigeon, but I&#8217;m not sure I could recommend it to our customers with a straight face. By the same token, I&#8217;m continually surprised to hear vendors and consultants insist that Web Services can be done without the web. Yet I&#8217;ve seen that claim repeated all [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/04/10/reviewrestful-webservices/' rel='bookmark' title='Review: Restful Web Services'>Review: Restful Web Services</a></li>
<li><a href='http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/' rel='bookmark' title='REST: How to respond to an HTTP POST'>REST: How to respond to an HTTP POST</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I know it&#8217;s <em>possible</em> to transmit <a href="http://en.wikipedia.org/wiki/IP_over_Avian_Carriers">Internet Protocol by carrier pigeon</a>, but I&#8217;m not sure I could recommend it to our customers with a straight face. By the same token, I&#8217;m continually surprised to hear vendors and consultants insist that Web Services can be done <em>without the web</em>. </p>
<p>Yet I&#8217;ve seen that claim repeated all over the Internet. Sure, it&#8217;s true in the academic sense. Technically, there&#8217;s nothing wrong with &#8220;webless&#8221; web services, just like IP by avian carrier will eventually get the job done (though latency and packet loss are a challenge). But practically speaking, why would you use anything other than HTTP?</p>
<p>The &#8220;webless web services&#8221; meme has infected a number of good ideas. The SOAP standard is a case in point. At first, SOAP was a simple XML wrapper around an XML payload. (Remember when the S in SOAP stood for Simple?) Then a variety of industry heavyweights jumped on the bandwagon, and soon SOAP could be used with <em>any</em> protocol. </p>
<p>With, uh, a few changes. Like <a href="http://en.wikipedia.org/wiki/Web_services">five or six additional specifications</a>. And schema. Lots of schema. <a href="http://www.w3.org/2003/Talks/05-gartner-tbl/slide6-0.html">Maybe a diagram would help?</a> No?</p>
<h4>Why not use REST instead?</h4>
<p><a href="http://blogs.msdn.com/drnick/archive/2009/02/03/stefan-tilkov-on-rest.aspx">Nicholas Allen</a> recently shared a great presentation on <a href="http://www.infoq.com/presentations/qcon-tilkov-rest-intro">REST and SOA</a> given by Stefan Tilkov at QCon. Stefan makes some great points about how RESTful web service design aligns well with the goals of Service Oriented Architecture (SOA). </p>
<p>Sure, you <em>could</em> use the WS-* stack if you like, but RESTful web architecture is a proven, scalable and truly simple approach, as long as you don&#8217;t mind having to use HTTP.</p>
<p>Much of the added plumbing in the WS-* stack is there to help transition older computer-to-computer network communication technologies. It allows applications that depend on <a href="http://en.wikipedia.org/wiki/CORBA">CORBA</a> or <a href="http://en.wikipedia.org/wiki/Distributed_Component_Object_Model">DCOM</a> to tunnel through firewalls. But unless you&#8217;re trying to retrofit a system built before, say, <a href="http://www.wdvl.com/Authoring/Languages/XML/News/Archives/News1998.html">1998</a>, you can skip all that stuff.</p>
<p>Wasn&#8217;t using web protocol the whole point of web services anyway? As Stefan said in his closing comments: &#8220;Protocol independence is a bug, not a feature.&#8221;</p>
<p>Use a RESTful architecture for new development. Put the <strong>web</strong> back in <strong>web services</strong>.</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/04/10/reviewrestful-webservices/' rel='bookmark' title='Review: Restful Web Services'>Review: Restful Web Services</a></li>
<li><a href='http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/' rel='bookmark' title='REST: How to respond to an HTTP POST'>REST: How to respond to an HTTP POST</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using WCF for REST, Part 3</title>
		<link>http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/</link>
		<comments>http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/#comments</comments>
		<pubDate>Tue, 27 May 2008 15:44:52 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=9</guid>
		<description><![CDATA[The easiest way to explain the issues we encountered when implementing REST is to work through the design principles we followed. I think much of our trouble came from the fact that we come from a web applications background, not a SOAP services background. I&#8217;m hoping that by laying out our REST design, some of [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
<li><a href='http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/' rel='bookmark' title='Put the &#8220;Web&#8221; Back in Web Services'>Put the &#8220;Web&#8221; Back in Web Services</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The easiest way to explain the <a href="http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/">issues we encountered when implementing REST</a> is to work through the design principles we followed. I think much of our trouble came from the fact that we come from a web applications background, not a SOAP services background. I&#8217;m hoping that by laying out our REST design, some of the Microsoft gurus can help us do things &#8220;the WCF way.&#8221; And perhaps we can help the WCF team out by highlighting a handful of places where we found WCF unintuitive.</p>
<h4>The Importance of Being Addressable</h4>
<p>Fundamentally, the REST pattern is about making resources available. This means that each item stored within your system can be accessed by someone with the correct permissions. Every one of these items has its own unique address, and its address should not change. This consistency is important, because it allows both people and computer programs to remember and reference items in your system.</p>
<p>Note that we&#8217;re talking about <em>resources </em>or <em>items</em>. In contrast with the SOAP model of web services, which allows programmers to invoke procedures on remote computers, REST is about providing data. SOAP is about <em>verbs</em>, while REST is about <em>nouns</em>. A SOAP service might <code>CalculateTotalSale()</code>; a REST service  provides  <code>CustomerRecieptNo_12345</code>. The kind of web services architecture you use will depend on the kind of application you&#8217;re building. The choice has major implications for the other components of your system.</p>
<p>REST imposes restrictions on what sort of things you can do, because it supports only a handful of actions: GET, POST, PUT, and DELETE. (There are a few other HTTP methods, but these four are the most important.) Fortunately, with these four actions, you can accomplish most basic programming tasks. There&#8217;s a close parallel to these actions and create/read/update/delete, or <a href="http://en.wikipedia.org/wiki/Create%2C_read%2C_update_and_delete">CRUD</a>, the building blocks of data storage systems.</p>
<h4>UriTemplate</h4>
<p>Since the address, or URI, is the primary way to access information in your system, it&#8217;s effectively part of your user interface. All the principles of good user interface design apply. So when designing a REST service, you need fine control over the structure of these identifiers.</p>
<p>SOAP, by contrast, typically has just one endpoint. The address itself conveys no information about what services are provided &#8212; that&#8217;s why SOAP services require a separate WSDL file to tell folks what&#8217;s possible. With REST, it should be easy to discover the extent of the system by looking at the URIs alone.</p>
<p>Coming up with good REST URI patterns can be tricky. Using short, descriptive naming conventions for your resources makes them easier to type. But URI patterns must also be distinct and unambiguous.</p>
<p>In the .NET framework, you use the UriTemplate class to define patterns. The UriTemplate implementation that shipped with .NET 3.5 allowed you to define variables that fit into slots in your URI. A typical UriTemplate might look like this: <code>http://restserver/{object}/{id}?view={viewname}</code>. </p>
<p>WCF looks for incoming URIs that match the patterns you define. The pattern defined above would match the following URIs:</p>
<ul>
<li><code>http://restserver/customer/5?view=profile</code></li>
<li><code>http://restserver/article/how_to_do_stuff?view=print</code></li>
<li><code>http://restserver/author/John-Smith?view=1</code></li>
</ul>
<p>Once you&#8217;ve defined a UriTemplate, you bind it to a method that has the same number of parameters.  (I won&#8217;t go into the ABCs of WCF here, but you can check out this <a href="http://msdn.microsoft.com/en-us/library/aa480190.aspx">MSDN Introduction to WCF</a> if you need a refresher.)</p>
<p>In WCF 3.5, you could only define a variable for a <em>whole segment</em>. A segment is basically the bit between the one forward slash and another, or one querystring parameter. A few bloggers <a href="http://www.aaronlerch.com/blog/2007/07/16/a-humble-wcf-feature-request-or-four/">requested more flexibility in UriTemplates</a>, and the WCF team answered with the soon-to-be-released 3.5 SP1. The ability to define variables for <em>partial</em> segments was crucial for our URI design.</p>
<h4>Representation Matters</h4>
<p>Most books about web services, including <a href="http://underground.infovark.com/2008/04/10/reviewrestful-webservices/">RESTful Web Services</a>, advocate leaving off file extensions from your URIs. This makes sense for SOAP, where you&#8217;re accessing methods and all responses are transmitted in XML. But in REST, you&#8217;re serving up <em>items</em>. </p>
<p>In our case, some of these items being served were files and some were records from a database. It seemed inconsistent to have some endpoints that had file extensions and others that didn&#8217;t. And we also wanted to be able to serve up different representations for our database records. Our REST service supports both JSON, XML, and HTML. It made sense to use a file extension to distinguish between the different representations.</p>
<p>One workaround would have been to create endpoints like <code>http://restserver/form/1040/xml</code> but that looked funny next to URIs like <code>http://resterver/file/documentation.pdf</code>. True RESTafarians would point out that neither the &#8220;/xml&#8221; or the &#8220;.pdf&#8221; are needed, since you can request an appropriate representation using the HTTP ACCEPT header. We decided against the header approach because not all browsers use the ACCEPT HTTP header. Besides, it might be useful for us humans to be able to reach alternate formats by simply changing the URL in the browser address bar. </p>
<p>In WCF 3.5, this required us to create <em>three times</em> the number of endpoints, with a separate method to handle each. We can&#8217;t wait for the official release of 3.5 SP1 to make UriTemplates like <code>http://restserver/user/{id}.{ext}</code> possible. </p>
<h4>The Final Slash</h4>
<p>Another source of endpoint duplication was the need to have <em>two</em> different endpoints for <code>http://restserver/folder</code> and <code>http://restserver/folder/</code>. Because the slash is used as a segment delimiter, the dispatcher in WCF 3.5 saw these two URLs as fundamentally different. </p>
<p>So handling what we thought were fairly trivial cases in URI patterns led us to create <strong>FIVE TIMES</strong> the number of endpoints we wanted. It&#8217;s a maintenance nightmare. SP1 can&#8217;t get here soon enough. </p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
<li><a href='http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/' rel='bookmark' title='Put the &#8220;Web&#8221; Back in Web Services'>Put the &#8220;Web&#8221; Back in Web Services</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WCF Instance Context</title>
		<link>http://underground.infovark.com/2008/05/21/wcf-instance-context/</link>
		<comments>http://underground.infovark.com/2008/05/21/wcf-instance-context/#comments</comments>
		<pubDate>Wed, 21 May 2008 22:31:19 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=23</guid>
		<description><![CDATA[I finally figured out the source of my HTTP 400 problem. Apparently the Windows Communication Foundation deals with exceptions differently depending on your InstanceContextMode settings. I had been using the Single setting but I should have used the PerCall setting. In PerCall mode, the try/catch block works as expected. I think it has something to [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
<li><a href='http://underground.infovark.com/2008/03/28/calling-a-static-method-from-an-object-instance-in-c/' rel='bookmark' title='Calling a Static Method from an Object Instance in C#'>Calling a Static Method from an Object Instance in C#</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I finally figured out the source of my <a href="http://underground.infovark.com/2008/04/09/wcf-bad-request/">HTTP 400</a> problem. Apparently the Windows Communication Foundation deals with exceptions differently depending on your <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontextmode.aspx">InstanceContextMode</a> settings. I had been using the <code>Single</code> setting but I should have used the <code>PerCall</code> setting. In PerCall mode, the try/catch block works as expected.</p>
<p>I think it has something to do with the way that WCF distinguishes between channel exceptions and message faults.</p>
<p>Anyway, if you&#8217;re building a REST web service, you&#8217;ll want to make sure your class is decorated with the following <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.servicebehaviorattribute.instancecontextmode.aspx">ServiceBehavior</a> attribute.</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ServiceBehavior<span class="br0">&#40;</span>InstanceContextMode <span class="sy0">=</span> InstanceContextMode.<span class="me1">PerCall</span><span class="br0">&#41;</span><span class="br0">&#93;</span></div>
</li>
</ol>
</div>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
<li><a href='http://underground.infovark.com/2008/03/28/calling-a-static-method-from-an-object-instance-in-c/' rel='bookmark' title='Calling a Static Method from an Object Instance in C#'>Calling a Static Method from an Object Instance in C#</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/05/21/wcf-instance-context/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using WCF for REST, Part 2</title>
		<link>http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/</link>
		<comments>http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/#comments</comments>
		<pubDate>Sat, 17 May 2008 18:16:53 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=21</guid>
		<description><![CDATA[In part one of this series, I listed several websites and blogs that had useful information on the Windows Communication Foundation (WCF) and REST. I also mentioned that if I was stating again, I&#8217;d probably use something other than WCF. Perhaps deriving my own REST server from System.Net.HTTPListener, for example. Vish asked for some additional [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/' rel='bookmark' title='Using WCF for REST, Part 3'>Using WCF for REST, Part 3</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
<li><a href='http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/' rel='bookmark' title='REST: How to respond to an HTTP POST'>REST: How to respond to an HTTP POST</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/">part one</a> of this series, I listed several websites and blogs that had useful information on the Windows Communication Foundation (WCF) and REST. I also mentioned that if I was stating again, I&#8217;d probably use something other than WCF. Perhaps deriving my own REST server from <a href="http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx">System.Net.HTTPListener</a>, for example.</p>
<p><a href="http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/#comment-18">Vish asked for some additional details</a> in his comment to that post. He works on the Microsoft WCF development team and was curious about our experience.</p>
<p>I had just begun putting together my response when I noticed Scott Guthrie&#8217;s post about <a href="http://weblogs.asp.net/scottgu/archive/2008/05/12/visual-studio-2008-and-net-framework-3-5-service-pack-1-beta.aspx">Service Pack 1 for the .NET Framework 3.5 beta release</a>. Steve Maine also posted specifics about the <a href="http://hyperthink.net/blog/2008/05/12/We+Are+Pleased+To+Bring+You+New+Features+In+NET+35+SP1.aspx">ADO.Net Data Services and WCF changes</a>.</p>
<p>So, Vish, it seems your team&#8217;s beaten me to the punch on some of these issues! Many of the difficulties I was having with WCF and REST were addressed by the service pack. Here&#8217;s an overview of our key stumbling blocks:</p>
<ol>
<li>REST requires much greater control over the URI than SOAP does, and the URITemplate class just wasn&#8217;t up to the task. We had to hardcode most of our endpoints to compensate. (Fixed in SP1. Hooray!)</li>
<li>Supporting multiple formats, such as serving both XML and JSON, either require you to program against Stream or require twice the number of endpoints.</li>
<li>Existing serializers had trouble with complicated object graphs, forcing us to perform serialization/deserialization ourselves. (This seems greatly improved in SP1.)</li>
<li>WCF allows only one contract/interface per endpoint. This makes it tricky to factor out common contract patterns.</li>
<li>Good REST practice would have you return many kinds of errors as HTTP status messages. SOAP embeds all error information in the returned XML. WCF is closely aligned with the SOAP approach, which means that you&#8217;ve got to be very careful distinguishing exceptions from faults when implementing REST in WCF. It was an unpleasant surprise, and we had to do quite a bit of work to deal with that.</li>
</ol>
<p>I&#8217;ll talk about all five of these areas in more detail in upcoming posts in this series. And I&#8217;ll be sure check out the SP1 beta once we get our Infovark Alpha release out the door.</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/' rel='bookmark' title='Using WCF for REST, Part 3'>Using WCF for REST, Part 3</a></li>
<li><a href='http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/' rel='bookmark' title='Using WCF for REST, Part 1'>Using WCF for REST, Part 1</a></li>
<li><a href='http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/' rel='bookmark' title='REST: How to respond to an HTTP POST'>REST: How to respond to an HTTP POST</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Using WCF for REST, Part 1</title>
		<link>http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/</link>
		<comments>http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 15:51:56 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=19</guid>
		<description><![CDATA[Just because you can do something doesn&#8217;t mean it&#8217;s a good idea. We decided to use the Windows Communication Foundation to drive our REST-based web service. In hindsight, it was a poor choice. REST support in WCF seems like it was a last-minute addition to .NET 3.5. You can certainly hack something together, but I&#8217;ve [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
<li><a href='http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/' rel='bookmark' title='Using WCF for REST, Part 3'>Using WCF for REST, Part 3</a></li>
<li><a href='http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/' rel='bookmark' title='Put the &#8220;Web&#8221; Back in Web Services'>Put the &#8220;Web&#8221; Back in Web Services</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Just because you <em>can </em>do something doesn&#8217;t mean it&#8217;s a good idea.</p>
<p>We decided to use the Windows Communication Foundation to drive our REST-based web service. In hindsight, it was a poor choice. REST support in WCF seems like it was a last-minute addition to .NET 3.5. You can certainly hack something together, but I&#8217;ve found few real-world examples on the Internet, and most of those sidestep the tricky issues.</p>
<p>Here&#8217;s the short of it: WCF was designed for RPC-SOAP. More importantly, it was designed to SOA-enable legacy services that used older communications channels like DCOM. If you&#8217;re starting from scratch, and have full control over the output of your web service and the design of your object model, I&#8217;d recommend using a different (and simpler) framework.</p>
<p>We&#8217;ve gotten a good bit of blog traffic from people looking for help with Windows Communication Foundation and the REST architectural pattern. (It&#8217;s good to know that we&#8217;re not the only ones needing advice.) Here are the better sources we&#8217;ve found so far.</p>
<p><a title="WCF" href="http://msdn2.microsoft.com/en-us/library/ms735119.aspx">Windows Communication Foundation</a> documentation on MSDN</p>
<p>Good <a href="http://qcon.infoq.com/sanfrancisco/presentation/REST,+JSON+and+RSS+with+Windows+Communication+Foundation+3.5">overview presentation</a> on REST and Syndication using WCF</p>
<p>Microsoft&#8217;s <a title="WCF Picture Services Sample" href="http://samples.netfx3.com/pictureservices/">Picture Services Sample</a></p>
<p>Justin Smith&#8217;s <a href="http://blogs.msdn.com/justinjsmith/archive/tags/Web+Programming+with+WCF/default.aspx">WCF articles on Cybertopian Chronicles</a></p>
<p><a href="http://blogs.msdn.com/drnick/">Nicholas Allen&#8217;s Indigo blog</a></p>
<p><a href="http://hyperthink.net/blog/">Steve Maine&#8217;s blog</a></p>
<p>Assorted posts on <a href="http://www.west-wind.com/WebLog/default.aspx">Rick Strahl&#8217;s blog</a></p>
<p><a href="http://www.thatindigogirl.com/">That Indigo Girl</a></p>
<p>If you find other useful places to look, let us know!</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
<li><a href='http://underground.infovark.com/2008/05/27/using-wcf-for-rest-part-3/' rel='bookmark' title='Using WCF for REST, Part 3'>Using WCF for REST, Part 3</a></li>
<li><a href='http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/' rel='bookmark' title='Put the &#8220;Web&#8221; Back in Web Services'>Put the &#8220;Web&#8221; Back in Web Services</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/04/22/using-wcf-for-rest-part-1/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Review: Restful Web Services</title>
		<link>http://underground.infovark.com/2008/04/10/reviewrestful-webservices/</link>
		<comments>http://underground.infovark.com/2008/04/10/reviewrestful-webservices/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 14:38:46 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Review]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=13</guid>
		<description><![CDATA[As we mentioned recently, we&#8217;re building the infovark server using the REST pattern. Since REST is more a loose set of guidelines than a strict series of rules, it&#8217;s hard for implementers to know where to begin. OK, you could go to the source, chapter 5 of Roy Fielding&#8217;s dissertation. Or you could check out [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/' rel='bookmark' title='Put the &#8220;Web&#8221; Back in Web Services'>Put the &#8220;Web&#8221; Back in Web Services</a></li>
<li><a href='http://underground.infovark.com/2008/11/05/review-the-pragmatic-programmer/' rel='bookmark' title='Review: The Pragmatic Programmer'>Review: The Pragmatic Programmer</a></li>
<li><a href='http://underground.infovark.com/2008/11/07/review-working-effectively-with-legacy-code/' rel='bookmark' title='Review: Working Effectively with Legacy Code'>Review: Working Effectively with Legacy Code</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>As we <a href="http://underground.infovark.com/2008/03/25/rest-for-the-weary/">mentioned recently</a>, we&#8217;re building the infovark server using the <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a> pattern. Since REST is more a loose set of guidelines than a strict series of rules, it&#8217;s hard for implementers to know where to begin.</p>
<p>OK, you <em>could </em>go to the source, <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm">chapter 5 of Roy Fielding&#8217;s dissertation</a>. Or you could check out the somewhat academic discussions on the <a href="http://rest.blueoxen.net/cgi-bin/wiki.pl">REST wiki</a>, though there hasn&#8217;t been much activity lately. You can occasionally find good advice from the odd blog post, like the <a href="http://wiki.opengarden.org/REST/REST_for_the_Rest_of_Us">REST for the Rest of Us</a> article at Open Garden. But ironically, there&#8217;s not a whole lot of material about implementing REST web services available <em>on the web</em> yet. (If you know of good links, leave a comment.)</p>
<div class="wp-caption alignright " style="width: 150px"><a href="http://www.amazon.com/Restful-Web-Services-Leonard-Richardson/dp/0596529260%3FSubscriptionId%3DAKIAIU3RPTD7NQ47YK4A%26tag%3Dinfovark-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0596529260"><img src="http://ecx.images-amazon.com/images/I/51gXYYHnDsL._SL160_.jpg" alt="" /></a><p class="wp-caption-text">RESTful Web Services</p></div>
<p>For the practical, gritty details of how it&#8217;s actually done, you&#8217;ll need the <a href="http://www.amazon.com/Restful-Web-Services-Leonard-Richardson/dp/0596529260%3FSubscriptionId%3DAKIAIU3RPTD7NQ47YK4A%26tag%3Dinfovark-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0596529260">Restful Web Services</a> book by Sam Ruby and Leonard Richardson. They describe the principles that inform REST-ian (RESTafarian?) design in detail, taking you step-by-step through two different sample applications. If you&#8217;re a Ruby programmer using Rails, you&#8217;ll find the book especially valuable, since that&#8217;s the language and framework in which most of the examples are done. For those of us using different technology, it&#8217;s the thought process behind the examples that is most illuminating.</p>
<p>This is because the key challenge of the REST paradigm is the fact that it can&#8217;t really be implemented on today&#8217;s web without some workarounds. REST will come into its own with <a href="http://en.wikipedia.org/wiki/HTML_5">HTML 5</a>. The book steers an interesting course between how REST web services <em>might </em>be done in HTML 5 with how they <em>must </em>be done today. I think the authors get the balance right, but at times it can make for a frustrating read for someone wanting practical advice about building a REST service <em>right now</em>.</p>
<p>But that&#8217;s less a criticism of the book than of the openness of the REST concept itself. The occasional what-if digression the authors make is a small price to pay for the amount of sound guidance you get. The appendixes alone, which discuss things like which HTTP status codes and headers are worth implementing and which are worth forgetting, will save you far more time than you&#8217;ll lose in reading how great things will be when HTML forms <em>finally </em>support the PUT method.</p>
<p>Until that day comes, keep this book handy.</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2009/02/05/put-the-web-back-in-web-services/' rel='bookmark' title='Put the &#8220;Web&#8221; Back in Web Services'>Put the &#8220;Web&#8221; Back in Web Services</a></li>
<li><a href='http://underground.infovark.com/2008/11/05/review-the-pragmatic-programmer/' rel='bookmark' title='Review: The Pragmatic Programmer'>Review: The Pragmatic Programmer</a></li>
<li><a href='http://underground.infovark.com/2008/11/07/review-working-effectively-with-legacy-code/' rel='bookmark' title='Review: Working Effectively with Legacy Code'>Review: Working Effectively with Legacy Code</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/04/10/reviewrestful-webservices/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WCF Bad Request</title>
		<link>http://underground.infovark.com/2008/04/09/wcf-bad-request/</link>
		<comments>http://underground.infovark.com/2008/04/09/wcf-bad-request/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 23:27:32 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=14</guid>
		<description><![CDATA[I&#8217;ve just identified a horrible bug in WCF for the .NET Framework 3.5. A caught exception in a WebInvoke operation will cause WCF to return an HTTP 400 Bad Request status code to the client. Any caught exception. Every time. Regardless of whatever error code you might want to send back. I found the error [...]


Related posts:<ol><li><a href='http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/' rel='bookmark' title='REST: How to respond to an HTTP POST'>REST: How to respond to an HTTP POST</a></li>
<li><a href='http://underground.infovark.com/2008/05/21/wcf-instance-context/' rel='bookmark' title='WCF Instance Context'>WCF Instance Context</a></li>
<li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just identified a horrible bug in WCF for the .NET Framework 3.5.</p>
<p>A caught exception in a WebInvoke operation will cause WCF to return an HTTP 400 Bad Request status code to the client. <em>Any </em>caught exception. <em>Every </em>time. Regardless of whatever error code you might <em>want </em>to send back.</p>
<p>I found the error by mistake. I&#8217;d used &#8220;BadGateway&#8221; instead of &#8220;BadRequest&#8221; in my code. If it weren&#8217;t for other odd WCF behavior, I wouldn&#8217;t have noticed that my status code was being ignored.</p>
<p>Consider the following example:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Read the Xml into our object and save.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">try</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// The following line triggered the error.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; obj.<span class="me1">ReadXml</span><span class="br0">&#40;</span>reader<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; obj.<span class="me1">Save</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Set HTTP Cache Options and MIME Type.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; Utilities.<span class="me1">SetCaching</span><span class="br0">&#40;</span>WebOperationContext.<span class="me1">Current</span>, obj.<span class="me1">DateModified</span>, <span class="nu0">60</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; Utilities.<span class="me1">SetMimeType</span><span class="br0">&#40;</span>Format.<span class="me1">Xml</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> Utilities.<span class="me1">GetXmlStream</span><span class="br0">&#40;</span>obj<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">catch</span> <span class="br0">&#40;</span>Exception e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="co1">// Was it a schema validation error? If so, provide detail.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw4">string</span>.<span class="me1">IsNullOrEmpty</span><span class="br0">&#40;</span>_XmlValidationErrors<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// I slipped here, using BadGateway 502 instead of Bad Request 400.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// But WCF doesn&#39;t care. If you enter the catch block it&#39;s _always_ 400.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;WebOperationContext.<span class="me1">Current</span>.<span class="me1">OutgoingResponse</span>.<span class="me1">StatusCode</span> <span class="sy0">=</span> HttpStatusCode.<span class="me1">BadGateway</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;WebOperationContext.<span class="me1">Current</span>.<span class="me1">OutgoingResponse</span>.<span class="me1">StatusDescription</span> <span class="sy0">=</span> _XmlValidationErrors;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;WebOperationContext.<span class="me1">Current</span>.<span class="me1">OutgoingResponse</span>.<span class="me1">SuppressEntityBody</span> <span class="sy0">=</span> <span class="kw1">false</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">return</span> <span class="kw1">null</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>If no error occurs, WCF will return the status code you specify. A try/finally block will work just fine; WCF returns whatever status code you specify. Enter a catch block, though, and it&#8217;s nothing but <strong>400 Bad Request</strong>. </p>
<p>Hey, if there&#8217;s an error, it <em>must </em>be the client&#8217;s fault, right?</p>


<p>Related posts:<ol><li><a href='http://underground.infovark.com/2009/03/24/rest-how-to-respond-to-an-http-post/' rel='bookmark' title='REST: How to respond to an HTTP POST'>REST: How to respond to an HTTP POST</a></li>
<li><a href='http://underground.infovark.com/2008/05/21/wcf-instance-context/' rel='bookmark' title='WCF Instance Context'>WCF Instance Context</a></li>
<li><a href='http://underground.infovark.com/2008/05/17/using-wcf-for-rest-part-2/' rel='bookmark' title='Using WCF for REST, Part 2'>Using WCF for REST, Part 2</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/04/09/wcf-bad-request/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The Address Bar as the New Command Line</title>
		<link>http://underground.infovark.com/2008/04/01/the-address-bar-as-the-new-command-line/</link>
		<comments>http://underground.infovark.com/2008/04/01/the-address-bar-as-the-new-command-line/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 18:21:30 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://underground.infovark.com/?p=12</guid>
		<description><![CDATA[It&#8217;s been a common meme over the past few years that command-line interfaces (CLIs) are making a resurgence. Jeff Atwood noted in 2005 that the Google search box is a command line of sorts. In early 2007, Lifehacker&#8217;s Gina Trapani listed several examples of CLIs showing up in a variety of applications. The return of [...]


<i>No related posts.</i>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a common meme over the past few years that command-line interfaces (CLIs) are making a resurgence.  Jeff  Atwood noted in 2005 that <a href="http://www.codinghorror.com/blog/archives/000296.html">the Google search box is a command line</a> of sorts.  In early 2007, Lifehacker&#8217;s Gina Trapani listed several examples of <a href="http://lifehacker.com/software/command-line/geek-to-live--the-command-line-comeback-226223.php">CLIs showing up in a variety of applications</a>.</p>
<p>The return of the command-line interface is striking. It was pronounced dead, replaced by the graphical user interface (GUI) more than two decades ago, after usability research discovered that novice users were much more comfortable with GUIs. But a CLI has three big advantages over a GUI.</p>
<p>The first advantage is speed. Expert users find that command-line interfaces are significantly faster than GUIs. People can type much faster than they can identify a link or button, move the mouse to it, and click. This is especially true if the user&#8217;s hands are already positioned above the keyboard. People that do a significant amount of word processing (or writing code) often memorize keyboard shortcuts to avoid having to grab the mouse. It might save only a fraction of second, but if you do it many, many times over the course of the day, those split-second differences add up.</p>
<p>The second advantage is that a command line interface is a <em>linear</em> interface. Neither the user nor the application have to worry about the exact position of the pointing device over a two-dimensional surface. This makes command-line interfaces ideal for devices that have tiny screens, or whose pointing devices aren&#8217;t very accurate. It&#8217;s much easier to text a few commands on a cell phone or PDA than it is to use a stylus or manipulate a touch screen.</p>
<p>These first two advantages of CLIs are are well-known. The third advantage is less obvious: It turns out that CLIs are also much easier for <em>computers</em> to use.</p>
<p>Why do we care about making things easier on our silicon-based friends? Well, one reason is that it indirectly makes things easier on those of us humans that give instructions to computers. (As a programmer myself, that&#8217;s a big selling point.) Another reason is that if it&#8217;s easy enough for a computer to figure out, then it ought to be brain-dead simple for a human to understand. As I&#8217;ve pointed out before, <a href="http://www.infovark.com/2008/01/31/code-head/">computers just aren&#8217;t very bright</a>.</p>
<p>So the advantage of having a command-line interface is that if you, a human, get bored of typing the same silly commands over and over, you can easily write a small program that instructs a computer to do it for you.  This is the reason why every office suite has some kind of macro language. It allows humans to hand off repetitive tasks to a machine so that people can get on with the important creative stuff.</p>
<p>So what&#8217;s this about using a browser&#8217;s address bar as a command line? With <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29">AJAX</a> technologies, the URI is no longer merely something that a human types into the address bar to get a web page. It&#8217;s also an interface that computers use to interact with data. This means the humble web URL shares most of the key characteristics and advantages of a command line interface.</p>
<p>It&#8217;s this insight that&#8217;s led to increased interest in the <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a> architectural style. REST has begun moving into the mainstream because the patterns it promotes allow the URI to serve an audience of computers as well as an audience of humans.</p>


<p><i>No related posts.</i></p>]]></content:encoded>
			<wfw:commentRss>http://underground.infovark.com/2008/04/01/the-address-bar-as-the-new-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

