在 WCF 的添加服务引用中找不到 net.tcp 端点?

Can't find net.tcp endpoint in add service reference in WCF?

我对 WCF 和 net.tcp 绑定有一个共同的问题。 我也在 google 上看到了 Whosebug 上的所有帖子..

我无法将服务引用添加到我的客户端的主要问题。 我收到错误:

Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http]. 
  1. 我正在使用 IIS 7。我在启用协议 net.tcp 中检查了未添加到网站的 HTTP.I,还添加了 net.tcp 到绑定。如果我点击浏览(http)我的地址。我看到我的文件夹和 WCF 应用程序,如果我 select svc 文件我看到正常地址:

    svcutil.exe net.tcp://MYADDRESS/Service.svc/mex

如果我看到这个 URL,我想我的 IIS 设置正确!!

但是当我尝试添加对客户端的引用时,问题就出现了。只是我看到了 http 端点,没有 net.tcp.

这是我的服务配置:

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

      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5"/>
      </system.web>
      <system.serviceModel>
        <services>
          <service name="MYSERVICE.SERVICE" behaviorConfiguration="behavior1">
            <endpoint 
                      binding="netTcpBinding"
                      contract="MYSERVICE.ISERVICE"> 
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:60745/MYSERVICE/SERVICE/"/>
              </baseAddresses>
            </host>
          </service>
        </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behavior1">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="netTcpBinding" scheme="net.tcp" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

注意:我的网站从 60745 地址开始,但是为了在 IIS 中绑定 net.tcp 我添加了 60746:* 我还为两个端口打开了入站出站规则。

谢谢!

根据您在评论中提到的问题,我自己也 运行 认为添加服务引用的 gui 不能很好地处理 mexTcpBinding

您可以将 HTTP mex 用于元数据,并且仍然将 net.tcp 用于您的数据通道。这是我的一个项目的示例,该项目使用带有 http mex 的 tcp 通道。

  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpConfig" closeTimeout="00:30:00" openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00" transferMode="Streamed"
          maxReceivedMessageSize="67108864">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="AsyncStreaming">
          <dispatcherSynchronization asynchronousSendEnabled="true"/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceCredentials>
            <serviceCertificate findValue="Example" x509FindType="FindBySubjectName"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Server.Endpoints.ExampleEndpoint">
        <endpoint address="" behaviorConfiguration="AsyncStreaming" binding="netTcpBinding" bindingConfiguration="NetTcpConfig" contract="Server.IExample"/>
        <endpoint address="" behaviorConfiguration="AsyncStreaming" binding="netTcpBinding" bindingConfiguration="NetTcpConfig" contract="Server.IExample2"/>
        <endpoint address="" behaviorConfiguration="AsyncStreaming" binding="netTcpBinding" bindingConfiguration="NetTcpConfig" contract="Server.IExample3"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <protocolMapping>
        <add binding="netTcpBinding" scheme="net.tcp" bindingConfiguration="NetTcpConfig"/>
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <diagnostics wmiProviderEnabled="false">
      <messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
        maxMessagesToLog="3000"/>
    </diagnostics>
  </system.serviceModel>