404 when running .net 4 WCF service on IIS (no svc file)

I'm testing out a REST service in WCF on .net 4 - i.e. no svc file. It works great when running against the VS dev server but when I switch it to run against IIS I get 404s when trying to browse the help page or hit any of the service methods.

I've dropped back to a bare bones service to just get it running on IIS but I'm not sure what's wrong with it.

The global.asax simply has

    protected void Application_Start(object sender, EventArgs e)
    {
        RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(DataPortalService)));
    }

and the service itself is as simple as it gets:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DataPortalService : IDataPortalService
{
    [WebGet(UriTemplate = "Test/TestMethod")]
    public string TestMethod()
    {
        return "Hi!";
    }
}

[ServiceContract]
public interface IDataPortalService
{
    [OperationContract]
    string TestMethod();
}

and config file of

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" />
      </webHttpEndpoint>
    </standardEndpoints>
  </system.serviceModel>  

</configuration>

Hitting the /help page or the method gives me a 404.0.

I presume I'm just missing some setting in IIS to kick it in to life although it's a bit daft that it works fine on the dev server but not IIS.

Answers


Solved it after a dig around some other forums.

I initially added the following to my web config:

<system.webServer>
    <handlers>
        <remove name="svc-Integrated-4.0" />
        <add name="svc-Integrated-4.0" path="*" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
</system.webServer>

Clearly by default IIS doesn't know what to do with the extensionless requests and passed them on to the static file handler.

Given that MVC is using the same routine architecture I figured that the basic MVC site template must have some config in similar to the above since my MVC sites have worked fine when moved to IIS.

It turns out that they have a slightly different config and have the following entry instead:

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

Both configs seem to work ok but I settled on using the 2nd option in this case.


I had runAllManagedModulesForAllRequests="true" in my web.config but still couldn't get past the 404.0. Also tried installing "IIS 7 Recommended Configuration" without any luck. Rerunning aspnet_regiis solved the problem to me.

  1. In the Run dialog box, type cmd, and then click OK.

  2. At the command prompt, use the cd command to change the directory of the Aspnet_regiis.exe version you want to use. By default, Aspnet_regiis.exe is located in the following directory: systemroot\Microsoft.NET\Framework\versionNumber

  3. Then run the following command: aspnet_regiis -ir

This will register "svc-Integrated-4.0" in the Handler Mappings.


HTTP 404 code can be returned also if you don't have some components of .NET framework installed.

There's for instance Windows Communication Foundation HTTP Activation feature in .NET Framework 3.5 and in .NET Framework 4.6 there are HTTP Activation, Message Queuing (MSMQ) Activation and a few more.

In Windows 10 these features aren't installed by default, so please keep in mind to take a look at Windows Features.


On IIS 5.1 on my machine, the .svc page was served only when I added HTTP Handler at Web Site level as well as virtual folder level. This should ideally work by inheritance!

Extention : .svc

Executable :

c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll


Need Your Help

How to handle back button on Ionic 2

ionic2 back-button back-button-control

How can I handle the back button action on Ionic 2?

How to get and change URL variable PHP

php html hyperlink

Hi could anyone help me with this