windows-services - 无法连接到 net.tcp ://localhost. .. TCP 错误代码 10061

标签 windows-services nettcpbinding net.tcp wcf

引用视频tutorial关于 Windows 服务中的 WCF 服务,我创建了一个示例 WCF 服务,并在 Windows 服务中使用 netTcpBinding 托管该服务。(因为我希望此 WCF 服务作为 Windows 服务运行)

它是一个简单的服务,可以添加/删除/加载员工详细信息,并由 Windows 表单应用程序使用。当我构建整个解决方案(由 wcf 服务 + Windows 服务 + 客户端应用程序组成)时,效果很好,但是当我想要验证我的客户是否直接引用解决方案中的项目,因此我从我的解决方案中排除了这两个服务(wcf+windows)。它停止工作并抛出错误,读取:

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

可能有助于回答的要点:

  • WCF 服务和 Windows 服务具有相同的 app.config
  • Windows 服务作为服务运行

这是我的客户端 app.config

<?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <system.serviceModel>
            <bindings>
                <netTcpBinding>
                    <binding name="netTcpEndPoint" 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="Transport">
                          <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                            <message clientCredentialType="Windows" />
                        </security>
                    </binding>
                </netTcpBinding>
            </bindings>
            <client>
                <endpoint address="net.tcp://localhost:8010/EmployeeService.Service1/"
                    binding="netTcpBinding" bindingConfiguration="netTcpEndPoint"
                    contract="Service1.IService1" name="netTcpEndPoint">
                    <identity>
                        <userPrincipalName value="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4d1d7c1d6e4c7cbc9d4c5cadd8ac7cbc9" rel="noreferrer noopener nofollow">[email protected]</a>" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>
    </configuration>

任何帮助将不胜感激......

最佳答案

我自己找到了答案,希望它能帮助其他人寻找答案......

我发现worker_DoWork()事件没有触发,所以添加worker.RunWorkerAsync();如下面的代码所示到您的 Windows 服务

protected override void OnStart(string[] args)
{                    
    worker = new BackgroundWorker();
    worker.RunWorkerAsync();
    worker.DoWork += new DoWorkEventHandler(worker_DoWork);                
}

从客户端项目中删除服务引用,然后再次添加它,因为它会更改您的 app.config 文件。

关于windows-services - 无法连接到 net.tcp ://localhost. .. TCP 错误代码 10061,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6747952/

相关文章:

c# - 检测 WCF 双工契约(Contract)中的客户端死亡

win7 上的 WCF Duplex net.tcp 问题

.net - 如果客户端和服务都在同一服务器上的同一帐户下运行,是否可以避免指定 servicePrincipalName?

c# - 从 Windows 服务处理长时间运行的操作

c# - 如何创建可以与GUI *或*一起作为C#中的Windows服务运行的Windows应用程序?

wcf - Mono WCF NetTcp 服务一次只需要一个客户端

wcf - 带有 SSL 证书的 Net.TCP 是否可以在互联网上使用

c# - 为什么 Windows 服务中的打印屏幕返回黑色图像?

winforms - Windows 服务与交互式应用程序中的 GDI 句柄

c# - 在 WCF 回调中收到的消息乱序