我在使用IIS 7.5构建和部署WCF Rest服务时遇到了问题。如果我打开Visual Studio2010并创建一个"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
发布于 2011-06-17 18:54:22
因为似乎没有人对这个问题感兴趣:)我自己想出来的。
为了让它正常工作,我似乎必须执行以下操作:
这就起到了作用。现在一切都正常了。希望我能节省一些人几个小时的谷歌搜索时间。
谢谢,
Jeffrey Kevin Pry
https://stackoverflow.com/questions/6227129
复制相似问题