创建新的 ChannelFactory;当出现故障时
重新创建 ChannelFactory
编辑:
使用 @Ladislav Mrnka 的答案 - 似乎完成此操作的最可靠方法是为 ChannelFactory
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您认为该解决方案对您有什么帮助?您将锁定该部分,以便只有一个线程可以进入该部分并检查 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: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 exposeCreateChannel
method and all other methods you need. You can use such wrapper for managing multiple factories.这两个
创建 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 :)