为什么 WCF 服务每 20 分钟停止工作一次?
我是wcf和多线程的新手,我编写了一个托管在IIS7中的wcf服务,在这个服务中有一个长时间运行的任务(System.Threading.Tasks.Task),它可能会运行20个小时。
但是这个wcf服务总是每20分钟停止工作一次。
当 application_stop 和 application_start 运行时,我让 wcf 向我发送电子邮件。因此,当它开始运行时,我会收到一封电子邮件,然后 20 分钟后,我会收到一封显示服务停止的电子邮件。
我真的不明白为什么会发生这种情况,为什么服务每 20 分钟停止一次。
wcf 服务每 20 分钟停止一次,还是任务线程每 20 分钟停止一次?
IIS7的任何配置都会影响wcf运行时间吗?
我尝试将receiveTimeout设置为一个很大的时间量,并使用asych调用在客户端调用wcf,但这没有帮助。
伙计们,我真的需要帮助,非常感谢。
以下代码属于调用此 wcf 服务的网站
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMailingService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="24.20:31:23.6470000" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:92/MailingService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMailingService" contract="MalingService.IMailingService"
name="BasicHttpBinding_IMailingService" />
</client>
</system.serviceModel>
I am newbie of wcf and mulit-thread, and I write a wcf service hosted in IIS7, in this service there is a long running task (System.Threading.Tasks.Task) which will probably be going to run 20 hours.
But this wcf service always stops to work every 20 minutes.
I make the wcf send email to me when application_stop and application_start is running. Therefore, I receive a email when it start run, and then after 20 minutes, I receive the email show that the service stop.
I really cannot figure out why this happen, why the service stop work every 20 minutes.
Does the wcf services stop every 20 minutes, or the Task thread stop every 20 minutes?
Will any configuration of IIS7 impact wcf running time?
I try to set the receiveTimeout to a every large time amount, and I use asych call to invoke wcf in client side, but this does not make help.
Guys, I really need help, many thanks.
Following code belongs to a website which calls this wcf service
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMailingService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="24.20:31:23.6470000" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:92/MailingService.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMailingService" contract="MalingService.IMailingService"
name="BasicHttpBinding_IMailingService" />
</client>
</system.serviceModel>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
IIS应用程序池空闲默认超时为20分钟。您可以通过以下步骤配置应用程序池空闲超时,这些步骤是我从本文中选择的 - http://technet.microsoft.com/en-us/library/cc771956(WS.10).aspx
正如重新运行所说,IIS 主机并不是最适合您的方案,Windows 服务上的 WAS 将是更好的选择。
IIS application pool idle default timeout is 20 minutes. You can configure application pool idle timeout by the below steps, which I picked from this article - http://technet.microsoft.com/en-us/library/cc771956(WS.10).aspx
As rerun said, IIS host is not the best for your scenario, WAS on a Windows Service would be a better option.
对于托管长时间运行的任务来说,IIS 是一个糟糕的选择。如果正好是 20 分钟,我会认为 iis 正在关闭所有者线程,但这只是猜测。我真的建议迁移到 Windows 服务 WCF 托管环境。
IIS is a poor choice for hosting a long running task. If it is at exactly 20 minutes I would think that iis is shutting down the owner thread but that is speculation. I would really suggest moving to a windows service wcf hosting environment.
我使用廉价的 cron 作业服务每 5 分钟在我的应用程序上触发一个处理程序。这有助于保持池的活力。如果您不想离开 IIS,这是一个快速且“肮脏”的修复方法。
I use a cheap cron job service service to hit a handler on my app every 5 minutes. This helps keep the pool alive. If you don't want to move away from IIS, this is a quick and "dirty" fix.