WCF

1. 在服务 Transfer 实现的协定列表中找不到协定名称 "IMetadataExchange"

将 ServiceMetadataBehavior 添加到配置文件或直接添加到 ServiceHost,以启用对该协定的支持

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="exposeExceptionDetail">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_ITransfer">
          <security mode="None"/>
        </binding>
      </netTcpBinding>
    </bindings>    
    <services>
      <service name="TestWcfScreen.Transfer"
               behaviorConfiguration="exposeExceptionDetail">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8733/Transfer/" />
          </baseAddresses>
        </host>
        <endpoint address="" 
                  binding="netTcpBinding" 
                  bindingConfiguration="NetTcpBinding_ITransfer"
                  contract="TestWcfScreen.ITransfer">
        </endpoint>
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

忘记添加 <serviceMetadata /> 这个标签

原文地址:https://www.cnblogs.com/luquanmingren/p/6911369.html