<?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; caching</title>
	<atom:link href="http://blog.emmerinc.be/index.php/tag/caching/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>Mon, 06 Sep 2010 19:43:52 +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>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>
	</channel>
</rss>
