WCF 代理池 - 值得吗?

发布于 2024-12-02 08:14:34 字数 86 浏览 0 评论 0原文

是否真的值得池化 WCF 代理客户端,还是在每次调用给定方法时实例化一个新代理更好?

顺便问一下,是否有人有他/她愿意分享的此类代理的池模式?

Is it really worth pooling WCF proxy clients, or is it better to instanciate a new proxy on every call to a given method?

By the way, does anyone have a pooling pattern for this kind of proxies which he/she is willing to share?

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

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

发布评论

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

评论(1

佞臣 2024-12-09 08:14:34

缓存 ChannelFactory 是值得的,因为它的构建成本很高。在某些情况下,由添加服务引用(或直接svcutil.exe)生成的代理会执行此操作(通常,如果您想拥有此缓存,则不得在代码中构建绑定)。如果您手动构建 ChannelFactory(不使用生成的代理),则可以将其存储在某个位置,而不是每次需要时都对其进行初始化。

池代理可能没有多大意义。对于无状态服务,代理创建应该很快(如果您有缓存工厂)。对于有状态服务,您不希望在多个“客户端”之间共享代理。连接级别本身也有池化。默认情况下,HTTP 绑定使用称为持久连接的东西。这些连接可以由多个代理重复使用。 Net.tcp 和 net.pipe 绑定内部使用连接池。这意味着代理的生命周期不必与连接的生命周期相同。

It is worth to cache ChannelFactory because its construction is costly. Proxies generated by Add Service Reference (or svcutil.exe directly) do this in some scenarios (generally you must not build binding in code if you want to have this caching). If you build ChannelFactory manually (you don't use generated proxies) it is up to you to store it somewhere instead of initializing it every time you need it.

Pooling proxies probably doesn't make much sense. For stateless services the proxy creation should be fast (if you have cached factory). For statefull services you don't want sharing proxy among multiple "clients". There is also pooling on connection level itself. HTTP bindings use something called persistent connections by default. These connections can be reused by multiple proxies. Net.tcp and net.pipe bindings use connection pooling internally. It means that lifetime of the proxy doesn't have to be the same as lifetime of the connection.

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