创建新的 ChannelFactory;当出现故障时

发布于 2024-11-13 07:10:40 字数 252 浏览 4 评论 0原文

重新创建 ChannelFactory的最可靠方法是什么?当进入故障状态时以线程安全的方式?此场景具有预期的并发性(为了便于讨论,假设有 50 个并发客户端)。我想知道一些实现这一目标(或替代方案)的推荐方法/想法/意见。

编辑:

使用 @Ladislav Mrnka 的答案 - 似乎完成此操作的最可靠方法是为 ChannelFactory创建一个包装器。我最终这样做了,并公开了包装器的 CreateChannel 方法。

What would be the most reliable way of recreating a ChannelFactory<T> in a thread safe manner when it enters a faulted state? This scenario has expected concurrency (let's say 50 concurrent clients for the sake of argument). I would like to know some recommended approaches/thoughts/opinions for achieving this goal (or an alternative).

Edit:

Using @Ladislav Mrnka's answer - it seems the most reliable way to accomplish this is to create a wrapper for ChannelFactory<T>. I ended up doing this, and exposing a CreateChannel method of the wrapper.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一笑百媚生 2024-11-20 07:10:40

您认为该解决方案对您有什么帮助?您将锁定该部分,以便只有一个线程可以进入该部分并检查 ChannelFactory 是否出现故障并重新创建它,但通道工厂的实例是共享的 - 您从属性返回它,因此:

  • 如果您进行检查并创建另一个线程可以在此之后接收工厂的实例,并在初始线程中使用新工厂之前对其进行故障排除(竞争条件)。
  • 如果您重新创建一个有故障的工厂,所有其他已经持有该引用的线程仍然指向有故障的工厂。

因此,该解决方案将确保以线程安全的方式重新创建 ChannelFactory,但您仍然必须检查工厂是否在您想要使用它的任何地方出现故障(这应该再次是线程安全的,以便可靠) )。

我认为可靠的方法是围绕 ChannelFactory 创建包装器,并通过线程安全性处理所有复杂性并检查包装器内的故障工厂。包装器将公开 CreateChannel 方法以及您需要的所有其他方法。您可以使用此类包装器来管理多个工厂。

How do you think this solution will help you? You will lock the section so that only one thread can go into that section and check if ChannelFactory is faulted and recreate it but the instance for channel factory is shared - you return it from the property so:

  • If you make a check and create the instance the other thread can receive the factory after that and fault it before you use your new factory in the initial thread (race condition).
  • If you recreate a faulted factory all other threads who already hold the reference are still pointing to the faulted one.

So the solution will ensure that ChannelFactory is recreated in the thread safe manner but you will still have to check if the factory is faulted anywhere you would like to use it (which should again be thread safe to be reliable).

I guess the reliable approach is creating wrapper around ChannelFactory and handle all complexity with thread safety and checking faulted factory inside the wrapper. The wrapper would expose CreateChannel method and all other methods you need. You can use such wrapper for managing multiple factories.

成熟的代价 2024-11-20 07:10:40

这两个
创建 WCF ChannelFactory

WCF 的最佳解决方法是什么客户端“using”块问题?
精彩的讨论帮助我构建了自己的防弹 WCF 服务。
我相信您也将从中受益匪浅。
两者都包含对您问题的直接回答:)

These two
creating WCF ChannelFactory<T>
and
What is the best workaround for the WCF client `using` block issue?
wonderful discussions helped me build my own bullet proof WCF service.
I believe you too are going to benefit from them greatly.
Both include direct answer to your question too :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文