使用单例 ASMX Web 服务代理可以吗?
我正在使用 ASMX Web 服务使用 .NET 3.5 编写的一些
旧代码。
Windows 服务(称为 FooService)静态缓存 Web 服务(称为 BarWS)的 ASMX 代理,它每小时大约调用 10-30 次来响应客户端请求。
作为
遗留代码,由于各种原因,它很难测试。我正在打破依赖关系以使其可测试,这个静态引用让我想知道。我使用 ASMX 已经很多年了,我记得代理是线程安全的 - 但我想知道它是否会变得不可用,就像单例/共享 WCF 代理在出现问题并出现故障时一样。
鉴于此代理的少量使用(BarWS 的调用次数少于 30 次/小时),我认为在每次调用时创建一个新的代理会安全得多 - 但我只是想知道我是否会做出不必要的更改。有人知道吗?
PS 我知道 WCF 更好,但在这个
遗留代码库中,迁移到 WCF 目前变化太大。
I am working with some <gulp>
legacy code written in .NET 3.5 using ASMX web services.
A windows service (call it FooService) is statically caching an ASMX proxy for a web service (call it BarWS) that it calls in response to client requests around 10-30 times an hour.
Being <gulp>
legacy code it is for various reasons incredibly hard to test. I am in the process of breaking dependencies to make it testable and this static reference got me wondering. It's been years since I used ASMX and I recall the proxy is thread-safe - but I wondered if it could become unusuable in the same way that singleton/shared WCF proxies can when they develop an issue and become faulted.
Given the light use of this proxy (BarWS is called less than 30 times/hour), I am thinking it would far safer to create a fresh proxy on every call - but I'm just wondering if I would be making an unnecessary change. Anyone know?
P.S. I know WCF is better, but migration to WCF is too much change right now in this <gulp>
legacy codebase.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
测量创建代理需要多长时间。如果这是一个错误的优化(我强烈怀疑它是),那么将其更改为基于实例的创建。一般来说,避免静电是好的。把它放在工厂后面,那么如果你真的愿意的话,至少你仍然可以拥有单例类型的行为,但这种创建行为将被屏蔽并独立于客户端。
Measure how long it takes to create a proxy. If it's a false optimization (I strongly suspect it is), then change it to instance based creation. It's generally good to avoid statics. Put it behind a factory, then at least you can still have singleton-type behaviour if you really wanted to, but this creational behaviour would then be masked and independent of the client.