WCF 客户端收到 TimeoutException(并且我正在关闭我的连接)
事情是这样的... 我已经研究这个问题很长时间了,但没有运气,
我在 IIS 上托管了一个 WCF 服务(我也在控制台主机中尝试过,我得到了相同的行为),我通过 scvutil 创建的代理调用它,并且服务在几次(很少的调用)后无法响应。
但是,这里有一些线索:
1-它只发生在测试环境中(而不是在我的开发机器上托管的服务中),数字!
2-我异步调用服务(client.MyServiceAsync)
3-这是最棘手的...如果我运行 fiddler 来查看发生了什么,客户端会工作并且永远不会失败,当然,我关闭 fiddler (甚至没有重新启动客户端)
到目前为止我不知道发生了什么。 我开始认为服务器(Win2003)可能有某种“防御者”来阻止进一步的连接,这可能吗? 当我说我在每次调用后都会关闭客户端时,请相信我,实际上是在我收到服务器的响应后,因为我使用的是异步调用。
任何提示或建议将不胜感激。 问候,
编辑:我认为这可能是有用的信息: 我已经在两端启用了跟踪,但没有运气。
在服务器端,我看到连接来来去去……在某些时候,没有更多连接进来。而在客户端,我看到连接一直在工作,直到其中一个抛出 TimeoutException……这就是我得到的全部
Here's the thing...
I've been working on this issue for a long time now with no luck
I have a WCF service hosted on IIS (I also tried in a console host and I get the same behavior) which I call thru my scvutil created proxy, and the service fails to respond after a few (very few calls).
But, here are a few clues:
1- It only happens on the testing environment (not with the services hosted on my dev machine), figures!
2- I call the service asynchronously (client.MyServiceAsync)
3- this is the trickiest one... if I run fiddler to see what's going on, the client works and never fails, unitl of course, I close fiddler (without even restarting the client)
I have no clue so far what's going on. I started to think maybe the server (a Win2003) has some kind of "defender" which blocks further connections, could that be possible? Please trust me when I say I do close the clients after every call, actually after I get the response from the server since I'm using ascynchronous calls.
Any tip or advice would be more than appreciated.
regards,
Edit: I thought this could be usefull info:
I have enabled tracing at both ends with no luck.
At the server side I see the connections coming and going... and at some point there are no more connection coming in. While at the client side I see connection working until one of them throws a TimeoutException... that's all I get
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最好的选择是在客户端和服务上启用跟踪,以查看控制流。 至少这样您将对 WCF 所采取的操作有一定的了解。
以下是有关启用跟踪的信息:
http://msdn.microsoft.com/en-us/library/ms733025。 。
我建议将客户端和服务器端跟踪加载到服务跟踪查看器工具中,以便您可以看到相关的事件 以下是有关该工具以及如何读取输出的更多信息:
http://msdn.microsoft.com/en-us/library/aa751795。 aspx
该工具对于调试此类事情非常有用。 希望您能立即看到发生了什么。
如果您发现仍然无法看到所需的信息,您还可以尝试消息日志记录(服务跟踪查看器工具也可以读取这些文件)。
不过,我确实认为您认为连接未正确关闭是正确的。 特别是对于异步操作,很容易在没有意识到的情况下做到这一点。 过去,当我在结束请求触发之前重新创建客户端对象时,我就发生过这种情况。 这导致我正确关闭第二对象的连接,但不是第一个。 跟踪查看器很快就向我指出了这一点。
Your best bet would be to enable tracing on both the client and the service to sort of see the flow of control. At least then you will get some visibility into the actions being taken by WCF.
Here's info on enabling tracing:
http://msdn.microsoft.com/en-us/library/ms733025.aspx
And I'd recommend loading the client-side and server-side traces into the Service Trace Viewer tool so you can see the events correlated together. Here's some more info on that tool and how to read the output:
http://msdn.microsoft.com/en-us/library/aa751795.aspx
That tool is invaluable for debugging this kind of thing. Hopefully you will see what's going on right away.
If you find you still aren't able to see the information you need, you can also try message logging (the service trace viewer tool can read those files too).
I do think you are on the right track thinking it's connections not closing properly, though. Especially with async operations, it's easy to do this without realizing it. This happened to me in the past when I was recreating my client object before the end request fired. This caused me to propely close the second object's connection, but not the first. The trace viewer pointed this out to me pretty quickly.
好的,这就是我解决问题的方法,以防有人遇到同样的问题。
我的异步调用的服务正在返回一个流,并且该流没有在客户端上处理,因此代理没有被释放。
谢谢大家的评论。 他们引导我找到了解决方案,因为没有什么新东西是我以前没听说过的。
Ok, so here's how I fixed the issue in case somebody is facing the same problem.
My services, called asynchronously, were returning a stream and this stream was not being disposed on the client, thus, the proxies were not being freeded.
Thanks everybody for the comments. They kinda led me to the solution since there was nothing NEW I hadn't heard before.
WCF 支持服务限制。 这允许您限制可以同时运行的消息/连接/实例的数量。 在 MSDN 上搜索 ServiceThrottle。
您可以在应用程序配置中指定 ServiceThrottle,如下所示:
如果您怀疑限制是问题所在,请在调试器或转储中查找 ServiceThrottle 对象。 以下是在转储上使用 cdb 的示例:
转储 ServiceHost
转储 ServiceHost 的限制信息
转储会话限制信息
WCF supports service throttling. This allows you to limit how many messages/connections/instances that can run at the same time. Search for ServiceThrottle on MSDN.
You specify your ServiceThrottle in app config like so:
If you suspect throttling is the problem, look for the ServiceThrottle object in the debugger, or in a dump. Here's an example using cdb on a dump:
Dump ServiceHost
Dump Throttling Info for the ServiceHost
Dump Session throttling information