【问题标题】:Hosting WCF Service on IIS 7 with net.tcp bindings - Error with consuming the service使用 net.tcp 绑定在 IIS 7 上托管 WCF 服务 - 使用服务时出错
【发布时间】:2011-10-24 13:21:36
【问题描述】:

我正在尝试在 IIS 7 / Win 7 中托管具有 Net TCP 绑定的 WCF 服务。该服务是托管的,我可以在我的客户端应用程序中添加对它的引用。

这里是服务配置文件:

  <configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.0" />

    </system.web>
    <system.serviceModel>
      <bindings>
        <netTcpBinding>
          <binding name="InsecureTcp" portSharingEnabled ="true">
            <security mode="None">
              <transport clientCredentialType="None" protectionLevel="None" />
            </security>
          </binding>
        </netTcpBinding>
      </bindings>
      <services>
        <service name="ApplicationProcessService">
          <endpoint address="" binding="netTcpBinding" bindingConfiguration="InsecureTcp"
            name="NetTCP_Port10000" contract="IApplicationProcess" />
          <endpoint address="mex" binding="mexHttpBinding" name="mexNetTCP_Port10000"
            contract="IMetadataExchange" />
        </service>
      </services>
      <behaviors>
        <serviceBehaviors>
          <behavior name="">
            <serviceMetadata httpGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="true" />
          </behavior>
        </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
        <baseAddressPrefixFilters>
        </baseAddressPrefixFilters>
      </serviceHostingEnvironment>

    </system.serviceModel>
    <system.webServer>
      <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>

  </configuration>

这是我添加引用时在客户端生成的配置:

<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTCP_Port10000" closeTimeout="00:01:00" openTimeout="00:01:00"
            receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
            transferMode="Buffered" transactionProtocol="OleTransactions"
            hostNameComparisonMode="StrongWildcard" listenBacklog="10"
            maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
            maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
              enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://localhost:10000/ApplicationProcess.svc"
          binding="netTcpBinding" bindingConfiguration="NetTCP_Port10000"
          contract="ApplicationProcessService.IApplicationProcess" name="NetTCP_Port10000" />
    </client>
  </system.serviceModel>
</configuration>

问题出在运行时,我收到以下错误:-

无法连接到 net.tcp://localhost:10000/AppServer.ApplicationProcess.svc。连接尝试持续了 00:00:02.0582058 的时间跨度。 TCP错误码10061:目标机器主动拒绝,无法建立连接。

我已按照http://www.singingeels.com/Articles/Duplex_WCF_Services_Hosted_in_IIS_Using_NetTcp.aspx中描述的步骤进行操作

并在我的防火墙中创建了一个入站规则,允许在端口 10000 上进行 TCP 通信。我不确定我缺少什么。有什么想法吗?

【问题讨论】:

标签: c# wcf iis-7 was net.tcp


【解决方案1】:

这里的关键是您启用了端口共享(绑定中的 PortSharingEnabled),这需要您运行 TCP 端口共享服务,该服务在 Windows 中默认不运行。见此链接:NetTcpBinding.PortSharingEnabled

【讨论】:

  • 我添加了 PortSharingEnabled,因为我认为这可能是这里的问题,但没有改变任何东西。我在 services.msc 下启动了 NetTcpPortSharing 服务。
  • 好的。做一个 netstat -ban 看看 10000 是否打开,也许它绑定到你的本地 ip(而不是全部)。尝试连接到您的机器名称/ip 而不是 localhost。
  • [FrameworkService.exe] TCP 0.0.0.0:10000 0.0.0.0:0 LISTENING
  • 看起来是正确的。我猜你安装了一些第三方防火墙。
  • 迈克菲企业防病毒软件。在 McAfee 中看不到防火墙设置。
【解决方案2】:

除了前面提到的 Net.Tcp 端口共享服务外,您还需要启用并启动 Net.Tcp Listener Adapter 服务。

【讨论】:

  • 已检查。这也是启用的。 Net.Tcp Listener Adapter 服务设置为自动启动,NetTcpPortSharing 服务也设置为自动启动。
  • 注意,auo start 只是意味着它会在 eindows 启动时启动。如果windows已经启动没有效果,则需要手动启动服务(或重启)
【解决方案3】:

除了需要启用的服务之外,我还必须启用 IIS 以识别 net.tcp。右键单击您的网站 > 管理应用程序 > 高级设置。启用协议的值应为:http,net.tcp

【讨论】:

    猜你喜欢
    • 2015-01-28
    • 1970-01-01
    • 2011-07-21
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多