在 IIS 中托管 WCF 服务时协议映射错误
Posted
技术标签:
【中文标题】在 IIS 中托管 WCF 服务时协议映射错误【英文标题】:Error in Protocol Mapping While hosting a WCF service in IIS 【发布时间】:2012-10-18 21:34:59 【问题描述】:我用 VS 2010 开发了一个简单的 WCF 服务。我通过添加应用程序托管在 IIS 的默认网站中并设置物理路径
我试图浏览 .svc 文件,它给了我以下错误:
"无法读取配置节 'protocolMapping',因为它缺少节声明"
我尝试了很多解决方案,但都不起作用
我创建的 WCF 服务库有一个 App.config,其中包含:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="EvalServiceLibrary.EvalService">
<clear />
<endpoint address="basic" binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="ws" binding="wsHttpBinding" contract="EvalServiceLibrary.IEvalService"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:8888/evalservice" binding="netTcpBinding"
contract="EvalServiceLibrary.IEvalService" listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="net.pipe://localhost/evalservice" binding="netNamedPipeBinding"
bindingConfiguration="" contract="EvalServiceLibrary.IEvalService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/evalservice" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我在 WCF 网站(我的客户端)中托管的 WCF 服务库应用程序有一个 Web.config,其中包含:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="EvalServiceLibrary.EvalService">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="" contract="EvalServiceLibrary.IEvalService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="" contract="EvalServiceLibrary.IEvalService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
【问题讨论】:
【参考方案1】:Amr,
听起来您运行 .svc 的文件夹可能存在权限问题,请您检查一下是否存在以下权限:
\IIS_IUSERS \IIS_IUSR ---如果在匿名模式下运行 web 服务对于协议映射问题,请确保您用于 IIS 站点的应用程序池设置为使用 .net 4,据我了解,协议映射仅在 .net 4 中可用。
希望对你有帮助
【讨论】:
权限问题已解决。但现在我正在尝试解决协议映射错误 对我来说,不需要添加额外的权限——只需按照您的指示修复应用程序池就足以解决问题。谢谢。 @AmrRamadan 关于Protocol Mapping error
的任何最终解决方案?【参考方案2】:
我遇到了同样的问题,但最后发现您必须将默认应用程序池设置为 .Net 4.0,而不仅仅是单个网站的应用程序池。
【讨论】:
【参考方案3】:对于协议映射问题,请确保您用于 IIS 站点的应用程序池设置为使用 .net 4。
【讨论】:
【参考方案4】:我也遇到过同样的问题。通过将应用程序池 .net 框架从 2.0 更改为 4.o 解决了我的问题
【讨论】:
【参考方案5】:.
我也遇到了同样的问题,但最后我可以通过打开一些 Windows 功能来解决它。
【讨论】:
【参考方案6】:<configSections>
<sectionGroup name="system.serviceModel" type="System.ServiceModel.Configuration.ServiceModelSectionGroup, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="protocolMapping" type="System.ServiceModel.Configuration.ProtocolMappingSection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
添加到 web.config 文件为我解决了
【讨论】:
以上是关于在 IIS 中托管 WCF 服务时协议映射错误的主要内容,如果未能解决你的问题,请参考以下文章
如何在 IIS 中正确托管连接到 SQLServer 的 WCF 数据服务?为啥我会收到错误消息?
Fileless Restful WCF 在本地 IIS7 中托管时无法正常工作,但可以在本地运行