首页 > 技术文章 > WCF IIS 部署错误处理

mahongbiao 原文

做Web接口,原来一直用Web Service的,但是.Net 3.5后,Web Service变成了WCF。代码的编写上,把WebMethod特性改成了OperationContract,然后把方法分拆到契约接口和实现方法。然后在部署上,不再依赖于IIS,但如果使用IIS,部署反倒麻烦了。

将WCF应用程序代码拷贝到IIS目录下,然后打开IIS管理器,将其转换为Application。访问时出现了错误。protocolMapping配置节有问题。

原因在于,WCF是.Net3.5?的东西,我创建的WCF应用是.Net4.5,而转换为的Application,使用默认的应用程序池,其使用的.net框架为2.0。因此2.0无法解析protocolMapping配置节。

针对此情况,新建4.0的应用程序池(管道模式要使用集成,不可以是经典模式),因为服务器是2008R2,所以IIS是7.5,所以.Net框架是4.0,所以把WCF应用更改为4.0,然后重新编译,然后修改应用程序池。

然后访问报以下错误。网上查找答案,有部署SilverLight遇到类似的问题。但是配置目录权限(给IISUser甚至是匿名用户添加了FullControl的权限)后,仍然没有效果。

This error can be caused by a virtual directory not being configured as an application in IIS.

后来睁大眼睛,终于看到了这一句,哎,其实人家提醒的明明白白,为什么自己这么糊涂。问题在于虚拟目录(可以理解为应用程序所在目录)没有被配置为应用程序。

我创建了一个解决方案,其中包含几个类库以及WCF服务,后来将解决方案目录转换为应用程序,然后浏览,然后找到了服务,点击报错,问题在于WCF服务项目的目录没有被转换,正确的是转换WCF服务。

Server Error in '/xxx' Application. --------------------------------------------------------------------------------

Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.  This error can be caused by a virtual directory not being configured as an application in IIS.

Source Error:

Line 20:       <add binding="basicHttpsBinding" scheme="https"/> Line 21:     </protocolMapping> Line 22:     <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/> Line 23:   </system.serviceModel> Line 24:   <system.webServer>

Source File: C:inetpubwwwrootxxxillion.wcfweb.config    Line: 22

-------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

推荐阅读