2011-06-03 61 views
1

我在使用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。

請幫忙,因爲我很困惑這一點。

在此先感謝!

傑弗裏·凱文撬

回答

1

因爲似乎沒有人有興趣在這個問題:)我想通了我自己。

看來,我不得不做以下得到它的工作:

  1. 打開命令提示符(cmd.exe的)
  2. CD C:\ WINDOWS \ Microsoft.NET \ Framework64 \ v4.0.30319 \(將取決於安裝)
  3. 執行ASPNET_REGIIS.EXE -i

該訣竅。現在都在工作。希望我可以省下幾個小時左右的搜索結果。

感謝,

傑弗裏·凱文撬