【发布时间】:2011-01-25 11:48:17
【问题描述】:
我正在 .net 4 上的 WCF 中测试 REST 服务 - 即没有 svc 文件。在 VS 开发服务器上运行时效果很好,但是当我将其切换到 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)]
public class DataPortalService : IDataPortalService
{
[WebGet(UriTemplate = "Test/TestMethod")]
public string TestMethod()
{
return "Hi!";
}
}
[ServiceContract]
public interface IDataPortalService
{
[OperationContract]
string TestMethod();
}
和配置文件
<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>
点击 /help 页面或方法会给我一个 404.0.
我想我只是缺少 IIS 中的一些设置来启动它,尽管它在开发服务器上运行良好但在 IIS 上运行良好有点愚蠢。
【问题讨论】:
-
您获得的是 HTTP 404.4 吗?如果是这样,请检查您的处理程序映射是否正确。
-
不 - 它是 404.0。鉴于在这种情况下没有 svc 文件,哪些映射会接收请求?