WCF代理池-值得吗? [英] WCF Proxy Pooling - Is it worth it?

查看:91
本文介绍了WCF代理池-值得吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

真的值得合并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?

推荐答案

值得缓存ChannelFactory,因为其构造成本很高.在某些情况下,添加服务参考(或直接为svcutil.exe)生成的代理可以做到这一点(通常,如果要进行此缓存,则不得在代码中构建绑定).如果您手动构建ChannelFactory(不使用生成的代理),则可以将其存储在某个地方,而不是每次需要时都对其进行初始化.

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.

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

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.

这篇关于WCF代理池-值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆