I am new to .NET and web services. My aim is to create a .asmx webservice in C# which will invoke itself in every 12 hours automatically. So, there won't be anybody invoking its methods but it will invoke itself regularly. I am confused about how to do this with .NET webservices.
-
Sounds like very strange design. Why do you want it to be web service at all? Web service runs only when it is called, so with your design, it should be running 24 hours per day just to be able to call itself.. to run itself.. You must think it again. For example, you can trigger calling web service by Windows Task Scheduler.Konrad Kokosa– Konrad Kokosa2014-07-02 10:33:10 +00:00Commented Jul 2, 2014 at 10:33
-
Well I want also clients to reach it but its main duty is to update database in 12 hours.birdcage– birdcage2014-07-02 10:37:19 +00:00Commented Jul 2, 2014 at 10:37
-
2Then create database job or windows task scheduler task.Konrad Kokosa– Konrad Kokosa2014-07-02 10:39:09 +00:00Commented Jul 2, 2014 at 10:39
-
but database will be updated by gathering some data from another website. my service will get data in 12 hours from another website and update db.birdcage– birdcage2014-07-02 10:40:42 +00:00Commented Jul 2, 2014 at 10:40
-
5Create window service which will call web service with regarding parameter, if any, also you can define it for some time span like after 5 min or 12 hour your service will call and do the required operation. i did such so many timeSunil Devre– Sunil Devre2014-07-02 10:50:24 +00:00Commented Jul 2, 2014 at 10:50
4 Answers
My suggestion would be to use either a windows service or a console app scheduled to run every 12 hours by the host system's scheduling software (Windows Task Scheduler, cron, etc.).
Here is an interesting discussion on the similar requirement like yours to run a method at regular intervals and David has given various options in there.
Comments
You can Create and schedule Jobs that will invoke every 12 Hours or say at 12am and 12pm everyday using Quartz.NET
You can create your Cron expression using :
"InitializeScheduler()" calls the job where JobType => typeof(YourClass) with Execute() holding the required method to execute. And cron expression will identify and schedule its time
Please follow the links for further understanding on the implementation :
Works best for my requirements
Comments
If it's a public webservice (or one available on the Internet, in any case) you can check out the new Azure Scheduler to invoke your webservice on a regular basis.