404在IIS上运行.net 4 WCF服务时(无svc文件)

Chr*_*s W 22 iis rest wcf

我正在测试.net 4上的WCF中的REST服务 - 即没有svc文件.它在VS dev服务器上运行时效果很好,但当我将其切换为针对IIS运行时,我在尝试浏览帮助页面或点击任何服务方法时得到404.

我已经退回到一个简单的骨头服务,只是让它在IIS上运行,但我不确定它有什么问题.

global.asax只是有

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

而服务本身就像它得到的一样简单:

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

[ServiceContract]
public interface IDataPortalService
{
    [OperationContract]
    string TestMethod();
}
Run Code Online (Sandbox Code Playgroud)

和配置文件

<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>
Run Code Online (Sandbox Code Playgroud)

点击/帮助页面或方法给我一个404.0.

我认为我只是错过了IIS中的一些设置以使其生动起来,尽管它在开发服务器上工作正常但不是IIS有点愚蠢.

Chr*_*s W 29

在围绕其他论坛进行挖掘后解决了这个问题.

我最初将以下内容添加到我的Web配置中:

<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>
Run Code Online (Sandbox Code Playgroud)

显然,默认情况下,IIS不知道如何处理无扩展请求并将它们传递给静态文件处理程序.

鉴于MVC使用相同的例程架构,我认为基本的MVC站点模板必须具有类似于上面的一些配置,因为我的MVC站点在移动到IIS时工作正常.

事实证明,他们的配置略有不同,而是有以下条目:

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
Run Code Online (Sandbox Code Playgroud)

这两个配置似乎都运行正常,但在这种情况下我决定使用第二个选项.

  • *如果您还没有应用此修补程序http://support.microsoft.com/kb/980368,则需要runAllManagedModulesForAllRequests ="true"*.点击此处了解更多信息http://blogs.msdn.com/b/tmarq/archive/2010/04/01/asp-net-4-0-enables-routing-of-extensionless-urls-without-impacting-static -requests.aspx (2认同)

mur*_*uge 10

runAllManagedModulesForAllRequests="true"在我的web.config中但仍然无法通过404.0.还尝试安装"IIS 7推荐配置"没有任何运气.重新运行aspnet_regiis解决了我的问题.

  1. 在"运行"对话框中,键入cmd,然后单击"确定".

  2. 在命令提示符下,使用cd命令更改要使用的Aspnet_regiis.exe版本的目录.默认情况下,Aspnet_regiis.exe位于以下目录中:systemroot\Microsoft.NET\Framework\versionNumber

  3. 然后运行以下命令: aspnet_regiis -ir

这将在Handler Mappings中注册"svc-Integrated-4.0".