禁止浏览WCF svc文件?

时间:2010-09-23 15:38:34

标签: c# .net wcf visual-studio-2010 iis-7

我正在使用VS2010 + C#+。Net 4.0 + IIS 7.5 + Windows 7.当我在IIS中打开一个svc文件(在IIS管理器中,右键单击svc文件并选择浏览)时,有一个WCF项目像这样的错误,任何想法有什么不对?

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 个答案:

答案 0 :(得分:2)

您可能必须在Visual Studio命令提示符中启动命令servicemodelreg –ia

如果它不起作用,请检查您是否安装了“WCF http激活”功能(添加/删除程序 - 打开或关闭Windows功能 - Microsoft .Net 3.5.1)。

更新1:可能您的应用程序托管在.NET 2.0 App Pool下。转到IIS管理器并检查基本设置...链接。单击“选择”按钮,您将看到您正在使用哪个选项。将其更改为使用.NET 4.0

更新2:您的web.config文件似乎不完整。我建议您使用WCF Configuration Editor工具配置服务。启动它(确保您使用的是该工具的.NET 4版本)并打开您的web.config文件。创建服务配置和服务端点配置,然后保存。

答案 1 :(得分:1)

可能在IIS上没有正确设置mime类型,请尝试使用aspnet_regiis工具。如果做不到这一点,我建议在iis中为你的虚拟目录添加一个mimetype,以便.NET运行时处理.svc文件。

相关问题