未能映射为IIS 7.5配置WCF REST服务的路径配置
问题描述:
我在使用IIS 7.5构建和部署WCF Rest服务时遇到问题。如果我打开Visual Studio 2010并创建一个类型为“WCF服务应用程序”的新项目,然后将其发布到IIS,它可以正常工作。但是,当我尝试从IService.cs接口指定操作合同上的WebGet属性时,我收到错误消息。未能映射为IIS 7.5配置WCF REST服务的路径配置
接口(从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 /)并且发布成功,但是当我尝试从浏览器访问任何页面时,出现以下错误:
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。
请帮忙,因为我很困惑这一点。
在此先感谢!
杰弗里·凯文撬
答
因为似乎没有人有兴趣在这个问题:)我想通了我自己。
看来,我不得不做以下得到它的工作:
- 打开命令提示符(cmd.exe的)
- CD C:\ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319 \(将取决于安装)
- 执行ASPNET_REGIIS.EXE -i
该诀窍。现在都在工作。希望我可以省下几个小时左右的搜索结果。
感谢,
杰弗里·凯文撬