Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 839
Chris W Avatar asked Jan 25 '11 11:01

Chris W


People also ask

How do I browse an SVC file in IIS?

Solution: Open IIS Manager (Start > Run > search "inetmgr"). Browse from the top level server to Sites and expand the Default Web Site. Select each of the Revit Server applications, and in the Content View, right click on the SVC file and select Browse.

Where is .SVC file in WCF?

.svc file in WXF:- asmx file in web services. In other words, WCF services hosted in IIS are represented as special content files (. svc files) inside the IIS application. This model is similar to the way ASMX pages are represented inside of an IIS application as .


2 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.

like image 125
Chris W Avatar answered Nov 18 '22 06:11

Chris W


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.

like image 27
muruge Avatar answered Nov 18 '22 05:11

muruge