Thursday, May 26, 2011

Setting up WCF REST Template with .NET 4.0 as a Virtual Directory in IIS6

  • Ensure the ServiceRoute name in Global.asax ends with .svc (or anything except extentionless that is mapped to C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll)
  • Ensure .NET 4.0 app pool exists (or create one called AppPoolNET4)
  • Create new Virtual Directory under the website in IIS6
    • Switch to use AppPoolNET4
    • Change ASP.NET version to 4.0 (restart IIS reqd)
  • Web.config stuff:
    • Look after your old IIS6 modules under <system.web> since <system.webServer> is ignored:

<httpModules>
<clear/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
   </httpModules>

  • May need to clear handlers and other sections e.g. <httpHandlers><clear/></httpHandlers>
  • Ensure you have aspNetCompatibilityEnabled="true" like so: 

<system.serviceModel><serviceHostingEnvironment aspNetCompatibilityEnabled="true" />...

  • Spec a shiney new 4.0 compiler too:

<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider,System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v4.0"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>

Debug output from WCF 4.0 REST Template

To view exception details for WCF v4.0 REST Template (instead of the generic "Response Error" message) add faultExceptionEnabled="true" to <standardEndpoint>:

<system.serviceModel>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" faultExceptionEnabled="true">
...

Additionally, add includeExceptionDetailInFaults="true" to <system.serviceModel> for stack trace etc:

<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>

Also see::
http://stackoverflow.com/questions/2312894/wcf-data-service-how-to-diagnose-request-error

Ah, nice to get the WCF v4.0 REST template working under IIS6!