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

后端 未结 4 1038
孤街浪徒
孤街浪徒 2020-12-08 08:13

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 40

相关标签:
4条回答
  • 2020-12-08 08:49

    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.

    0 讨论(0)
  • 2020-12-08 08:50

    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.

    0 讨论(0)
  • 2020-12-08 08:54

    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.

    0 讨论(0)
  • 2020-12-08 08:58

    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

    0 讨论(0)
提交回复
热议问题