我在使用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的应用程序池。
请帮忙,因为我对此感到非常困惑。
提前致谢!
Jeffrey Kevin Pry
答案 0 :(得分:1)
由于似乎没有人对这个问题感兴趣:)我自己想出来了。
似乎我必须执行以下操作才能使其正常工作:
这就是诀窍。现在一切正常。希望我可以在谷歌搜索几个小时左右。
谢谢,
Jeffrey Kevin Pry