REST服务在不活动后进入休眠状态

REST服务在不活动后进入休眠状态

本文介绍了WCF REST服务在不活动后进入休眠状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在常规ASP.NET Web项目中声明的WCF REST服务:

  [ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,IncludeExceptionDetailInFaults = true)]
public class BasicApp

我正在使用它作为我正在构建的iPhone应用程序的服务层,因此我使用优秀的ASIHTTPRequest库请求它。



服务本身工作正常,但当它闲置大约10分钟时,服务似乎进入睡眠状态,这最终会让我在iPhone上出现超时问题。



如果我通过浏览器请求服务它是相同的,但是在30秒左右之后服务醒来然后所有连续请求都非常快。我知道我可以提高iPhone的超时限制,但对于手持设备来说这似乎并不是很好。



我猜它是配置问题。该服务托管在带有IIS 7.5的Win2008R2上



IIS网站配置了自己的AppPool,运行带有集成管道的.NET框架v4。



任何人都知道如何解决这个问题?

解决方案

托管服务的应用程序池定义了空闲时间-out属性(IIS管理控制台中应用程序池的高级设置),默认为20分钟。如果应用程序池在空闲超时内未收到任何请求,则终止服务池的工作进程。在收到新请求后,IIS必须再次启动该进程,该进程必须加载应用程序域和所有相关程序集,编译.svc文件,运行服务主机并处理请求。



解决方案可能会增加空闲超时,但此超时的含义是正确处理服务器资源。如果不需要该过程,则应该停止。另一个丑陋的解决方法是使用一些ping进程(例如服务器上的cron作业或计划任务),它将定期ping同一应用程序中的服务或页面上的某些方法。




I've got a WCF REST service that is declared in a regular ASP.NET web project:

[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true)]
public class BasicApp

I'm using it as a service layer for an iPhone app I'm building, so I'm requesting it using the excellent ASIHTTPRequest library.

The service itself is working just fine, but when it has been idle for approximately 10 minutes the service seems to go to sleep, which in the end gives me timeout issues on the iPhone.

If I request the service through the browser it's the same, but after 30 seconds or so the service "wakes up" and then all consecutive requests are really fast. I know I can up the timeout limit on the iPhone, but that doesn't really seem to work very well for a handheld device.

I'm guessing it's a configuration issue. The service is hosted on Win2008R2 with IIS 7.5

The IIS website is configured with it's own AppPool running .NET framework v4 with Integrated Pipeline.

Anyone has an idea how to resolve this?

解决方案

The application pool hosting your service defines Idle Time-out property (advanced settings of app pool in IIS management console) which defaults to 20 minutes. If no request is received by the app pool within idle timeout the worker processes serving the pool is terminated. After receiving a new request the IIS must start the process again, the process must load application domain and all related assemblies, compile .svc file, run the service host and process the request.

The solution can be increasing idle time-out but the meaning of this time-out is correct handling of server resources. If the process is not needed it should be stopped. Another ugly workaround is using some ping process (for example cron job or scheduled task on the server) which will regularly ping call some method on the service or page in the same application.

Edit: This answer is obsolete - it was written for old IIS versions where "AlwaysRunning" option wasn't available. Please check other answers.

这篇关于WCF REST服务在不活动后进入休眠状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:02