【发布时间】:2020-02-21 15:42:48
【问题描述】:
我有一个托管在 Windows 服务中的 WCF 服务。然后我有一个 GUI(客户端),然后与该服务通信。最近有报道称,与服务的通信在空闲 10 分钟后停止。
我做了一些研究,看起来服务由于不活动而丢弃了连接。因此,我想增加接收超时并启用可靠会话并将 inactivityTimeout 设置为更长。但是,当我在 WCF 服务和客户端 app.config 文件中执行此操作时,我收到以下错误:
设置reliableSession enabled="False" 会导致客户端和服务运行。 (虽然只有 10 分钟)
做一些研究,建议是因为以下三个原因之一:
- 客户和发送方之间有不同的合同。
- 您在客户端和发送方之间使用了不同的绑定。
- 客户端和发送者之间的消息安全设置不一致。
但据我所知,客户端和服务器之间的设置/合同是一致的。我希望这是愚蠢的。这是我的服务和客户端的 app.config:
服务
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IHwResourceManagerWcfService" receiveTimeout="infinite" >
<reliableSession enabled="True" inactivityTimeout="infinite"/>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8523/HwResourceManagerWcfService"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IHwResourceManagerWcfService"
contract="WindowsServices.IHwResourceManagerWcfService" name="NetTcpBinding_IHwResourceManagerWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service name="MT.Tools.HwResourceManager.WCF.HwResourceManagerWcfService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="MT.Tools.HwResourceManager.WCF.IHwResourceManagerWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8523/HwResourceManagerWcfService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
客户
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IHwResourceManagerWcfService" receiveTimeout="infinite" >
<reliableSession enabled="True" inactivityTimeout="infinite"/>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8523/HwResourceManagerWcfService"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IHwResourceManagerWcfService"
contract="WindowsServices.IHwResourceManagerWcfService" name="NetTcpBinding_IHwResourceManagerWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
任何帮助将不胜感激。
【问题讨论】:
标签: c# wcf windows-services wcf-binding