Register WCF for IIS

I encountered problems when testing this code example on a newly installed server (Windows Server 2012 R2):

Consuming a WCF Service from an SSRS (RDL) Server Report

 

I got this error:

HTTP_Error_404.17

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=3.0.0.0, 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:

Error message after you install the .NET Framework 4.0: “Could not load type ‘System.ServiceModel.Activation.HttpModule'”

By modifying the configuration file:

%windir%\system32\inetsrv\config\Applicationhost.config

With:

<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler,runtimeVersionv2.0" />

 

After this both the old (.NET 3.5) and newer (.NET 4.5+) sites were functional.