参考有关 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>
任何帮助将不胜感激....