在为IIS 7.5配置WCF REST服务时,无法映射路径
本文关键字:路径 映射 服务 REST IIS 配置 WCF 在为 | 更新日期: 2023-09-27 17:58:23
我在使用IIS 7.5构建和部署WCF Rest服务时遇到问题。如果我打开Visual Studio 2010并创建一个类型为"WCF服务应用程序"的新项目,然后将其发布到IIS,则工作正常。但是,当我尝试从IService.cs接口在操作约定上指定WebGet属性时,我会遇到错误。
接口(来自IService.cs):
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet(UriTemplate = "hello/?n={name}")]
Message SayHello(string name);
}
对应方法(来自Service.svc):
public Message SayHello(string name) {
return Message.CreateMessage(MessageVersion.None, "*", "Hello "+name+"!");
}
我尝试将其发布到我创建的IIS应用程序(http://localhost/rest/)在我的根网站下(http://localhost/)并且发布成功,但是当我试图从浏览器访问任何页面时,我会收到以下错误:
Failed to map the path '/rest'.
我还尝试将UriTemplate更改为[WebGet(UriTemplate = "rest/hello/?n={name}")]
,结果也出现了同样的错误。
我正在使用IIS的默认配置文件:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
我还应该提到,我正在使用.NET 4.0的应用程序池。
请帮忙,因为我对此感到非常困惑。
提前感谢!
Jeffrey Kevin Pry
因为似乎没有人对这个问题感兴趣:)我自己想出来了。
似乎我必须做以下几件事才能让它发挥作用:
- 打开命令提示符(cmd.exe)
- cd C:''Windows''Microsoft.NET''Framework64''v4.0.30119''(根据安装程序的不同而有所不同)
- 执行aspnet_regiis.exe-i
成功了。现在一切都正常了。希望我能为某人节省几个小时左右的谷歌搜索时间。
谢谢,
Jeffrey Kevin Pry