WCF net.tcp 连接总是失败

发布于 2024-12-15 01:01:32 字数 2562 浏览 2 评论 0原文

我尝试使用 net.tcp 绑定设置测试服务。我还设置了一个 http 端点。配置如下:

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="Inbound_REST">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="InboundHttpConfiguration">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="InboundTcpConfiguration">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="InboundTcpConfiguration" name="Inbound">
          <endpoint address="" binding="netTcpBinding" contract="IContract">
            <identity>
              <dns value="localhost"/>
            </identity>
          </endpoint>
          <host>
            <baseAddresses>
              <add baseAddress="net.tcp://localhost:6969/Inbound" />
            </baseAddresses>
          </host>
        </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <client>
      <endpoint name="httpEndPoint" address="http://localhost:1568/Inbound.svc" binding="basicHttpBinding" contract="IContract" />
       <endpoint name="tcpEndPoint" address="net.tcp://localhost:6969/Inbound" binding="netTcpBinding" contract="IContract" />
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="httpbind">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="tcpbind">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
  </system.serviceModel>

当我尝试使用 net.tcp 绑定使用服务时,它总是返回错误:

无法连接到 net.tcp://localhost:6969/Inbound。连接尝试持续的时间跨度为 00:00:00.9531494。 TCP错误代码10061:无法建立连接,因为目标机器主动拒绝它127.0.0.1:6969。

顺便说一下,http绑定工作正常。我认为这可能是某些机器配置的问题,但无法找到根本原因。

I tried to setup a service for testing using a net.tcp binding. I also set a http endpoint. The configuration is as follows:

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="Inbound_REST">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="InboundHttpConfiguration">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="InboundTcpConfiguration">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="InboundTcpConfiguration" name="Inbound">
          <endpoint address="" binding="netTcpBinding" contract="IContract">
            <identity>
              <dns value="localhost"/>
            </identity>
          </endpoint>
          <host>
            <baseAddresses>
              <add baseAddress="net.tcp://localhost:6969/Inbound" />
            </baseAddresses>
          </host>
        </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <client>
      <endpoint name="httpEndPoint" address="http://localhost:1568/Inbound.svc" binding="basicHttpBinding" contract="IContract" />
       <endpoint name="tcpEndPoint" address="net.tcp://localhost:6969/Inbound" binding="netTcpBinding" contract="IContract" />
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="httpbind">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="tcpbind">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
  </system.serviceModel>

When I attempt to consume the service using the net.tcp binding, it always return me the error:

Could not connect to net.tcp://localhost:6969/Inbound. The connection attempt lasted for a time span of 00:00:00.9531494. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:6969.

By the way, the http binding works fine. I think it could be some machine configuration, but wasn't able to find what's the root cause.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

仄言 2024-12-22 01:01:32

如果您尝试通过 Visual Studio 运行 WCF 服务,则不支持 netTcpBinding。对不起!

查看这篇文章了解更详细的解释。

If you are trying to run your WCF service through visual studio netTcpBinding is not supported. Sorry!

Check out this post for a more detailed explanation.

像你 2024-12-22 01:01:32

为什么您省略了客户端的 net.tcp 地址的“.svc”?也许应该是“net.tcp://localhost:6969/Inbound.svc”

Why did you leave out the ".svc" for the net.tcp address for the client? Maybe it should be "net.tcp://localhost:6969/Inbound.svc"

旧城空念 2024-12-22 01:01:32

您正在使用什么主机..IIS7 或控制台或其他?

1) 检查所有 tcp 服务是否在 services.msc 中运行

请关闭防火墙或向 tcp 端口添加防火墙例外,

2)如果您在 iis7 中托管,

请检查此链接IIS7 对非 http 协议的支持

What hosting you are using..IIS7 or console or others?

1)Check all tcp services are running in services.msc

2)Turn off your fire wall or add firewall exception to your tcp port

if you are hosting in iis7 check this link

IIS7 support for non http protocols

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文