I encountered problems when testing this code example on a newly installed server (Windows Server 2012 R2):
I got this error:
HTTP Error 404.17 - Not Found The requested content appears to be script and will not be served by the static file handler. Most likely causes: The request matched a wildcard mime map. The request is mapped to the static file handler. If there were different pre-conditions, the request will map to a different handler.
Relevant Windows features were already installed.
Resolved the problem by running this in a command prompt:
cd "C:\Windows\Microsoft.NET\Framework64\v3.0\Windows Communication Foundation" ServiceModelReg.exe –i
However this was not an ideal solution, because it broke newer sites with:
System.TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
Tried fixing it by running:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319> aspnet_regiis.exe -iru
Unfortunately that failed with:
This option is not supported on this version of the operating system. Administrators should instead install/uninstall ASP.NET 4.5 with IIS8 using the "Turn Windows Features On/Off" dialog, the Server Manager management tool, or the dism.exe command line tool. For more details please see http://go.microsoft.com/fwlink/?LinkID=216771.
Eventually I found the solution here: WCF on IIS8; *.svc handler mapping doesn’t work
Resolved the problem by running:
dism /Online /Disable-Feature /Featurename:IIS-ASPNET45 dism /Online /Enable-Feature /Featurename:IIS-ASPNET45 /all dism /Online /Enable-Feature /FeatureName:WCF-HTTP-Activation dism /Online /Enable-Feature /FeatureName:WCF-HTTP-Activation45
Also had to follow the advice from the Microsoft article:
By modifying the configuration file:
<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler,runtimeVersionv2.0" />
After this both the old (.NET 3.5) and newer (.NET 4.5+) sites were functional.