如何在WCF中自动重新连接命名管道绑定 [英] How can I make Named Pipe binding reconnect automatically in WCF
问题描述
我正在编写一项仅会从本地主机拨打电话的服务。性能很重要,因此我想尝试一下 NetNamedPipeBinding 而不是 NetTcpBinding ,然后查看是否可以看到性能显着提高。
I'm writing a service that will only get calls from the local host. Performance is important so I thought I'd try the NetNamedPipeBinding instead of NetTcpBinding and see If I could see any noticeable performance gains.
如果客户端在向服务器执行了一个或多个请求之后闲置了较长时间,则下一个请求似乎将由于以下原因而失败:绑定中有一些空闲超时。重新启动该服务时,也会发生同样的事情。
If a client, after having performed one or more requests to the server, is idle for a longer period of time the next request will fail seemingly due to some idle timeout in the binding. The same thing also happens when the service gets restarted.
我需要我的客户在允许的时间内保持打开状态,以免产生开销与建立新连接有关。我还需要能够不时地重新启动服务,并让客户端在他们注意到连接已终止时自动重试。
I need my clients to be able to keep a connection open for as long as it's allowed in order to avoid the overhead associated with setting up a new connection. I also need to be able to restart the service from time to time and have the clients to automatically retry if they notice that the connection has been terminated.
我知道是由NetTcpBinding中的可靠性支持的,但是如何在NetNamedPipeBinding中获得相同级别的重新连接可靠性呢?
I know that this is suppported by the reliability stuff in NetTcpBinding but how would one go about getting the same level of re-connect reliability in the NetNamedPipeBinding? Is it even possible?
问题有点学术性,因为它不是使用NetNamedPipes的要求,我可以很容易地采用它来使用tcp-binding,但是
The question is somewhat academic as it isn't a requirement to use NetNamedPipes, I could just as easily adopt it to use the tcp-binding but It's an itch and I'd really like to scratch it.
推荐答案
我的经验是,当使用NetNamedPipes时, ReceiveTimout绑定功能上的(例如不活动超时)而不是接收超时。请注意,这与NetTCPBinding的工作方式不同。使用TCP,这实际上是一个接收超时,您可以通过可靠的消息传递配置一个单独的不活动超时。 (这似乎也与SDK文档相反,但是,哦)。
My experience is that, when using NetNamedPipes, the "ReceiveTimout" on the binding functions like an "Inactivity Timeout" rather than a receive timout. Note that this different than how a NetTCPBinding works. With TCP, it really is a receive timeout and there's a separate inactivity timeout you can configure via reliable messaging. (It's also appears to be contrary to the SDK documentation, but oh well).
要解决此问题,请在创建绑定时将RecieveTimout设置为较大值。 >
例如,如果您正在按程序创建绑定...
To fix this, set the RecieveTimout to something big when you create the binding.
For example, if you are creating your binding procedurally...
NetNamedPipeBinding myBinding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
myBinding.ReceiveTimeout = TimeSpan.MaxValue;
或者,如果您关心声明式创建绑定...
Or, if you care creating your binding declaratively...
<netNamedPipeBinding>
<binding name="myBinding" receiveTimeout="infinite">
</binding>
</netNamedPipeBinding>
这篇关于如何在WCF中自动重新连接命名管道绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!