【问题标题】:Failed to map path whem configuring WCF REST service for IIS 7.5无法映射路径 whem 为 IIS 7.5 配置 WCF REST 服务
【发布时间】: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 的应用程序池。

请帮忙,因为我对此感到非常困惑。

提前致谢!

杰弗里·凯文·普瑞

【问题讨论】:

    标签: c# .net wcf iis


    【解决方案1】:

    因为似乎没有人对这个问题感兴趣 :) 我自己想通了。

    看来我必须执行以下操作才能使其正常工作:

    1. 打开命令提示符 (cmd.exe)
    2. cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319\(会因设置而异)
    3. 执行 aspnet_regiis.exe -i

    成功了。现在一切正常。希望我可以为某人节省几个小时左右的 Google 搜索时间。

    谢谢,

    杰弗里·凯文·普瑞

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 2013-01-21
      相关资源
      最近更新 更多