【发布时间】:2011-09-07 19:12:46
【问题描述】:
我在使用 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+"!");
}
我尝试将其发布到我在根站点 (http://localhost/) 下创建的 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 的应用程序池。
请帮忙,因为我对此感到非常困惑。
提前致谢!
杰弗里·凯文·普瑞
【问题讨论】: