1

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.

leppie
  • 115,091
  • 17
  • 196
  • 297
birdcage
  • 2,638
  • 4
  • 35
  • 58
  • 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 Jul 02 '14 at 10:33
  • Well I want also clients to reach it but its main duty is to update database in 12 hours. – birdcage Jul 02 '14 at 10:37
  • 2
    Then create database job or windows task scheduler task. – Konrad Kokosa Jul 02 '14 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 Jul 02 '14 at 10:40
  • Still, you solution for web service calling itself is not possible. – Konrad Kokosa Jul 02 '14 at 10:45
  • 5
    Create 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 time – Sunil Devre Jul 02 '14 at 10:50
  • This is the best answer so far. Thanks for that. @SunilDevre – birdcage Jul 02 '14 at 12:21
  • @SunilDevre a windows Service seems like overkill - a console app that calls the web service could be scheduled by Windows without the overhead of a service (and having to program the timeer, start, stop, pause, etc.) – D Stanley Jul 02 '14 at 18:09

4 Answers4

1

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 :

http://www.cronmaker.com/

"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 :

http://www.quartz-scheduler.net/

http://geekswithblogs.net/TarunArora/archive/2012/11/17/quartz.net-writing-your-first-hello-world-job.aspx

http://simplequartzschedulerincsharp.blogspot.in/

Works best for my requirements

cosmoloc
  • 2,884
  • 5
  • 29
  • 48
1

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.

Community
  • 1
  • 1
Dennis R
  • 3,195
  • 1
  • 19
  • 24
1

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.

Dan Esparza
  • 28,047
  • 29
  • 99
  • 127
0

You Can create windows service and setup to call after every 12 hours you can easily find how to create and setup windows service

Samir
  • 36
  • 4