<?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"
	>

<channel>
	<title>Damian Mehers Blog</title>
	<atom:link href="http://damianblog.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://damianblog.com</link>
	<description>.NET from Geneva, Switzerland.</description>
	<pubDate>Sun, 26 Apr 2009 19:34:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
	<language>en</language>
			<item>
		<title>Got a product idea? Don&#8217;t register the domain.</title>
		<link>http://damianblog.com/2009/04/26/first-create-then-register/</link>
		<comments>http://damianblog.com/2009/04/26/first-create-then-register/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 19:22:36 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[business-of-software]]></category>

		<guid isPermaLink="false">http://damianblog.com/2009/04/26/first-create-then-register/</guid>
		<description><![CDATA[Since I started programming in the early eighties I’ve dreamed of ideas for software tools, utilities and products.&#160; I’ve followed through and created some of them, but for many I’ve not, and I think I’ve finally figured out why:&#160; it can only be because I registered the domain name before I created the product.&#160; Let [...]]]></description>
			<content:encoded><![CDATA[<p>Since I started programming in the early eighties I’ve dreamed of ideas for software tools, utilities and products.&#160; I’ve followed through and created some of them, but for many I’ve not, and I think I’ve finally figured out why:&#160; it can <em>only</em> be because I registered the domain name <em>before</em> I created the product.&#160; Let me explain …</p>
<p>Having an idea for a product or web site can be enormously seductive.&#160; We can dream away, and if we never follow through, we can never fail.&#160; Even better we can tell others about our fantastic idea, and almost know what it would feel like if it was a success.&#160; Almost.</p>
<p>But the killer is that we can research domain names.&#160; We can spend hours trying to find exactly the right domain for our product-to-be.&#160; The one we haven’t even started creating yet.&#160; And finally, when we’ve got that perfect domain, we can pull out our credit card, and register it.&#160; Then, we are done.&#160; That’s it.&#160; No need to do anything else.&#160; Dreamed about the success, got the domain name, and then … well, there isn’t really any need to take it any further, is there?</p>
<p>This post isn’t just about the dangers of premature registration, it is also to allow me to put some of my own overly-enthusiastic registrations to rest.&#160; So here they are.&#160; None of them are real, except in my imagination (and of course in the domain name registration) …</p>
<ul>
<li>Asknearme.com : Transient, anonymous conversations.&#160; A GPS-enabled mobile-phone location-based service that is an <strong>anti-social networking</strong> site, where you could anonymously ask questions to anyone who happens to be close to you geographically: where are the closest toilets?&#160; Has anyone found a green hat?&#160; </li>
<li>Askmystreet.com : do you know everyone on your street?&#160; Anyone?&#160; This site was to let you get in touch with people living near you, to help build physical communities out of virtual ones. </li>
<li>tracejs.com, jsprof.com, jsprofiler.com, javascriptprofiler.com : this product idea used the JavaScript debugger API on windows to continuously break into JavaScript code running in Internet Explorer, and let you see what JavaScript code was executed, and how much time each function took.&#160;&#160; <a href="/2008/09/09/tracejs-v2-rip/">I got close on this one</a>. </li>
</ul>
<p>For balance, I have got it right a few times:</p>
<ul>
<li><a href="http://www.mcefm.com/">mcefm.com</a> – listen to Last.fm in Windows Media Center.&#160; I’ve stopped developing it since Last.fm cracked down on the use of their APIs in some countries. </li>
<li><a href="http://www.beebmc.com/">beebmc.com</a> – listen to BBC Radio within Windows Media Center.&#160; Still exists, and still quite popular. </li>
<li>j-integra.com (<a href="http://www.j-integra.com/">not mine any more</a>) – Java-COM interoperability, initially through my Java implementation of the DCOM wire protocol. </li>
<li>promptsql.com (<a href="http://www.promptsql.com/">not mine any more</a>) – SQL Intellisense within Query Analyzer and SQL Server Management Studio </li>
</ul>
<p>This post is a <em>little</em> tongue in cheek, although there is a kernel of truth.&#160; It is important to follow through on our ideas, and not just live on the dream.&#160; Don’t deflate the excitement by working on the incidental.&#160; Tackle the core first.</p>
<p>Stop that dreaming, and get coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2009/04/26/first-create-then-register/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Windows Home Server needs a peer backup system</title>
		<link>http://damianblog.com/2009/04/11/whs-peer-backup/</link>
		<comments>http://damianblog.com/2009/04/11/whs-peer-backup/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 18:10:27 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[Product-Ideas]]></category>

		<guid isPermaLink="false">http://damianblog.com/2009/04/11/whs-peer-backup/</guid>
		<description><![CDATA[I&#8217;ve just set up a Windows Home Server on my home network, and so far I think it is fantastic. I&#8217;ve been able to collect an assortment of hard drives and plug them all into the same machine, and have them seamlessly presented as a single large virtual drive:

Our photos are stored in a shared [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just set up a <a href="http://en.wikipedia.org/wiki/Windows_Home_Server">Windows Home Server</a> on my home network, and so far I think it is fantastic. I&#8217;ve been able to collect an assortment of hard drives and plug them all into the same machine, and have them seamlessly presented as a single large virtual drive:</p>
<p><a href="http://damianblog.com/wp-content/uploads/2009/04/image1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="333" alt="image" src="http://damianblog.com/wp-content/uploads/2009/04/image-thumb1.png" width="474" border="0"></a></p>
<p>Our photos are stored in a shared folder hosted by the Windows Home Server, and by enabling the &#8220;Duplication&#8221; feature, I know that copies are kept on two physical disks, meaning that in the event of a hard disk failure, I&#8217;ll still have a copy on another disk.&nbsp; I&#8217;ve also been able to set up all of the computers in the house to be backed up.</p>
<p>There is however, as <a href="http://www.hanselman.com/blog/ReviewHPMediaSmartWindowsHomeServer.aspx">others have noted</a>, a big flaw in this situation. Although I have all my photos duplicated on two disks, and all my computers backed up , in the event of a fire, or theft, I&#8217;m screwed.&nbsp; Someone could walk off with all the physical disks.</p>
<p>What I really need is off-site backup. I&#8217;ve been doing this using an excellent service called <a href="http://en.wikipedia.org/wiki/Mozy">Mozy</a>, which for US$5 a month offers unlimited backups for a single PC.&nbsp; Unfortunately Windows Home Server is based on Windows Server 2003, and Mozy will not run on Server operating systems.</p>
<h3>A modest idea: a peer backup service</h3>
<p>What I&#8217;d like to have, and what I&#8217;m tempted to develop, is a peer backup system, implemented via a Windows Home Server Add-in I&#8217;d create, and a web site which serves to hook people&#8217;s Windows Home Servers together.</p>
<p>My idea is this: I&#8217;d create a web site where people could register (probably automatically via the add-in) their need for an off-site backup, indicating how much space they need to backup. They need to commit to making an equivalent amount of space available on their computer for someone else.</p>
<p>My web site would match people up, and then the people could use each others systems to automatically perform offsite backups.&nbsp; The add-ins could talk to each other, either peer-to-peer, or via my web site. There are issues of course. The backed up data would have to be encrypted, which makes incremental backups problematic.</p>
<p>The next obvious step would be to allow the backups to be stored redundantly across the computers of multiple participants, so that you are not just reliant on one other person.&nbsp; For this to work you&#8217;d need to volunteer to make available much more space for other people&#8217;s backups than your own backups require - perhaps twice as much.</p>
<p>I&#8217;m tempted to develop this service, however&nbsp; I&#8217;m not sure how I could cover my costs. Would you pay say US$25 a year for a peer-based secure offsite backup service?</p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2009/04/11/whs-peer-backup/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cycling to work: give it some thought.</title>
		<link>http://damianblog.com/2009/03/30/cycling-to-work-give-it-some-thought/</link>
		<comments>http://damianblog.com/2009/03/30/cycling-to-work-give-it-some-thought/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 04:00:02 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[Fluff]]></category>

		<guid isPermaLink="false">http://damianblog.com/2009/03/30/cycling-to-work-give-it-some-thought/</guid>
		<description><![CDATA[
I started working for Cargill Energy at the beginning of 2009, and almost immediately decided to cycle the 23 km (14 miles) each way.&#160;&#160;&#160; I live in a small village along lake Geneva in Switzerland, and work in Geneva itself.&#160;
The cycle ride takes me along the lake road, through villages that date back to Roman [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>I started working for <a href="http://www.cargillenergy.com/">Cargill Energy</a> at the beginning of 2009, and almost immediately decided to cycle the 23 km (14 miles) each way.&nbsp;&nbsp;&nbsp; I live in a small village along lake Geneva in Switzerland, and work in Geneva itself.&nbsp;
<p>The cycle ride takes me along the lake road, through villages that date back to Roman times, and into Geneva itself.&nbsp; A shortcut through the old part of the town gets me to Cargill around 6:40.&nbsp; I take a shower and am at my desk at 7am.
<p>It was tough to start with.&nbsp; It was below freezing, dark, and the cycle paths had big chunks of ice welded to the ground.&nbsp;
<p>After a minute or two of cycling I go into auto-pilot and start thinking about stuff.&nbsp; I usually regain consciousness an hour or so later when I&#8217;m at the office, and I find that I&#8217;ve generally made decisions.&nbsp; Sometimes tough decisions about what I need to do to advance my career, what I need to propose to the team I&#8217;m in to help us work more effectively, but I also gain significant insight into how I could go about designing a piece of software I&#8217;m working on,
<p>Two hours a day is a big chunk of time to spend commuting to work, but it really isn&#8217;t two hours spent exercising: its two hours spent thinking. And they are almost always the two most valuable hours of my working day. </p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2009/03/30/cycling-to-work-give-it-some-thought/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Screencast: Testing, Mocking and Dependency Injection: more than just buzz-words</title>
		<link>http://damianblog.com/2009/02/20/testingmockingandependencyinjection/</link>
		<comments>http://damianblog.com/2009/02/20/testingmockingandependencyinjection/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 19:36:15 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[Screencast]]></category>

		<guid isPermaLink="false">http://damianblog.com/2009/02/20/testingmockingandependencyinjection/</guid>
		<description><![CDATA[This 40 minute screencast covers unit testing, mocking, dependency injection, and inversion of control. 
The idea is again that this will be is very much a hands-on, practical screencast.&#160; Not technology for its own sake, but reviewing how and why these concepts evolved, and how they can be used in practice. 
I&#8217;m not a TDD [...]]]></description>
			<content:encoded><![CDATA[<p>This 40 minute screencast covers unit testing, mocking, dependency injection, and inversion of control. </p>
<p>The idea is again that this will be is very much a hands-on, practical screencast.&#160; Not technology for its own sake, but reviewing how and why these concepts evolved, and how they can be used in practice. </p>
<p>I&#8217;m not a TDD (Test Driven Development) fanatic, I don&#8217;t think we should always have 100% code coverage with our tests, but I do think there is a lot of value in testing, and in making our code testable.</p>
<p>The screencast is available here <a href="http://damianblog.com/TestingMockingAndDependencyInjection.wmv">http://damianblog.com/TestingMockingAndDependencyInjection.wmv</a></p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2009/02/20/testingmockingandependencyinjection/feed/</wfw:commentRss>
<enclosure url="http://damianblog.com/TestingMockingAndDependencyInjection.wmv" length="54399309" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>Screencast intro to VS 2008 &#38; .NET 3.5</title>
		<link>http://damianblog.com/2009/02/16/screencast-intro-net35/</link>
		<comments>http://damianblog.com/2009/02/16/screencast-intro-net35/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 20:14:15 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[Screencast]]></category>

		<guid isPermaLink="false">http://damianblog.com/2009/02/16/screencast-intro-net35/</guid>
		<description><![CDATA[I recently gave a presentation at work introducing some of the new features of VS 2008 and .NET 3.5.&#160; No slides, just code.&#160; And no pre-prepared chunks of code that are pasted into the editor either - everything written by hand.
In this 40 minute screencast I blast through Automatic Properties, Collection Initializers (Lists &#38; Dictionaries), [...]]]></description>
			<content:encoded><![CDATA[<p>I recently gave a presentation at work introducing some of the new features of VS 2008 and .NET 3.5.&nbsp; No slides, just code.&nbsp; And no pre-prepared chunks of code that are pasted into the editor either - everything written by hand.</p>
<p>In this 40 minute screencast I blast through Automatic Properties, Collection Initializers (Lists &amp; Dictionaries), Implicit Typing, Anonymous Types, Extensions Methods, &#8220;Normal&#8221; Delegates, Anonymous Delegates, a natural evolution of delegates to Lambda expressions, Linq to objects using method chaining, Linq to objects using the natural Linq syntax, and finally Linq to XML.</p>
<p>Download or watch the screencast here: <a href="http://damianblog.com/WhatsNewInVS2008and.NET3.5.wmv">http://damianblog.com/WhatsNewInVS2008and.NET3.5.wmv</a></p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2009/02/16/screencast-intro-net35/feed/</wfw:commentRss>
<enclosure url="http://damianblog.com/WhatsNewInVS2008and.NET3.5.wmv" length="57818401" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>Microsoft fixed my bug</title>
		<link>http://damianblog.com/2009/02/14/finally-an-os-bug/</link>
		<comments>http://damianblog.com/2009/02/14/finally-an-os-bug/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 18:27:52 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[Debugging]]></category>

		<guid isPermaLink="false">http://damianblog.com/2009/02/14/finally-an-os-bug/</guid>
		<description><![CDATA[Like a lot of people, when I first began developing on a &#8220;proper&#8221; Operating System (as opposed to the 8 bit computers I started with), sooner or later I convinced myself I&#8217;d found a bug in the operating system.
Of course I&#8217;d be wrong, and after suffering the embarrassment of discovering that it was my own [...]]]></description>
			<content:encoded><![CDATA[<p>Like a lot of people, when I first began developing on a &#8220;proper&#8221; Operating System (as opposed to the 8 bit computers I started with), sooner or later I convinced myself I&#8217;d found a bug in the operating system.</p>
<p>Of course I&#8217;d be wrong, and after suffering the embarrassment of discovering that it was my own stupidity, rather than an OS bug, that was causing the errors, I eventually acquired an automatic reflex to never ever believe that there was a bug in the OS.&nbsp; It had to be a bug in my code.&nbsp; This was a good thing, since I was always right.</p>
<p>Despite this, it seems that I never fully learned this lesson.&nbsp; And so it was that last May I opened a <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=331513">bug report on Microsoft Connect</a>, fully expecting to be gently, but firmly rebuffed, with an explanation of where exactly I&#8217;d gone wrong.</p>
<p>The issue that I was facing was in detecting whether a connection to my web application was coming from the local machine (running the web application), or from a remote machine.&nbsp; I was calling the <a href="http://msdn.microsoft.com/en-us/library/system.net.httplistenerrequest.islocal.aspx">HttpListenerContext.Request.IsLocal</a> method, and it was always returning false, even though the client was definitely local.</p>
<p>A little digging with <a href="http://reflector.red-gate.com/Download.aspx">Reflector</a> showed that the method was implemented using &#8220;==&#8221; to compare the local address with the remote address, instead of the Equals method.&nbsp; If the &#8220;==&#8221; operator had been overloaded then it would have worked.</p>
<p>A couple of days ago, I got a message saying that this was indeed a bug, and that it was fixed in version 4.0 of the .NET framework.&nbsp; So it looks like I have finally actually discovered an honest-to-goodness bug.</p>
<p>Or perhaps they are just being kind to me.</p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2009/02/14/finally-an-os-bug/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Small utility to generate summary of your Media Center recorded movies</title>
		<link>http://damianblog.com/2008/12/21/small-utility-to-generate-summary-of-your-media-center-recorded-movies/</link>
		<comments>http://damianblog.com/2008/12/21/small-utility-to-generate-summary-of-your-media-center-recorded-movies/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 20:47:14 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[Media Center]]></category>

		<guid isPermaLink="false">http://damianblog.com/2008/12/21/small-utility-to-generate-summary-of-your-media-center-recorded-movies/</guid>
		<description><![CDATA[I&#8217;ve created a small simple utility to create an HTML summary document listing all the movies I&#8217;ve recorded using Vista Media Center.
I did this to get a compact record which I can browse without firing up Media Center, and which I can print out to give to visitors that are not familiar with Media Center.
This [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a small simple utility to create an HTML summary document listing all the movies I&#8217;ve recorded using Vista Media Center.</p>
<p>I did this to get a compact record which I can browse without firing up Media Center, and which I can print out to give to visitors that are not familiar with Media Center.</p>
<p>This is what the output looks like:</p>
<p><a href="http://www.atadore.com/images/SmallutilitytogeneratesummaryofyourMedia_12CEF/image.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="366" alt="image" src="http://www.atadore.com/images/SmallutilitytogeneratesummaryofyourMedia_12CEF/image_thumb.png" width="464" border="0" /></a></p>
<p>The links you can see are links to IMDB.</p>
<p>When you run the utility you can choose the directories it should look in, and the name of the output file:</p>
<p><a href="http://www.atadore.com/images/SmallutilitytogeneratesummaryofyourMedia_12CEF/image_3.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="298" alt="image" src="http://www.atadore.com/images/SmallutilitytogeneratesummaryofyourMedia_12CEF/image_thumb_3.png" width="463" border="0" /></a></p>
<p>The first checkbox lets you tell the utility to only output films that it has found duplicated &#8212; I added this so that I could easily find films that I&#8217;d recorded twice by accident.&#160; The second checkbox tells it to also output the locations of the media files so that you can see where they are.</p>
<p>This tool is free, unsupported, and is to be used <u>entirely at your own risk</u>.&#160; <strong>You can download it <a href="http://damianblog.com/download/GenerateVMCMoviesHtml.exe">here</a></strong>.</p>
<p>You might also want to <a href="http://damianblog.com/2008/04/28/bulk-fetching-images-for-dvr-ms-files/">check out this other utility</a> which you can use to download image files for your films so that the images appear in generated html and also in Windows Media Center.</p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2008/12/21/small-utility-to-generate-summary-of-your-media-center-recorded-movies/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dealing with WCF Error: Cannot create a service reference with namespace X because the name is already in use by an existing service reference, folder or file</title>
		<link>http://damianblog.com/2008/12/04/cannot-create-service-reference/</link>
		<comments>http://damianblog.com/2008/12/04/cannot-create-service-reference/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 11:07:56 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://damianblog.com/2008/12/04/cannot-create-service-reference/</guid>
		<description><![CDATA[If you get the above error when trying to add a WCF service reference that you have previously deleted then try:

 deleting the Service References.DeviceService.Reference.cs.dll file you&#8217;ll find under obj\Debug\TempPE.&#160; 
deleting the service folder you&#8217;ll still find under Service References on disk, even though you deleted the reference in Visual Studio.
commenting out all references to [...]]]></description>
			<content:encoded><![CDATA[<p>If you get the above error when trying to add a WCF service reference that you have previously deleted then try:</p>
<ul>
<li> deleting the <font face="Consolas">Service References.DeviceService.Reference.cs.dll</font> file you&#8217;ll find under <font face="consol">obj\Debug\TempPE.&#160; </font></li>
<li>deleting the service folder you&#8217;ll still find under <font face="Consolas">Service References </font>on disk, even though you deleted the reference in Visual Studio.</li>
<li>commenting out all references to the service&#8217;s namespace in your code</li>
<li>rebuilding</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2008/12/04/cannot-create-service-reference/feed/</wfw:commentRss>
		</item>
		<item>
		<title>My PDC 2008 &#34;Show Off&#34; entry: Using .NET code injection to do the seemingly impossible</title>
		<link>http://damianblog.com/2008/11/05/my-pdc-2008-show-off-entry-using-net-code-injection-to-do-the-seemingly-impossible/</link>
		<comments>http://damianblog.com/2008/11/05/my-pdc-2008-show-off-entry-using-net-code-injection-to-do-the-seemingly-impossible/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 20:29:47 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[Media Center]]></category>

		<category><![CDATA[Screencast]]></category>

		<guid isPermaLink="false">http://damianblog.com/2008/11/05/my-pdc-2008-show-off-entry-using-net-code-injection-to-do-the-seemingly-impossible/</guid>
		<description><![CDATA[Having come third in the first event &#34;Show Off&#34; entry, for PDC 2005, I decided to submit an entry for the 2008 PDC.
I decided to base my entry on a .NET code injection blog article I&#8217;d written a couple of months ago.&#160; I got a very positive response from the people running the contest, although [...]]]></description>
			<content:encoded><![CDATA[<p>Having <a href="http://channel9.msdn.com/posts/PDC2005ShowOff/How-I-Got-SQL-Intellisense-Working-in-Microsoft-Query-Analyzer/">come third</a> in the first event &quot;Show Off&quot; entry, for PDC 2005, I decided to submit an entry for the 2008 PDC.</p>
<p>I decided to base my entry on a <a href="http://damianblog.com/2008/07/02/net-code-injection/">.NET code injection blog article</a> I&#8217;d written a couple of months ago.&#160; I got a very positive response from the people running the contest, although on the night I didn&#8217;t actually win. </p>
<p>I missed the showing of my entry because I was attending a dinner thrown by Microsoft Switzerland for the people that attended the PDC from Switzerland.</p>
<p>In any event, here is my entry: <a title="http://damianblog.com/DamianMehersPDC2008ShowOff.wmv" href="http://damianblog.com/DamianMehersPDC2008ShowOff.wmv">http://damianblog.com/DamianMehersPDC2008ShowOff.wmv</a></p>
<p>&#160;</p>
<p> <!-- begin embedded WindowsMedia file... --></p>
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2008/11/05/my-pdc-2008-show-off-entry-using-net-code-injection-to-do-the-seemingly-impossible/feed/</wfw:commentRss>
<enclosure url="http://damianblog.com/DamianMehersPDC2008ShowOff.wmv" length="3426853" type="video/x-ms-wmv" />
		</item>
		<item>
		<title>WCF REST Services: Setting the response format based on request&#8217;s expected type</title>
		<link>http://damianblog.com/2008/10/31/wcf-rest-dynamic-response/</link>
		<comments>http://damianblog.com/2008/10/31/wcf-rest-dynamic-response/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 06:42:27 +0000</pubDate>
		<dc:creator>dmehers</dc:creator>
		
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://damianblog.com/2008/10/31/wcf-rest-dynamic-response/</guid>
		<description><![CDATA[I just attended the Microsoft PDC in LA.&#160; One of the many excellent sessions was a pre-conference on WCF, part of which was presented by Ron Jacobs. Ron did a fantastic job of explaining WCF REST Services and the WCF REST Starter Kit.
One of the examples he showed from the WCF REST Starter kit was [...]]]></description>
			<content:encoded><![CDATA[<p>I just attended the Microsoft PDC in LA.&#160; One of the many excellent sessions was a pre-conference on WCF, part of which was presented by <a href="http://blogs.msdn.com/rjacobs/">Ron Jacobs</a>. Ron did a fantastic job of explaining WCF REST Services and the WCF REST Starter Kit.</p>
<p>One of the examples he showed from the WCF REST Starter kit was an example where the response type (JSON or XML) is dynamically set based on the HTTP request&#8217;s requested content type in the &quot;Accepts&quot; HTTP Header.</p>
<p>That example works by switching between two different operation implementations (methods).</p>
<p>I liked the idea of using the requested content type to automatically return JSON or XML depending on the requested content type, but I wasn&#8217;t so keen on having to implement two methods.</p>
<p>I thought I&#8217;d try to get a similar thing working but using a <strong>single operation implementation</strong> which is called no matter whether or JSON or XML are requested.</p>
<h3>The DynamicResponseType attribute</h3>
<p>This is how it works.&#160; You decorate your method with an additional DynamicResponseType attribute which I have defined:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2000px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; 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">
<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: white; border-bottom-style: none"><span style="color: #606060">   1:</span> [ServiceContract]</pre>
<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: #606060">   2:</span> [ServiceBehavior(IncludeExceptionDetailInFaults = <span style="color: #0000ff">true</span>, InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   3:</span> [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]</pre>
<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: #606060">   4:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Service1</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   5:</span> {</pre>
<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: #606060">   6:</span>     [OperationContract]</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     [WebGet(UriTemplate = <span style="color: #006080">&quot;GetData?param1={i}&amp;param2={s}&quot;</span>)]</pre>
<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: #606060">   8:</span>     <em>[DynamicResponseType]</em></pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     <span style="color: #0000ff">public</span> SampleResponseBody GetData(<span style="color: #0000ff">int</span> i, <span style="color: #0000ff">string</span> s)</pre>
<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: #606060">  10:</span>     {</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  11:</span>         <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> SampleResponseBody() { </pre>
<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: #606060">  12:</span>             Name = <span style="color: #006080">&quot;Test&quot;</span>,</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  13:</span>             Value = s, </pre>
<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: #606060">  14:</span>             Time = DateTime.Now.ToShortTimeString() </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  15:</span>         };</pre>
<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: #606060">  16:</span>     }</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  17:</span> }</pre>
<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: #606060">  18:</span>&#160; </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  19:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> SampleResponseBody</pre>
<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: #606060">  20:</span> {</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  21:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Name { get; set; }</pre>
<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: #606060">  22:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Value { get; set; }</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  23:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> IntValue { get; set; }</pre>
<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: #606060">  24:</span>     <span style="color: #0000ff">public</span> <span style="color: #0000ff">string</span> Time { get; set; }</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  25:</span> }</pre>
</p></div>
</div>
<h3>An example client</h3>
<p>Then when the client requests a specific type (XML or JSON), it is served automatically.</p>
<p>Below I have a pure HTML/Javascript client with two buttons, each of which call the same&#160; GetWebRequest function when they are clicked but passing a different requested content type as a parameter.&#160; The GetWebRequest function issues an HTTP request to the WCF operation I showed above.</p>
<p>The first button says it wants JSON, and the second XML.&#160; This is done by setting the &quot;Accept&quot; request header:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2000px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; 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">
<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: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span></pre>
<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: #606060">   2:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">form</span> <span style="color: #ff0000">id</span><span style="color: #0000ff">=&quot;form1&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span><span style="color: #0000ff">&gt;</span></pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">div</span><span style="color: #0000ff">&gt;</span></pre>
<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: #606060">   4:</span>     </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">input</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;button&quot;</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;Click to request JSON&quot;</span> </pre>
<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: #606060">   6:</span>         <span style="color: #ff0000">onclick</span><span style="color: #0000ff">=&quot;GetWebRequest('application/json');&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     </pre>
<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: #606060">   8:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">input</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;button&quot;</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">=&quot;Click to request XML&quot;</span> </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   9:</span>         <span style="color: #ff0000">onclick</span><span style="color: #0000ff">=&quot;GetWebRequest('application/xml');&quot;</span> <span style="color: #0000ff">/&gt;</span></pre>
<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: #606060">  10:</span>     </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  11:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">div</span><span style="color: #0000ff">&gt;</span></pre>
<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: #606060">  12:</span>     <span style="color: #0000ff">&lt;</span><span style="color: #800000">asp:ScriptManager</span> <span style="color: #ff0000">ID</span><span style="color: #0000ff">=&quot;ScriptManager1&quot;</span> <span style="color: #ff0000">runat</span><span style="color: #0000ff">=&quot;server&quot;</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">asp:ScriptManager</span><span style="color: #0000ff">&gt;</span></pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  13:</span>     <span style="color: #0000ff">&lt;/</span><span style="color: #800000">form</span><span style="color: #0000ff">&gt;</span></pre>
<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: #606060">  14:</span>&#160; </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  15:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">script</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">=&quot;text/javascript&quot;</span><span style="color: #0000ff">&gt;</span>
<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: white; border-bottom-style: none"><span style="color: #606060">   1:</span>&#160; </pre>
<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: #606060">   2:</span>   <span style="color: #0000ff">function</span> GetWebRequest(acceptType) {  </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     <span style="color: #0000ff">var</span> wRequest = <span style="color: #0000ff">new</span> Sys.Net.WebRequest();</pre>
<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: #606060">   4:</span>     <em>wRequest.get_headers()[<span style="color: #006080">&quot;Accept&quot;</span>] = acceptType;</em></pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     <span style="color: #0000ff">var</span> url = <span style="color: #006080">&quot;/Service1.svc/GetData?param1=12&amp;param2=&quot;</span>;</pre>
<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: #606060">   6:</span>     wRequest.set_url(url + <span style="color: #0000ff">new</span> Date());</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   7:</span>     wRequest.set_httpVerb(<span style="color: #006080">&quot;GET&quot;</span>);</pre>
<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: #606060">   8:</span>     wRequest.add_completed(OnWebRequestCompleted);</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   9:</span>     wRequest.invoke();</pre>
<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: #606060">  10:</span>   }</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  11:</span>&#160; </pre>
<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: #606060">  12:</span>   <span style="color: #0000ff">function</span> OnWebRequestCompleted(executor, eventArgs) {</pre>
<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: white; border-bottom-style: none"><span style="color: #606060">  13:</span>     alert(executor.get_responseData());</pre>
<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: #606060">  14:</span>   }</pre>
<p><span style="color: #0000ff">&lt;/</span><span style="color: #800000">script</span><span style="color: #0000ff">&gt;</span></pre>
<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: #606060">  16:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span></pre>
</p></div>
</div>
<p>This is the form that gets displayed initially:</p>
<p><a href="http://damianblog.com/wp-content/uploads/2008/10/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="202" alt="image" src="http://damianblog.com/wp-content/uploads/2008/10/image-thumb.png" width="651" border="0" /></a></p>
<p>When you click on the first button we request JSON from the WCF Service operation: </p>
<p><a href="http://damianblog.com/wp-content/uploads/2008/10/image1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="163" alt="image" src="http://damianblog.com/wp-content/uploads/2008/10/image-thumb1.png" width="470" border="0" /></a></p>
<p>When you click on the second button we request XML <strong>from the same WCF Service operation</strong>: </p>
<p><a href="http://damianblog.com/wp-content/uploads/2008/10/image2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="221" alt="image" src="http://damianblog.com/wp-content/uploads/2008/10/image-thumb2.png" width="491" border="0" /></a> </p>
<h3>How it works.</h3>
<p>I&#8217;ve created my own&#160; WCF ServiceHostFactory which I wire up in the SVC file:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; 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">
<div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; 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">
<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: white; border-bottom-style: none"><span style="color: #606060">   1:</span> <span style="background-color: #ffff00">&lt;%@ ServiceHost Language=&quot;C#&quot; </pre>
<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: #606060">   2:</span>     Debug=&quot;true&quot; </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     Service=&quot;WcfService2.Service1&quot; </pre>
<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: #606060">   4:</span>     CodeBehind=&quot;Service1.svc.cs&quot; </pre>
<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: white; border-bottom-style: none"><span style="color: #606060">   5:</span>     Factory=&quot;DamianBlog.ServiceHostFactory2Ex&quot; %&gt;</span></pre>
</p></div>
</div>
<p align="left">In my ServiceHostFactory2Ex class I ensure that my own WebServiceHost class gets created.</p>
<p align="left">Then in my own WebServiceHost I ensure that my own WebHttpBehavior replaces the standard one.</p>
<p align="left">Next in my own WebHttpBehavior I override the GetReplyDispatchFormatter method and return my own IDispatchMessageFormatter.</p>
<p align="left">In my own IDispatchMessageFormatter I implement the SerializeReply method and then use a JSON formatter or XML formatter depending on the &quot;Accepts&quot; HTTP request header which I pick up from the OperationContext.Current.RequestContext.RequestMessage.</p>
<p align="left">The full source is available for download here <a href="http://damianblog.com/WCFDynamicResponseDemo.zip">http://damianblog.com/WCFDynamicResponseDemo.zip</a>. </p>
<p align="left">Rob Jacobs blogs at <a href="http://blogs.msdn.com/rjacobs/">http://blogs.msdn.com/rjacobs/</a></p>
<p align="left">
]]></content:encoded>
			<wfw:commentRss>http://damianblog.com/2008/10/31/wcf-rest-dynamic-response/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
