2010-09-23 26 views
3

我使用的是VS2010 + C#+ .Net 4.0 + IIS 7.5 + Windows 7.當我打開IIS中的WCF項目的svc文件(在IIS管理器中,右鍵單擊svc文件並選擇瀏覽)時,出現錯誤像這樣,任何想法有什麼不對?禁止瀏覽WCF svc文件?

This type of page is not served. 
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.svc' may be incorrect. Please review the URL below and make sure that it is spelled correctly. 

這是我使用的web.config文件的內容,它是正確的嗎?

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
     <staticContent> 
      <remove fileExtension=".svc" /> 
     </staticContent> 
     <handlers> 
      <remove name="svc-ISAPI-2.0" /> 
      <remove name="svc-Integrated" /> 
      <add name="svc-ISAPI-2.0" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" /> 
     </handlers> 
    </system.webServer> 
</configuration> 

回答

2

您可能必須在Visual Studio命令提示符下啓動命令servicemodelreg –ia

如果不起作用,請檢查是否安裝了「WCF http激活」功能(添加/刪除程序 - 打開或關閉Windows功能 - Microsoft .Net 3.5.1)。

更新1:可能您的應用程序託管在.NET 2.0應用程序池中。轉到IIS管理器並檢查基本設置...鏈接。點擊選擇按鈕,你會看到你使用哪個選項。更改爲使用.NET 4.0

更新2:您的web.config文件似乎不完整。我建議你使用WCF Configuration Editor工具來配置你的服務。啓動它(確保你使用的是.NET 4版本的工具)並打開你的web.config文件。創建服務配置和服務端點配置,然後保存它。

+0

謝謝!我應該在C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319下運行servicemodelreg?或者在C:\ Windows \ Microsoft.NET \ Framework \ v3.0 \ Windows Communication Foundation下? – George2 2010-09-24 02:48:18

+0

我試過你的解決方案,但遇到了一個新問題=> http://stackoverflow.com/questions/3776493/loading-error-for-system-servicemodel-activation-httpmodule我很困惑爲什麼加載3.0服務時出錯模型錯誤。我的代碼是爲.NET 4.0構建的。 – George2 2010-09-24 03:24:00

+0

我也懷疑web.config是不正確的。我已發佈web.config我原來的帖子,任何想法? – George2 2010-09-24 03:32:49

1

它可能是MIME類型在IIS上沒有正確設置,請嘗試使用aspnet_regiis工具。否則,我建議在iis中的虛擬目錄中添加一個mimetype以處理由.NET運行時處理的.svc文件。

+0

謝謝!我應該使用什麼選項運行aspnet_regiis?我應該在.Net 4.0下運行aspnet_regiis,對嗎? – George2 2010-09-24 02:49:41

+0

我試過你的解決方案,但遇到了一個新問題=> http://stackoverflow.com/questions/3776493/loading-error-for-system-servicemodel-activation-httpmodule我很困惑爲什麼加載3.0服務時出錯模型錯誤。我的代碼是爲.NET 4.0構建的。 – George2 2010-09-24 03:24:26

+0

我也懷疑web.config是不正確的。我已發佈web.config我原來的帖子,任何想法? – George2 2010-09-24 03:32:25