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

本文关键字:net 找不到 tcp 结点 引用 WCF 添加 服务 | 更新日期: 2023-09-27 18:36:49

我在WCF和net.tcp绑定方面遇到了常见问题。我看到堆栈溢出上的所有帖子也在谷歌上搜索。.

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

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应用程序,如果我选择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:*我还打开了两个端口的入站出站规则。

谢谢!

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

从您在评论中提到的问题来看,我自己也运行了它,添加服务引用的 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>