<?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>Emmer Inc &#187; REST</title>
	<atom:link href="http://blog.emmerinc.be/index.php/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.emmerinc.be</link>
	<description>Tales from a .NET developer who's making the jump to the iPhone &#38; App Store wonderland.</description>
	<lastBuildDate>Wed, 23 Jun 2010 20:57:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Basic authentication of a .NET REST service</title>
		<link>http://blog.emmerinc.be/index.php/2009/07/28/basic-authentication-of-a-net-rest-service/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/07/28/basic-authentication-of-a-net-rest-service/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 17:07:36 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[sample]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WCF REST Contrib]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=566</guid>
		<description><![CDATA[One of the issues one can encounter when building a REST service with the .NET Framework 3.5 SP1 is the fact that when basic authentication is enabled, it defaults to authentication against Windows accounts in IIS. It&#8217;s not possible to specify your own handler/provider to authenticate against for instance a proprietary user database, nor is [...]]]></description>
			<content:encoded><![CDATA[<p>One of the issues one can encounter when building a REST service with the .NET Framework 3.5 SP1 is the fact that when basic authentication is enabled, it defaults to authentication against Windows accounts in IIS. It&#8217;s not possible to specify your own handler/provider to authenticate against for instance a proprietary user database, nor is it possible to secure only a certain operation/service and leave the others unsecured.</p>
<p>Luckily there&#8217;s a open source project hosted on <a href="http://www.codeplex.com/">CodePlex </a> called <a href="http://wcfrestcontrib.codeplex.com/">WCF REST Contrib</a> which, besides adding a whole lot of other improvements, solves the aforementioned issues. The project provides a sample solution showcasing all the features, which might seem a bit overwhelming since it includes quite some configuration. I have attached a sample project with only the bare minimum configuration (using attributes) to enable per operation authentication. </p>
<p>Browse to CancerService.svc/request/skincancer to test the authentication, the browser should display a prompt asking for a username and password. The username is &#8220;tony&#8221; and password &#8220;clifton&#8221;. Don&#8217;t mind the rather questionable service and operation name, I had no inspiration at the time.</p>
<p>The original documentation failed to mention that the per operation/service authentication depended on the WebErrorHandler, which has been corrected.</p>
<p>Attachment: <a href='http://blog.emmerinc.be/wp-content/uploads/2009/07/AuthenticationTryout.zip'>Authentication Tryout</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/07/28/basic-authentication-of-a-net-rest-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Caching using WCF REST Starter Kit in Medium Trust</title>
		<link>http://blog.emmerinc.be/index.php/2009/04/26/caching-using-wcf-rest-starter-kit-in-medium-trust/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/04/26/caching-using-wcf-rest-starter-kit-in-medium-trust/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 06:43:05 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[Medium Trust]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[WCF REST Starter Kit]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=463</guid>
		<description><![CDATA[Caching is one of the features provided by the WCF REST Starter Kit released by Microsoft at CodePlex. Jesus Rodriguez has written a walkthrough on how to get it running. The kit was designed to run under Medium Trust, but if you want to use caching in this trust level, you&#8217;ll have to configure it [...]]]></description>
			<content:encoded><![CDATA[<p>Caching is one of the features provided by the <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24644">WCF REST Starter Kit</a> released by Microsoft at CodePlex. <a href="http://weblogs.asp.net/gsusx/">Jesus Rodriguez</a> has written a <a href="http://weblogs.asp.net/gsusx/archive/2008/10/29/adding-caching-to-wcf-restful-services-using-the-rest-starter-kit.aspx">walkthrough</a> on how to get it running. The kit was designed to run under Medium Trust, but if you want to use caching in this trust level, you&#8217;ll have to configure it a bit differently.</p>
<blockquote><p>System.Security.SecurityException: Request for the permission of type &#8216;System.Configuration.ConfigurationPermission, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#8217; failed.</p></blockquote>
<p>Using Jesus&#8217; approach you&#8217;ll be greated by a nice Security Exception, for some reason you can&#8217;t configure the caching in the Web.Config in Medium Trust. Luckily you can add all the caching configuration as attributes to your method. You&#8217;ll have to remove the &lt;caching&gt; block from the Web.Config, but leave the aspNetCompatibilityEnabled tag enabled! Here&#8217;s an example:</p>
<p>Instead of using this XML configuration:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;caching<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outputCacheSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outputCacheProfiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;clear</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SampleProfile&quot;</span> <span style="color: #000066;">duration</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">enabled</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;Any&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outputCacheProfiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outputCacheSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/caching<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>We add these attributes, unfortunately you&#8217;ll have to add these attributes to every method you&#8217;d like to cache. There are more attributes available, you can see them using the IntelliSense, but this configuration mimics the XML config.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>AspNetCompatibilityRequirements<span style="color: #000000;">&#40;</span>RequirementsMode <span style="color: #008000;">=</span> AspNetCompatibilityRequirementsMode.<span style="color: #0000FF;">Allowed</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> SampleService <span style="color: #008000;">:</span> ISampleService
<span style="color: #000000;">&#123;</span>
   <span style="color: #000000;">&#91;</span>WebGet<span style="color: #000000;">&#40;</span>UriTemplate<span style="color: #008000;">=</span> <span style="color: #666666;">&quot;/results&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
   <span style="color: #000000;">&#91;</span>WebCache<span style="color: #000000;">&#40;</span>Duration<span style="color: #008000;">=</span><span style="color: #FF0000;">30</span>, Location<span style="color: #008000;">=</span>OutputCacheLocation.<span style="color: #0000FF;">Any</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
   <span style="color: #0600FF;">public</span> Atom10FeedFormatter GetData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
      ...
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Note: Tested in the ASP.NET Development Server provided by Visual Studio 2008 SP1. The OutputCacheLocation enum is located in the System.Web.UI namespace.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/04/26/caching-using-wcf-rest-starter-kit-in-medium-trust/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing svc extension of WCF REST service</title>
		<link>http://blog.emmerinc.be/index.php/2009/03/01/removing-svc-extension-of-wcf-rest-service/</link>
		<comments>http://blog.emmerinc.be/index.php/2009/03/01/removing-svc-extension-of-wcf-rest-service/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 23:35:38 +0000</pubDate>
		<dc:creator>Yannick Compernol</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://blog.emmerinc.be/?p=39</guid>
		<description><![CDATA[What if we had a REST service implemented with WCF to retrieve some info about a user. The method would be called with the following url: &#8220;http://domain/service.svc/user/john&#8221;. Although this works perfectly and conforms to the REST guidelines, for some the svc extension is a thorn in the eye. Turns out it&#8217;s very easy to strip [...]]]></description>
			<content:encoded><![CDATA[<p>What if we had a REST service implemented with WCF to retrieve some info about a user. The method would be called with the following url: &#8220;http://domain/service.svc/user/john&#8221;. Although this works perfectly and conforms to the REST guidelines, for some the svc extension is a thorn in the eye. Turns out it&#8217;s very easy to strip the svc extension with a HTTPModule. The module adds an eventhandler for the BeginRequest event of the application, each time a request is received the module checks if it is a call without the svc extension. If this is the case, it reroutes the request to service.svc with the specified parameters. To the outside world it will appear as if &#8220;http://domain/service/user/john&#8221; is called, while this resource actually does not exist.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Init<span style="color: #000000;">&#40;</span>HttpApplication context<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   context.<span style="color: #0000FF;">BeginRequest</span> <span style="color: #008000;">+=</span> <span style="color: #FF0000;">delegate</span>
   <span style="color: #000000;">&#123;</span>
      HttpContext ctx <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span><span style="color: #008000;">;</span>
      <span style="color: #FF0000;">string</span> path <span style="color: #008000;">=</span> ctx.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">AppRelativeCurrentExecutionFilePath</span>.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
      <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>path.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/service/&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
      <span style="color: #000000;">&#123;</span>
         <span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> path.<span style="color: #0000FF;">IndexOf</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">'/'</span>, <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
         <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>i <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
         <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> service <span style="color: #008000;">=</span> path.<span style="color: #0000FF;">Substring</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, i<span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;.svc&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> parameters <span style="color: #008000;">=</span> path.<span style="color: #0000FF;">Substring</span><span style="color: #000000;">&#40;</span>i, path.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">-</span> i<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            ctx.<span style="color: #0000FF;">RewritePath</span><span style="color: #000000;">&#40;</span>service, parameters, <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span>, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
         <span style="color: #000000;">&#125;</span>
      <span style="color: #000000;">&#125;</span>
   <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>In our case service would equals &#8220;~/service.svc&#8221; and the paramaters variable would equal &#8220;/user/john&#8221;.</p>
<p>Hooking the HTTPModule into the web.config is done in the system.web/httpmodules element. In this case the module class is called ServiceRedirector.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system.web<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;httpModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>  
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;add</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ServiceRedirector&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ServiceRedirector&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/httpModules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system.web<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>The HTTPModule above could be extended to support multiple services, but I leave that as an exercise for the reader.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.emmerinc.be/index.php/2009/03/01/removing-svc-extension-of-wcf-rest-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
