本文介绍了重用的ChannelFactory策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在读那的ChannelFactory创建是昂贵,除非有技术原因不,应该在可能的情况或者通过某种方式缓存他们,或使用工厂静态实例重用ChannelFactories。

I've been reading that ChannelFactory creation is expensive and that unless there is a technical reason not to, one should reuse ChannelFactories when possible either by caching them someway, or by using static instances of the factories.

在你的经验,你有没有发现什么的ChannelFactory重用策略,是一个ASP.NET应用程序?

In your experience, what ChannelFactory reuse strategies have you found to be the most useful and robust within the context of an ASP.NET application?

推荐答案

如果您正在使用.NET 3.0 SP1及以上,并且不需要,需要直接处理渠道特殊的东西,那么最好的办法是只使用自ClientBase的&lt客户端代理类; T> (像导入的服务时所产生的那些)。那些已经下缓存工厂。见这里的细节。

If you're using .NET 3.0 SP1 and up and don't need special stuff that requires handling channels directly, then the best option would be to just use client-side proxy classes derived from ClientBase<T> (like the ones generated when importing services). Those already cache the factory underneath. See here for the details.

如果没有,那么是的,你需要坚持的IChannelFactory&LT; T&GT;反对的地方,但你必须仍然确保你妥善处理共享(我不认为有一个工厂的访问堆栈作出任何保证是线程安全的),但除此之外,它应该是相当直接的

If not, then yeah, you'll need to stick the IChannelFactory<T> object somewhere, but you need to still make sure you handle sharing appropriately (I don't think there's any guarantees made by the stack that access of a factory is thread-safe), but other than that, it should be fairly straight-forward.

这篇关于重用的ChannelFactory策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 23:02