c# - WCF 在服务实现的契约(Contract)列表中找不到契约(Contract)名称 'IMetadataExchange'

标签 c# asp.net web-services wcf endpoint

我一直在使用网络服务,它工作得很好,然后我添加了 App.config 和 Web.config 的行为部分中的属性,它崩溃了 错误是*

WCF The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service


,在下面你可以找到我的服务库的 App.config 的 xml 代码。在它下面你可以找到我的网站的 web.config 文件的 xml 代码提前感谢你的帮助:) 我的库的 App.config

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </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="FluoraPinServiceLibrary.Service1">
        <endpoint address="" binding="basicHttpBinding" contract="FluoraPinServiceLibrary.IFluoraPinServices">
          <identity>
            <dns value="192.168.1.3" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.1.3:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->

          <!-- 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="true"/>
        </behavior>
        <behavior name="Throttled">
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->

          <!-- 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="true" />
          <serviceThrottling
        maxConcurrentCalls="4"
        maxConcurrentSessions="4"
        maxConcurrentInstances="4"
          />
          <serviceMetadata
            httpGetEnabled="true"
            httpGetUrl=""
          />


        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

</configuration>

这就是我的 Web.config 文件的代码

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="false" targetFramework="4.5.1" />
    <httpRuntime enableVersionHeader="false" executionTimeout="72000" maxRequestLength="4096" minFreeThreads="72" minLocalRequestFreeThreads="88" useFullyQualifiedRedirectUrl="false" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->

          <!-- 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="true"/>
        </behavior>
      <behavior  name="Throttled">
          <serviceThrottling 
            maxConcurrentCalls="4" 
            maxConcurrentSessions="4" 
            maxConcurrentInstances="4"
          />
          <serviceMetadata 
            httpGetEnabled="true" 
            httpGetUrl=""
          />
        </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>

最佳答案

您的默认行为只有 serviceDebug 标记。您需要添加 serviceMetadata 标签。

    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->

      <!-- 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="true"/>
      <serviceMetadata/>
    </behavior>

您可以找到详细信息here

关于c# - WCF 在服务实现的契约(Contract)列表中找不到契约(Contract)名称 'IMetadataExchange',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22757674/

相关文章:

c# - 如何在同一行上左右对齐两个段落?

c# - 无法加载文件或程序集 'System.IO, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一

asp.net - ASP.NET 应用程序中什么消耗了超过 65% 的时间?

android - 从 JSON Web 服务加载数据并将其显示在 ListView 中

web-services - 使用 JWT 处理过期/"remember me"功能

c# - 将项目添加到通用列表时为 "Index was outside the bounds of the array"

c# - 在 C# 中,是否有一种巧妙的方法来切换由逗号分隔的字符串的两个部分?

c# - 使用 JavaScript 查找具有多个 ASP UserControl 的 ID

c# - 简单登录 C# 和 MySQL Web 应用程序

c# - @ 作为 C# 中成员名称的一部分的目的是什么?