<?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>Dan Rigsby - Coding Up Style &#187; REST</title>
	<atom:link href="http://www.danrigsby.com/blog/index.php/category/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danrigsby.com/blog</link>
	<description>Developer.Speaker.Blogger</description>
	<lastBuildDate>Tue, 17 Nov 2009 18:29:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>New Webcast: REST Support in WCF</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/09/25/new-webcast-rest-support-in-wcf/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/09/25/new-webcast-rest-support-in-wcf/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 13:55:00 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Wcf]]></category>
		<category><![CDATA[Webcast]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/09/25/new-webcast-rest-support-in-wcf/</guid>
		<description><![CDATA[ I have a new 10 min 12 sec training webcast up over adding REST support to a WCF application.&#160; This video builds on top of the Understanding REST video.&#160; If you have a decent understanding of REST, you don’t necessarily need to watch that video first, but in it I define the 4 tenets [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/09/screencast1thumb.png"><img title="screencast1-thumb" style="border-right: 0px; border-top: 0px; display: inline; margin: 0px 0px 0px 5px; border-left: 0px; border-bottom: 0px" height="128" alt="screencast1-thumb" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/09/screencast1thumb-thumb.png" width="128" align="right" border="0" /></a> I have a new 10 min 12 sec training webcast up over adding REST support to a WCF application.&#160; This video builds on top of the <a href="http://www.danrigsby.com/blog/index.php/2008/09/11/new-webcast-understanding-rest/">Understanding REST video</a>.&#160; If you have a decent understanding of REST, you don’t necessarily need to watch that video first, but in it I define the 4 tenets of REST which this video applies to WCF. This video also complements a recent presentation I have been giving called “<a href="http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/">RESTing on the Web with WCF</a>”.</p>
<p>So what are you waiting for?&#160; Head on over and check out the webcast!</p>
<p>The video available through <a href="http://www.jupitermedia.com">JupiterMedia</a> and can be viewed at <a href="http://www.internet.com/video/">http://www.internet.com/video/</a>. Just look for the &quot;Developer Video&quot; titled &quot;REST Support in WCF&quot;.</p>
<p>Direct links are:    <br /><a title="http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1815668056" href="http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1815668056">http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1815668056</a></p>
<div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.danrigsby.com/blog/index.php/2008/09/25/new-webcast-rest-support-in-wcf/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.danrigsby.com/blog/index.php/2008/09/25/new-webcast-rest-support-in-wcf/&amp;bgcolor=FF8000&amp;fgcolor=FFFFFF&amp;border=000000&amp;cbgcolor=D4E1ED&amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/09/25/new-webcast-rest-support-in-wcf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New Webcast: Understanding REST</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/09/11/new-webcast-understanding-rest/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/09/11/new-webcast-understanding-rest/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 19:44:33 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Webcast]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/?p=500</guid>
		<description><![CDATA[ I have a new 12 min 0 sec training webcast out over REST.&#160; This video is designed to explain REST at an architectural level, without diving into how to implement it in any specific language. This complements a recent presentation I have been giving called “RESTing on the Web with WCF”.
The video available through [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/09/screencast1.png"><img title="screencast1" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="128" alt="screencast1" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/09/screencast1-thumb.png" width="128" align="right" border="0" /></a> I have a new 12 min 0 sec training webcast out over <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>.&#160; This video is designed to explain REST at an architectural level, without diving into how to implement it in any specific language. This complements a recent presentation I have been giving called “<a href="http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/">RESTing on the Web with WCF</a>”.</p>
<p>The video available through <a href="http://www.jupitermedia.com">JupiterMedia</a> and can be viewed at <a href="http://www.internet.com/video/">http://www.internet.com/video/</a>. Just look for the &quot;Developer Video&quot; titled &quot;Understanding REST&quot;.</p>
<p>Direct links are:    <br /><a title="http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1788889483" href="http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1788889483">http://link.brightcove.com/services/link/bcpid1431564240/bclid1433966034/bctid1788889483</a>    <br /><a href="http://www.internet.com/player/index.php?bcpid=1431564240&amp;bclid=1433966034&amp;bctid=1788889483">http://www.internet.com/player/index.php?bcpid=1431564240&amp;bclid=1433966034&amp;bctid=1788889483</a></p>
<div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.danrigsby.com/blog/index.php/2008/09/11/new-webcast-understanding-rest/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.danrigsby.com/blog/index.php/2008/09/11/new-webcast-understanding-rest/&amp;bgcolor=FF8000&amp;fgcolor=FFFFFF&amp;border=000000&amp;cbgcolor=D4E1ED&amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/09/11/new-webcast-understanding-rest/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>RESTing on the Web with Wcf</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 20:51:48 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Wcf]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/</guid>
		<description><![CDATA[I had the opportunity to speak the Kentucky Day of .Net yesterday. I gave my Agile Project Management with Scrum talk and got to premier my newest presentation on REST entitled RESTing on the Web with Wcf.&#160; Both talks went very well.&#160; The REST presentation was a blast to do.&#160; I got a number of [...]]]></description>
			<content:encoded><![CDATA[<p>I had the opportunity to speak the <a href="http://kydayof.net/default.aspx">Kentucky Day of .Net</a> yesterday. I gave my <a href="http://www.danrigsby.com/files/Presentations/AgileMgmtWithScrum.zip">Agile Project Management with Scrum</a> talk and got to premier my newest presentation on REST entitled <a href="http://www.danrigsby.com/files/Presentations/RestingOnTheWeb.zip">RESTing on the Web with Wcf</a>.&#160; Both talks went very well.&#160; The REST presentation was a blast to do.&#160; I got a number of excellent comments afterwards, and I think it may be my new favorite talk to give.&#160; I want to give a “Thank You” to the organizers of such a great event,&#160; and I want to thank all of the people who made it out. If you attended any of my talks, please pass on any feedback about what I could do better or what I did right.&#160; I am always looking for ways to improve and to help convey the material to others. And, if you are interested in REST, know a lot about it, or are giving other presentations on REST, I would appreciate any comments you may have on my slides.</p>
<p>To catch any of my future talks, you can always check out my speaking engagements here: <a title="Speaking Engagements" href="http://www.danrigsby.com/blog/index.php/speakings/">Speaking Engagements</a>. I am currently promoting 4 main talks this season (September – November). If you are interested in hearing any of these, <strong><em>please</em></strong> send me an email, talk to your user group leaders, or comment on this thread.&#160; I enjoy every opportunity to speak, share, and talk with my peers. <em>I do still have materials for a session on Heroes {Community} Launch (Visual Studio 2008 and .Net 3.5), if there is any interest in this still.</em></p>
<table cellspacing="0" cellpadding="2" width="100%" border="1">
<tbody>
<tr>
<td valign="top" width="30%"><a href="http://www.danrigsby.com/files/Presentations/RestingOnTheWeb.zip">RESTing on the Web with Wcf</a></td>
<td valign="top" width="70%">.Net 3.5 ushered in a new Web Programming Model for Wcf which extended the library to support REST, Json, and Syndication.&#160; This session will dive into what this new model has to offer and how you can use it to extend the reach and scalability of your applications.</td>
</tr>
<tr>
<td valign="top" width="30%">Duplexing WCF in the Enterprise (Don’t call us, we’ll call you!)</td>
<td valign="top" width="70%">Duplexing in Wcf is the act of having the service call back to its clients.&#160; This topic rarely gets touched on, but is crucial for complex enterprise applications.&#160; This session explains duplexing and introduces the Publish/Subscribe server model as an example of how this can be used in an enterprise level application.</td>
</tr>
<tr>
<td valign="top" width="30%"><a href="http://www.danrigsby.com/files/Presentations/IntroductionToWcf.zip">Introduction to Wcf</a></td>
<td valign="top" width="70%">Windows Communication Foundation is Microsoft’s &quot;next-generation&quot; programming platform and runtime system for building, configuring and deploying network-distributed services. It was initially released with .Net 3.0, but there are many people who have yet to dive into this technology. This is an introduction session that will guide you through the basics of Wcf, why you should move to Wcf, and how you can move your existing applications to Wcf.</td>
</tr>
<tr>
<td valign="top" width="30%"><a href="http://www.danrigsby.com/files/Presentations/AgileMgmtWithScrum.zip">Agile Project Management with Scrum</a></td>
<td valign="top" width="70%">An introduction to Agile Project Management with Scrum. We will go over the Agile Manifesto and dive into the core principles that make up Scrum and how it can be used to help your development processes.</td>
</tr>
</tbody>
</table>
<p><em>Expect new presentations for Winter (December – February).&#160; I am anticipating upcoming talks on the following: <a href="http://jquery.com/">JQuery</a>, <a href="http://en.wikipedia.org/wiki/Windows_Live_Core">Live Mesh API</a>, <a href="http://www.microsoft.com/soa/products/oslo.aspx">Oslo</a>, and <a href="http://www.danrigsby.com/blog/index.php/2008/08/18/microsoft-pdc-2008/">PDC 2008</a>.</em></p>
<p><em></em></p>
<p><a href="http://www.danrigsby.com/blog/wp-content/uploads/2008/09/dsc03064.jpg"><img title="DSC03064" style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 5px 0px 0px; border-right-width: 0px" height="184" alt="DSC03064" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/09/dsc03064-thumb.jpg" width="244" align="left" border="0" /></a>As a <em>treat</em>, here is a picture of “RESTifarian Dan the Pig” taken at the closing ceremony of <a href="http://kydayof.net/default.aspx">Kentucky Day of .Net</a>.&#160; I didn’t wear both of these items at the same time during my talks, but those who attended would understand each of these props. </p>
<div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"><a href="http://www.dotnetkicks.com/kick/?url=http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/&amp;bgcolor=FF8000&amp;fgcolor=FFFFFF&amp;border=000000&amp;cbgcolor=D4E1ED&amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/"></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/09/07/resting-on-the-web-with-wcf/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>REST and Max URL Size</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/06/17/rest-and-max-url-size/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/06/17/rest-and-max-url-size/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 18:47:00 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Wcf]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/?p=244</guid>
		<description><![CDATA[I have heard many people say that the definition of REST is to just put everything in the URL.&#160; This isn’t true.&#160; One of the tenants of REST is to “embrace” the URL and use it as much as possible, but moving information to POST data is just as important and often necessary.&#160; I can [...]]]></description>
			<content:encoded><![CDATA[<p>I have heard many people say that the definition of REST is to just put everything in the URL.&#160; This isn’t true.&#160; One of the tenants of REST is to “embrace” the URL and use it as much as possible, but moving information to POST data is just as important and often necessary.&#160; I can understand how this can be misunderstood.&#160; Most REST interfaces do take in all values in into the URL to make it easier to navigate the data.&#160; Having to build a POST package can be tedious at times.&#160; So, what if you do want to send larger data to the service?&#160; When should you decide to move away from a pure URL approach and start using POST data in the header?</p>
<p><strong>Browser and WebServer Limits: </strong><em></em><a title="http://www.boutell.com/newfaq/misc/urllength.html" href="http://www.boutell.com/newfaq/misc/urllength.html"><em>http://www.boutell.com/newfaq/misc/urllength.html</em></a></p>
<ul>
<li><strong>Internet Explorer:</strong> <a href="http://support.microsoft.com/kb/208427">2,083 characters</a>, with no more than 2,048 characters in the path portion of the URL </li>
<li><strong>Firefox:</strong> 65,536 characters show up, but longer URLs do still work even up past 100,000 </li>
<li><strong>Safari:</strong> &gt; 80,000 characters </li>
<li><strong>Opera:</strong> &gt; 190,000 characters </li>
<li><strong>IIS:</strong> 16,384 characters, but is configurable </li>
<li><strong>Apache:</strong> 4,000 characters </li>
</ul>
<p>Different things can happen when you go beyond these URL limits depending on the browser and web servers. It could be a “413 (Entity Too Large)” error, “414 (Request-URI Too Long)” error, the URL could be truncated, or it may just work.&#160; However since different things can happen and your service could be consumed by any source, you have to assume the worst could happen.</p>
<p>By looking at just these numbers, it seems you would be pretty safe with a URL that gets up to 2,000 characters.&#160; However, lets look at the W3C standards on this.&#160; The HTTP specification doesn’t really set a size for the length of a URL, but it does recommend being cautious when going above 255. According to <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.2.2">Hypertext Transfer Protocol &#8211; HTTP/1.1 section 3.2</a>:</p>
<blockquote><p>Servers ought to be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations might not properly support these lengths.</p>
</blockquote>
<p>So for the sake of a REST interface you <em>should</em> avoid setting up an interface where there is any possibility of a URL getting beyond 255.&#160; If you are using a GET verb to request a resource via the URL you should be pretty safe.&#160; However POSTing or PUTing an insert or update via a URL may not be the way to go unless the data size is very small.</p>
<p>The most important thing is to keep your interfaces <strong>consistent</strong>.&#160; You don’t want one operation that allows an insert via the URL and another through POST data.&#160; This just makes things confusing and less discoverable.&#160; Especially since REST has no way to <a href="http://www.danrigsby.com/blog/index.php/2008/05/29/rest-services-and-metadata-endpoints-in-wcf/">publish metadata</a> about the operations.&#160;&#160; You could follow standards such as these:</p>
<table cellspacing="0" cellpadding="2" width="400" border="1">
<tbody>
<tr>
<td valign="top" width="143"><strong>CRUD Operation</strong></td>
<td valign="top" width="128"><strong>HTTP Verb</strong></td>
<td valign="top" width="127"><strong>Data Location</strong></td>
</tr>
<tr>
<td valign="top" width="143">Create</td>
<td valign="top" width="128">POST or PUT</td>
<td valign="top" width="127">POST Data</td>
</tr>
<tr>
<td valign="top" width="143">Read</td>
<td valign="top" width="128">GET</td>
<td valign="top" width="127">URL</td>
</tr>
<tr>
<td valign="top" width="143">Update</td>
<td valign="top" width="128">POST or PUT</td>
<td valign="top" width="127">POST Data</td>
</tr>
<tr>
<td valign="top" width="143">Delete</td>
<td valign="top" width="129">DELETE</td>
<td valign="top" width="127">URL</td>
</tr>
</tbody>
</table>
<p>In general this follows “<a href="http://lesscode.org/2006/03/19/high-rest/">High REST</a>” which is the more pure REST.&#160; This dictates that the HTTP Verbs define the methods to act on the resource. </p>
<p>Ultimately it’s up to you how you implement the REST interface, but stay consistent, be careful about URL limits, and try to follow industry standards.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/06/17/rest-and-max-url-size/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>REST Services and Metadata Endpoints in WCF</title>
		<link>http://www.danrigsby.com/blog/index.php/2008/05/29/rest-services-and-metadata-endpoints-in-wcf/</link>
		<comments>http://www.danrigsby.com/blog/index.php/2008/05/29/rest-services-and-metadata-endpoints-in-wcf/#comments</comments>
		<pubDate>Thu, 29 May 2008 13:21:15 +0000</pubDate>
		<dc:creator>Dan Rigsby</dc:creator>
				<category><![CDATA[REST]]></category>
		<category><![CDATA[Wcf]]></category>

		<guid isPermaLink="false">http://www.danrigsby.com/blog/?p=231</guid>
		<description><![CDATA[As mentioned in a previous article, there is no defined a way to get metadata about REST based services using webHttpBinding.&#160; Since REST doesn&#8217;t use SOAP, there is no WSDL that defines the service and no built in way to generate metadata about it.&#160; REST operations return back POX or JSON or something else.&#160; 
You [...]]]></description>
			<content:encoded><![CDATA[<p>As mentioned in a <a href="http://www.danrigsby.com/blog/index.php/2008/05/27/wcf-metadata/">previous article</a>, there is no defined a way to get <a href="http://www.danrigsby.com/blog/index.php/2008/05/27/wcf-metadata/">metadata</a> about <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a> based services using <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.webhttpbinding.aspx">webHttpBinding</a>.&#160; Since REST doesn&#8217;t use <a href="http://en.wikipedia.org/wiki/Simple_Object_Access_Protocol">SOAP</a>, there is no <a href="http://en.wikipedia.org/wiki/Web_Services_Description_Language">WSDL</a> that defines the service and no built in way to generate metadata about it.&#160; REST operations return back <a href="http://en.wikipedia.org/wiki/Plain_Old_XML">POX</a> or <a href="http://en.wikipedia.org/wiki/Json">JSON</a> or something else.&#160; </p>
<p>You can still create a <a href="http://msdn.microsoft.com/en-us/library/aa967390.aspx">mexHttpBinding</a> endpoint which can be used to represent the structure of the data that the REST service understands.&#160; You just cant really use this metadata to build a proxy client based on the REST interface. You don&#8217;t need any addition endpoints to expose the WSDL, having just a webHttpBinding endpoint is enough.&#160; You just need to enable httpGet on the serviceMetadata (see <a href="http://www.danrigsby.com/blog/index.php/2008/05/27/wcf-metadata/">here</a> for more detailed information on this):</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">serviceBehaviors</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">behavior</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">=&quot;contactServiceBehavior&quot;</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">serviceMetadata</span> <span style="color: #ff0000">httpGetEnabled</span><span style="color: #0000ff">=&quot;true&quot;</span><span style="color: #0000ff">/&gt;</span>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">behavior</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">serviceBehaviors</span><span style="color: #0000ff">&gt;</span></pre>
</div>
<p>One common tactic to give the REST service some kind of documentation, is to have a &quot;Documentation&quot; or &quot;Help&quot; method on your service that returns a an HTML page as a <a href="http://msdn.microsoft.com/en-us/library/system.io.stream.aspx">Stream</a> which describes how to work with the REST service (as seen in <a href="http://samples.netfx3.com/pictureservices/">pictureservices</a>).&#160; This isn&#8217;t really metadata that can be consumed to generate a proxy class, but it is informative to other developers and consumers of your REST service.</p>
<h2>Example</h2>
<p>Lets look at an example of the &quot;Documentation&quot; method on a REST service.&#160; This example is based on a simple contact service that holds a collection of contacts.&#160; Some of the methods are AddContact, GetContact, UpdateContact, etc. The complete interface for the service is:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">using System.Collections.Generic;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Syndication;
using System.ServiceModel.Web;

namespace Rigsby.RestDocumentation
{
    [ServiceContract]
    public interface IContactService
    {
        [OperationContract]
        [WebGet(UriTemplate = &quot;help&quot;)]
        Stream GetDocumentation();

        [OperationContract]
        [WebGet(UriTemplate = &quot;contacts&quot;)]
        List<span style="color: #0000ff">&lt;</span><span style="color: #800000">Contact</span><span style="color: #0000ff">&gt;</span> GetAllContacts();

        [OperationContract]
        [WebGet(UriTemplate = &quot;contacts/feed?format={format}&quot;,
            BodyStyle = WebMessageBodyStyle.Bare)]
        [ServiceKnownType(typeof(Atom10FeedFormatter))]
        [ServiceKnownType(typeof(Rss20FeedFormatter))]
        SyndicationFeedFormatter GetContactsFeed(string format);

        [OperationContract]
        [WebGet(UriTemplate = &quot;contact/{contactId}&quot;)]
        Contact GetContact(string contactId);

        [OperationContract]
        [WebGet(UriTemplate = &quot;contact/name/{name}&quot;)]
        List<span style="color: #0000ff">&lt;</span><span style="color: #800000">Contact</span><span style="color: #0000ff">&gt;</span> GetContactByName(string name);

        [OperationContract]
        [WebGet(UriTemplate=&quot;contact/name/startswith/{startsWith}&quot;)]
        List<span style="color: #0000ff">&lt;</span><span style="color: #800000">Contact</span><span style="color: #0000ff">&gt;</span> GetContactsWhereNameStartsWith(string startsWith);

        [OperationContract]
        [WebGet(UriTemplate = &quot;contact/name/endsWith/{endsWith}&quot;)]
        List<span style="color: #0000ff">&lt;</span><span style="color: #800000">Contact</span><span style="color: #0000ff">&gt;</span> GetContactsWhereNameEndsWith(string endsWith);

        [OperationContract]
        [WebGet(UriTemplate = &quot;contact/name/contains/{contains}&quot;)]
        List<span style="color: #0000ff">&lt;</span><span style="color: #800000">Contact</span><span style="color: #0000ff">&gt;</span> GetContactsWhereNameContains(string contains);

        [OperationContract]
        [WebInvoke(Method = &quot;POST&quot;, UriTemplate = &quot;contact/{name}&quot;)]
        void AddContact(string name);

        [OperationContract(Name = &quot;AddFullContact&quot;)]
        [WebInvoke(Method = &quot;POST&quot;, UriTemplate = &quot;contact&quot;)]
        void AddContact(Contact contact);

        [OperationContract]
        [WebInvoke(Method=&quot;DELETE&quot;, UriTemplate = &quot;contact/{contactId}&quot;)]
        int DeleteContact(string contactId);

        [OperationContract]
        [WebInvoke(Method = &quot;PUT&quot;, UriTemplate = &quot;contact/{contactId}&quot;)]
        void UpdateContact(string contactId, Contact contact);
    }
}</pre>
</div>
<p>The operation to look at is &quot;GetDocumentation&quot;.&#160; This method returns a stream which will be the HTML of the documentation for the service.&#160; The UriTemplate we are using is just &quot;help&quot;, so the full path would just be something like &quot;http://localhost:8080/ContactService/help&quot;.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">[OperationContract]
[WebGet(UriTemplate = <span style="color: #006080">&quot;help&quot;</span>)]
Stream GetDocumentation();</pre>
</div>
<div>&#160;</div>
<div>The implementation of this is pretty straight forward.&#160; We basically just create a new <a href="http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx">StreamWriter</a>, write the contents of our HTML to it, set content type of the outgoing response to &quot;text/html&quot;, and return the stream:</div>
<div>&#160;</div>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">public</span> Stream GetDocumentation()
{
    MemoryStream stream = <span style="color: #0000ff">new</span> MemoryStream();

    StreamWriter writer = <span style="color: #0000ff">new</span> StreamWriter(stream, Encoding.UTF8);
    writer.Write(Properties.Resources.Documentation);
    writer.Flush();
    stream.Position = 0;

    WebOperationContext.Current.OutgoingResponse.ContentType = <span style="color: #006080">&quot;text/html&quot;</span>;

    <span style="color: #0000ff">return</span> stream;
}</pre>
</div>
<div>&#160;</div>
<div>When a user navigates to &quot;http://localhost:8080/ContactService/help&quot;, the following HTML page is displayed which documents how to use the REST interface:</div>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" border="0" alt="restdoc" src="http://www.danrigsby.com/blog/wp-content/uploads/2008/05/restdoc.gif" width="675" height="534" /></p>
<p>The HTML for this was manually hacked together, but you could write some process that looks at some custom attributes on the service to build this help file:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; padding-left: 4px; font-size: 8pt; border-top: gray 1px solid; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;!</span><span style="color: #800000">DOCTYPE</span> <span style="color: #ff0000">html</span> <span style="color: #ff0000">PUBLIC</span> <span style="color: #0000ff">&quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;</span> <span style="color: #0000ff">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">html</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">=&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #ff0000">xml:lang</span><span style="color: #0000ff">=&quot;en-US&quot;</span> <span style="color: #ff0000">lang</span><span style="color: #0000ff">=&quot;en-US&quot;</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">title</span><span style="color: #0000ff">&gt;</span>Contact Service - Documentation<span style="color: #0000ff">&lt;/</span><span style="color: #800000">title</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">meta</span> <span style="color: #ff0000">http-equiv</span><span style="color: #0000ff">=&quot;Content-Type&quot;</span> <span style="color: #ff0000">content</span><span style="color: #0000ff">=&quot;text/html; charset=utf-8&quot;</span> <span style="color: #0000ff">/&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">style</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;text/css&quot;</span><span style="color: #0000ff">&gt;</span>
        body {margin: 0px;padding: 0px;font-family: Calibri, Tahoma, Arial;}
        .banner {padding: 5px 5px 5px 15px;background-color: Gray;color: White;}
        .content {margin: 15px;}
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">style</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">div</span> <span style="color: #ff0000">class</span><span style="color: #0000ff">=&quot;banner&quot;</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">h1</span><span style="color: #0000ff">&gt;</span>Contact Service<span style="color: #0000ff">&lt;/</span><span style="color: #800000">h1</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">div</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;</span><span style="color: #800000">div</span> <span style="color: #ff0000">class</span><span style="color: #0000ff">=&quot;content&quot;</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">h2</span><span style="color: #0000ff">&gt;</span>Available Feeds<span style="color: #0000ff">&lt;/</span><span style="color: #800000">h2</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">ul</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>GET /contacts/feed?format={format}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Returns a feed of all contacts as &quot;rss&quot; or &quot;atom&quot;<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ul</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">h2</span><span style="color: #0000ff">&gt;</span>Available Endpoints<span style="color: #0000ff">&lt;/</span><span style="color: #800000">h2</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;</span><span style="color: #800000">ul</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>GET /help<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Displays the service documentation<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>GET /contacts<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Returns all contacts<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>GET /contact/{contactId}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Returns a contact by contactId<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>GET /contact/name/{name}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Returns all contacts with the specified name<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>GET /contact/name/startswith/{startswith}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Returns all contacts whose name starts with the specified string<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>GET /contact/name/endsWith/{endsWith}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Returns all contacts whose name ends with the specified string<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>GET /contact/name/contains/{contains}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Returns all contacts whose name contains the specified string<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>

            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>POST /contact/{name}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Adds a new contact with the specified name (ignores POST data)<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>POST /contact<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Adds a new contact with the POST data<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>DELETE /contact/{contactId}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Deletes a contact by contactId<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
            <span style="color: #0000ff">&lt;</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;&lt;</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span>PUT /contact/{contactId}<span style="color: #0000ff">&lt;/</span><span style="color: #800000">b</span><span style="color: #0000ff">&gt;</span> <span style="color: #ff0000">&amp;mdash;</span> Updates a contact by contactId<span style="color: #0000ff">&lt;/</span><span style="color: #800000">li</span><span style="color: #0000ff">&gt;</span>
        <span style="color: #0000ff">&lt;/</span><span style="color: #800000">ul</span><span style="color: #0000ff">&gt;</span>
    <span style="color: #0000ff">&lt;/</span><span style="color: #800000">div</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span>
<span style="color: #0000ff">&lt;/</span><span style="color: #800000">html</span><span style="color: #0000ff">&gt;</span></pre>
</div>
<p>You can download a complete sample of the code discussed in this article here: <a href="http://www.danrigsby.com/Files/Rigsby.RestDocumentation.zip">http://www.danrigsby.com/Files/Rigsby.RestDocumentation.zip</a></p>
</p>
<p><a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fwww.danrigsby.com%2fblog%2findex.php%2f2008%2f05%2f29%2frest-services-and-metadata-endpoints-in-wcf%2f"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.danrigsby.com%2fblog%2findex.php%2f2008%2f05%2f29%2frest-services-and-metadata-endpoints-in-wcf%2f&amp;bgcolor=FF9900" border="0" alt="kick it on DotNetKicks.com" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.danrigsby.com/blog/index.php/2008/05/29/rest-services-and-metadata-endpoints-in-wcf/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

