[英]WCF - decrease the timeout for WCF connection
I have a WCF service and I defined a operation contract method called IsAlive(). 我有一个WCF服务,并且定义了一个名为IsAlive()的操作协定方法。 The goal is to check if the client is still alive or not before the exceution of its callback function.
目的是在执行其回调函数之前检查客户端是否仍然存在。
if (IsClientAlive())
WcfService.Callback.UIMessageOnCallback(UIMessage);
The default timeout is set to 1 minute, too long in my case. 默认超时设置为1分钟,对于我来说太长了。 As everything happens in the same workstation, I would like to reduce it to 5 seconds so there is only a little delay in the execution.
由于所有事情都是在同一工作站上发生的,因此我希望将其减少到5秒,因此执行的延迟很小。
Following the instructions here https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-timeout-values-on-a-binding 按照此处的说明https://docs.microsoft.com/zh-cn/dotnet/framework/wcf/feature-details/configuring-timeout-values-on-a-binding
I modified my app.config accordingly, but the nothing changed afterwards. 我相应地修改了app.config,但此后什么都没有改变。 The IsAlive() function keeps taking 1 minute to finalize.
IsAlive()函数需要1分钟才能完成。 Any idea what am I missing?
知道我想念什么吗?
<?xml version="1.0" encoding="utf-8" ?><configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup> <system.serviceModel>
<bindings>
<wsHttpBinding>
<binding openTimeout="00:00:05"
closeTimeout="00:00:05"
sendTimeout="00:00:05"
receiveTimeout="00:01:00">
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="EEAS.Kiosk.WcfService">
<endpoint address="" binding="wsDualHttpBinding" contract="EEAS.Kiosk.IWcfService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/KioskService/WcfService/" />
</baseAddresses>
</host>
</service>
</services> </system.serviceModel></configuration>
NOTE : I had a mispelling "wsHttpBinding" when it had to be "wsDualHttpBinding". 注意 :当必须为“ wsDualHttpBinding”时,我拼错了“ wsHttpBinding”。 Thanks stuardt for the tip!
谢谢斯图尔特的提示! I did the change but IsAlive() function always thrown an exception "sessionful channel timed out".
我进行了更改,但IsAlive()函数始终引发异常“会话通道超时”。
{System.ServiceModel.CommunicationObjectAbortedException: The operation 'IsAlive' could not be completed because the sessionful channel timed out waiting to receive a message. {System.ServiceModel.CommunicationObjectAbortedException:操作'IsAlive'无法完成,因为会话通道超时等待接收消息。 To increase the timeout, either set the receiveTimeout property on the binding in your configuration file, or set the ReceiveTimeout property on the Binding directly.
要增加超时,请在配置文件中的绑定上设置receiveTimeout属性,或者直接在绑定上设置ReceiveTimeout属性。
So I put the ReceiveTimeout timeout back to 1 minute but the error persists. 因此,我将ReceiveTimeout超时恢复为1分钟,但错误仍然存在。 Any idea what could be happening?
知道会发生什么吗? I checked the variable host.State and its value is CommunicationState.Opened.
我检查了变量host.State,其值是CommunicationState.Opened。
This explanation gave me the final tip. 这个解释给了我最后的提示。 https://www.rauch.io/2015/06/25/all-wcf-timeouts-explained/
https://www.rauch.io/2015/06/25/all-wcf-timeouts-explained/
So I implemented a heartbeat in the client using a timer every 15 seconds. 因此,我每隔15秒使用计时器在客户端中实现一次心跳。 The receiveTimeout is set to 1 minute so it could miss 3 heartbeat before dropping the connection.
receiveTimeout设置为1分钟,因此在断开连接之前可能会丢失3个心跳。
in the main method of the client: 在客户端的主要方法中:
System.Timers.Timer keepAliveTimer = new System.Timers.Timer(15000);
keepAliveTimer.AutoReset = false;
keepAliveTimer.Elapsed += new System.Timers.ElapsedEventHandler(keepAliveTimer_Elapsed);
keepAliveTimer.Start();
and the function which calls the isAlive method in the WCF service. 和在WCF服务中调用isAlive方法的函数。
void keepAliveTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
client.isAlive();
}
catch (System.Exception ex)
{
eventLog1.WriteEntry(" [CRITICAL EXCEPTION in keepAliveTimer_Elapsed()]. WCf service is down, Kiosk Tray Agent is trying to send a heartbeat." + Environment.NewLine + "Caught an exception of type" + ex.GetType().Name, EventLogEntryType.Error, 912);
}
finally
{
((System.Timers.Timer)sender).Start();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.