404在IIS上运行.net 4 WCF服务时(无svc文件) [英] 404 when running .net 4 WCF service on IIS (no svc file)

查看:251
本文介绍了404在IIS上运行.net 4 WCF服务时(无svc文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试.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)));
}

并且服务本身就像它一样简单:

  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
公共类DataPortalService:IDataPortalService
{
[WebGet( UriTemplate =Test / TestMethod)]
public string TestMethod()
{
returnHi!;
}
}

[ServiceContract]
公共接口IDataPortalService
{
[OperationContract]
string TestMethod();
}

和配置文件

 <结构> 
< system.web>
< compilation debug =truetargetFramework =4.0/>
< /system.web>

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

< / configuration>

点击/ help页面或方法给我一个404.0。



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

解决方案

在搜索其他论坛后解决了这个问题。



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

 < system.webServer> 
< handlers>
< remove name =svc-Integrated-4.0/>
< add name =svc-Integrated-4.0path =*verb =*type =System.ServiceModel.Activation.ServiceHttpHandlerFactory,System.ServiceModel.Activation,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35resourceType =未指定requireAccess =ScriptpreCondition =integratedMode,runtimeVersionv4.0/>
< / handlers>
< /system.webServer>

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



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



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

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

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


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.

解决方案

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.

这篇关于404在IIS上运行.net 4 WCF服务时(无svc文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆