2

参考有关 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="user@company.com" />
                    </identity>
                </endpoint>
            </client>
        </system.serviceModel>
    </configuration>

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

4

2 回答 2

3

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

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

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

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

于 2011-07-20T07:37:54.253 回答
0

只是一个可能对某些人有所帮助的速记:

此错误出现在控制 Perkin Elmer - Thermo Fisher Scientific 液体处理设备(机器人)的两台计算机之间。

McAfee Antivirus 干扰了他们的通信,卸载 McAfee 消除了该错误。MS Security Essentials Antivirus 没有干扰。

于 2013-03-25T17:45:33.170 回答