C# 在 IIS 中托管 WCF 服务时协议映射错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13123861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 01:39:55  来源:igfitidea点击:

Error in Protocol Mapping While hosting a WCF service in IIS

c#wcfweb-servicesiiswcf-binding

提问by Amr Ramadan

I developed a simple WCF service with VS 2010. And i hosted in the default website in IIS by Adding Application and set the Physical Path

我使用 VS 2010 开发了一个简单的 WCF 服务。我通过添加应用程序并设置物理路径托管在 IIS 的默认网站中

And i tried to browse the .svc file it gives me the following error:

我试图浏览 .svc 文件,它给了我以下错误:

"The configuration section 'protocolMapping' cannot be read because it is missing a section declaration"

"配置节 'protocolMapping' 无法读取,因为它缺少节声明"

Protocol Mapping Error

协议映射错误

and I tried many solutions but it doesn't work

我尝试了很多解决方案但它不起作用

I Created WCF Service Library has an App.config with this:

我创建的 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>

and i Hosted the WCF Service Library application in WCF website (My Client) has an Web.config with this:

并且我在 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>

采纳答案by Iain

Amr,

阿姆,

This sounds like you may have permission issues in the folder you .svc is running from, please can you check and see if the following permissions are there:

这听起来您在运行 .svc 的文件夹中可能存在权限问题,请您检查并查看是否存在以下权限:

  • \IIS_IUSERS
  • \IIS_IUSR ---If running webservice in Anonymous Mode
  • \IIS_IUSERS
  • \IIS_IUSR ---如果在匿名模式下运行 web 服务

For the issue with protocol Mapping, please ensure that the app Pool you are using for the IIS site is setup to use .net 4, as from what I understand protocol mapping is only available in .net 4.

对于协议映射问题,请确保您用于 IIS 站点的应用程序池设置为使用 .net 4,因为据我所知,协议映射仅在 .net 4 中可用。

Hope this helps

希望这可以帮助

回答by Valerie

I had the same issue, but finally figured out that you have to set the DEFAULT application pool to .Net 4.0, not just the Application Pool for the individual website.

我遇到了同样的问题,但最终发现您必须将 DEFAULT 应用程序池设置为 .Net 4.0,而不仅仅是单个网站的应用程序池。

回答by Ravin singh D

I have face the same issue. By changing application pool .net framework from 2.0 to 4.o was solved my problem

我遇到了同样的问题。通过将应用程序池 .net 框架从 2.0 更改为 4.o 解决了我的问题

回答by Jaydeep Shil

For the issue with protocol Mapping, please ensure that the app Pool you are using for the IIS site is setup to use .net 4.

对于协议映射问题,请确保您用于 IIS 站点的应用程序池设置为使用 .net 4。

enter image description here

在此处输入图片说明

回答by Hamid Noahdi

.enter image description here

.在此处输入图片说明

I also had the same issue, but finally I could solve it by turning some windows features on.

我也有同样的问题,但最后我可以通过打开一些 Windows 功能来解决它​​。