首先写了一个Service,然后编译一下,再在Debug文件夹中运行,然后在客户端的程序中添加服务引用,提示以下错误:元数据包含无法解析的引用:“net.tcp://localhost:5351/”。
没有终结点在侦听可以接受消息的 net.tcp://localhost:5351/。这通常是由于不正确的地址或者 SOAP 操作导致的。如果存在此情况,请参阅 InnerException 以了解详细信息。如果该服务已在当前解决方案中定义,请尝试生成该解决方案,然后再次添加服务引用。
我的服务端配置文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="WCFSample.CalculatorService" behaviorConfiguration="serbe">
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:5351" />
          </baseAddresses>
        </host>
        <endpoint address="net" binding="netTcpBinding" bindingConfiguration="bd" contract="WCFSample.ICalculator" />
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="bd">
        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serbe">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

解决方案 »

  1.   

    你服务器端的配置中没有添加Metadata Endpoint的Binding。这个Binding对于客户端添加引用是必须的,但是一旦添加以后,你可以去掉这个Binding。
      

  2.   

    你参考系统自动生成的config文件:  <system.serviceModel>
        <services>
          <service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
            <!-- Service Endpoints -->
            <endpoint address="" binding="wsHttpBinding" contract="WcfService1.IService1">
              <!-- 
                  Upon deployment, the following identity element should be removed or replaced to reflect the 
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
                  automatically.
              -->
              <identity>
                <dns value="localhost"/>
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="WcfService1.Service1Behavior">
              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
              <serviceMetadata httpGetEnabled="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>
    其中:
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    这一行就是添加metadata endpoint的。你可以参考,当然,也要记得相应的配置behavior。之后启动服务,成功以后,再在客户端添加服务引用。
      

  3.   

    谢谢acqy ,按照你的方法问题解决。
      

  4.   

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      

  5.   

    TCP呢 ?   那个只是Http的