.svc WCF web service returns 404 Not Found on IIS 8

When a Windows Communications Foundation (WCF) web service returns a 404 Not Found error, after installing the HTTP-Activation feature in IIS, you might need to add an extra Handler to your IIS configuration.
Published on Monday, 30 June 2014

Configure .svc WCF handler in IIS

When the .svc web service handler doesn't work on IIS 8.0 with ASP.NET 4.5...

  • Request path: *.svc
  • Type: System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
  • Name: svc-Integrated-4.0
[TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]

If you have installed the NET-WCF-HTTP-Activation45 feature in IIS, and the *.svc handler is present in IIS, then you may need to edit your web.config file to let the Version=3.0.0.0 version of System.ServiceModel (System.ServiceModel.Activation.HttpModule) to be loaded only for runtimeVersionv2.0:

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

if your webservice displays the following Exception:

[TypeLoadException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
   System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +39
   System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +37
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +65
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +38

[ConfigurationErrorsException: Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +359
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, Boolean checkAptcaBit) +19
   System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement) +39
   System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) +42
   System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +160
   System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +950
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +82
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915300
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

In this post you learned how to configure an extra handler to your IIS configuration if to resolve 404 Not Found errors for .svc WCF web services in Windows Server IIS 8 after installing the HTTP-Activation feature in IIS.