Timer on Website to activate Web Service calls eve

2019-03-02 12:41发布

If I want to run a series of Web service calls every hour. How can I do that from my Web Server?

I'm guessing there is a timer which needs to be deployed somewhere so it counts down and when the time is up, it would consume those Web service again and retrieve the returned XML data to be stored in database. Then the timer resets again.

5条回答
成全新的幸福
2楼-- · 2019-03-02 13:12

Another approach is to use an IIS Auto-Start website contaning your Windows Service logic. The IIS Auto-start is supierior to using a Windows Service as it contains all the IIS application hosting logic including auto-restart, and aggressive resource management. A poorly written Windows Service can take down a Server but it takes a lot for an ASP.net IIS hosted application to take down its host (its almost impossible).

Auto Starting Websites

查看更多
唯我独甜
3楼-- · 2019-03-02 13:13

If you want to do this from within an ASP.NET web application, check out the Quartz.NET Job Scheduler, it's perfect for this sort of thing.

Otherwise you could run a separate application as Windows Service with a timer, or a console application as a Windows scheduled task.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-03-02 13:13

You can use System.Threading.Timer class with application Start event in global.asax:

protected static Timer timer;

protected void Application_Start(Object sender, EventArgs e)
{
    timer = new Timer(MyRoutineToCall, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
}

protected void MyRoutineToCall(Object state)
{
    // do your stuff here
}
查看更多
Ridiculous、
5楼-- · 2019-03-02 13:15

Why not just use cron? Cron is set up to do just this sort of thing.

查看更多
虎瘦雄心在
6楼-- · 2019-03-02 13:16

The Windows Task Scheduler may be what you need.

查看更多
登录 后发表回答