简体   繁体   English

检查WCF通信通道状态的正确方法

[英]Proper way to check WCF Communication Channel State

I am developing a WCF client / server solution which I need to have the communication channel available 24/7 as there is a windows service that publishes data continually - my WF implementation is a Subscribe/Publish service. 我正在开发WCF客户端/服务器解决方案,由于Windows服务可以连续发布数据,因此我需要使通信通道24/7可用-我的WF实现是“订阅/发布”服务。 I have put some things together but seem to have issues losing connections and some other nefarious problems. 我整理了一些东西,但似乎遇到了失去联系的问题和其他一些邪恶的问题。 As I was reading on Microsoft website about checking the Communication Object Checking the value of the ICommunicationObject.State property is a race condition and is not recommended to determine whether to reuse or close a channel. 正如我在Microsoft网站上阅读的有关检查通信对象的内容一样,检查ICommunicationObject.State属性的值是一种竞争条件,不建议您确定是重用还是关闭通道。 However the examples I have been seeing all use this technique! 但是我看到的所有示例都使用了这种技术! Microsoft makes that notation but gives no further information or advice in regards to how to do it "PROPERLY". Microsoft做出了这种表示法,但未提供有关如何“正确”执行此操作的进一步信息或建议。

So I would like to know what is the proper way to do this - those with experience regarding this please chime in and help I as I am learning WCF - I can use good tips of how to's. 因此,我想知道什么是正确的方法-那些有经验的人请加入我的行列,并在我学习WCF时为我提供帮助-我可以使用如何做的好技巧。

So I would like to know what is the proper way to do this 所以我想知道什么是正确的方法

Well, a race condition is a race condition - they are impossible to catch before the fact because they have not hapenned yet. 好吧,竞赛条件就是竞赛条件-他们还没有停滞不前,因此不可能在事实面前抓住。 So your expectation of being able to know the state of the channel before you call it is unreasonable. 因此,您期望在调用该通道之前就知道该通道的状态是不合理的。

However, we know we should always be able to reuse a channel if it is not in a faulted (or closed) state. 但是,我们知道,如果通道不处于故障(或关闭)状态,那么我们应该总是能够重用它。 So we can just wrap our call to the channel in a try...catch and then handle exceptions as appropriate . 因此,我们可以仅在try ... catch中包装对通道的调用,然后适当地处理异常。

If the channel is not reusable then this is actually an error condition which needs to be handled after the fact. 如果通道不可重用,那么实际上这是一个错误情况,需要在事后进行处理。 In a workflow, you could usually implement this as a compensation mechanism, perhaps by creating another channel and then calling it. 在工作流中,通常可以通过创建另一个通道然后调用它来将其实现为补偿机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM