【问题标题】:Unable to add service client for a net.tcp WCF service无法为 net.tcp WCF 服务添加服务客户端
【发布时间】:2024-01-13 22:48:02
【问题描述】:

我正在尝试为基于 net.tcp 的 WCF 服务添加客户端。当我使用“添加服务引用”并提供此 URL:net.tcp://localhost/service1.svc 时,会出现以下错误。

URI 前缀无法识别。元数据包含一个引用 无法解决:“net.tcp://localhost/service1.svc”。不能 连接到 net.tcp://localhost/service1.svc。连接尝试 持续了 00:00:02.0051147 的时间跨度。 TCP 错误代码 10061:否 可以建立连接,因为目标机器主动拒绝 它是 127.0.0.1:808。无法建立连接,因为目标 机器主动拒绝它 127.0.0.1:808 如果服务定义在 当前解决方案,尝试构建解决方案并添加服务 再次参考。

我检查了 WCF 非 http 服务的 Windows 组件,但它们已经安装。这是快照:

如您所见,它们是为 .NET 3.5.1 安装的,而我的服务是在 .NET 4.5 中构建的。这是问题吗?我应该如何解决它?因为 Windows 组件列表中没有 .NET 4.5 的选项。

以下是我的 WCF 服务的配置:

<system.serviceModel>
<services>
<service name="CoreService.Service1" behaviorConfiguration="beh1">
  <host>
    <baseAddresses>
      <add baseAddress="net.tcp://localhost/Service1.svc"/>
    </baseAddresses>
  </host>
        <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.IAccountService"/>
       <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.ICategoryService"/>
         <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.ICommonService"/>
         <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.IFollowerService"/>
         <endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.IInterestService"/>
<endpoint
     binding="netTcpBinding"
     bindingConfiguration="ultra"
     contract="CoreService.IInviteService"/>

  <endpoint
          address="mex"
          binding="mexTcpBinding"
          contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="ultra"
     maxBufferPoolSize="2147483647"
     maxBufferSize="2147483647"
     maxConnections="2147483647"
     maxReceivedMessageSize="2147483647"
     portSharingEnabled="false"
     transactionFlow="false"
     listenBacklog="2147483647"
     sendTimeout="00:01:00">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
    <serviceBehaviors>
      <behavior name="beh1">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="True" />
        <dataContractSerializer maxItemsInObjectGraph="65536" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

【问题讨论】:

    标签: c# asp.net .net wcf tcp


    【解决方案1】:

    这似乎不是 WCF HTTP 或非 HTTP 激活功能与您的服务之间的不兼容问题。

    据我说,IIS 中的配置缺失或错误,这可以解释连接被拒绝的原因。要使用 net.tcp 正确配置 IIS,请查看 here

    【讨论】:

    • 感谢您的链接。我交叉检查了配置,唯一的问题是我没有将 net.tcp 添加到网站的启用协议中。但是在我添加之后,它显示了以下错误There is no compatible TransportManager found for URI. . This may be because you have used an absolute address that points outside of the virtual application, or the binding settings of the endpoint do not match those that have been set by other services or endpoints. Note that all bindings for the same protocol should have the same settings in the same application.
    • 现在已经解决了。我删除了 maxConnection 属性并且它起作用了。 :)