如果我不关闭 WCF/ASMX 代理会有多糟糕?

发布于 2024-08-16 08:41:00 字数 228 浏览 4 评论 0 原文

所以有人(好吧,就是我)没有意识到使用 WCF 代理后需要关闭它们。

这有多糟糕?它会导致什么样的问题。

是否只是因为垃圾收集而延迟关闭资源 - 或者我真的应该担心诸如过早的应用程序池回收之类的事情吗?

事实上,我遇到这个问题的 ASMX 比 WCF 代理要多得多 - 所以同样的问题也适用于 ASMX。

显然,现在我知道了这一点,我将逐步修复它,但希望您能了解这到底有多糟糕?

So somebody (ok it was me) didn't realize you need to close WCF proxies after using them.

How bad is this? What kind of problems can it cause.

Is there just a delay in closing resources because of garbage collection - or should I really worry about things like premature app pool recycling?

I actually have far more ASMX than WCF proxies with this issue - so the same question goes for ASMX also.

Obviously now that I know this I'm going to gradually fix it, but would appreciate input on how bad this really is?

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

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

发布评论

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

评论(3

拒绝两难 2024-08-23 08:41:00

WCF 服务具有默认超时。如果不关闭它,服务将等待,直到超时。

WCF 还具有最大并发调用数,默认值为 10。

因此,如果不关闭连接,则每分钟只能进行 10 个调用。 (假设默认设置)

这里有人遇到类似的问题:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d58ee1c6-032b-40f3-b734-6628f3991bb2/

A WCF service has a default timeout. If you do not close it, the service will wait until there is a timeout.

WCF also has a max concurrent calls, that has a default of 10.

Therefore, if you do not close your connections you can only have 10 calls per min. (assuming default settings)

Here is someone with a similar problem:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/d58ee1c6-032b-40f3-b734-6628f3991bb2/

浅浅 2024-08-23 08:41:00

您可以安全地重用 WCF 连接,只需额外注意检查它是否处于故障状态即可。

You can safely to reuse a WCF connection, just taking additional care to check if it's in a faulted state.

笑饮青盏花 2024-08-23 08:41:00

作为一般指南,当您希望逐渐解决此问题时,不要用 using 语句包装您的代理,我见过很多人这样做,我一直在这样做,直到我读到IDesign 的文章,这样做可能会导致 Dispose 抛出异常并掩盖真正的异常,在 try/catch 中显式关闭代理,如果关闭导致异常,则使用 Abort 进行资源清理。

编辑:正如下面的评论所述,这适用于 WCF 代理。

As a general guide when you are looking to gradually fix this, don't wrap your proxy's with a using statement, I've seen a lot of people do this, I was doing it until I read an article by IDesign that doing this might cause the Dispose to throw an exception and mask a real exception, explicitly close your proxy in try/catch, if close causes an exception, use Abort for resource clean up.

EDIT: As noted by the comment below this applies to WCF Proxies.

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