Search code examples
wcf-data-services

recurring action in WCF Data service


I have a WCF Data Services web service and there is an some code that should be executed every 10 minutes. I wonder how can I achieve that without affecting the performance of the service.

I would be grateful too if you could give me some general tips to increase the performance of the service.


Solution

  • WCF Data Services doesn't really have any facilities to do that, it's merely concerned about interfacing OData requests. Hence, the solution you're looking for is most likely host-dependent.

    If you're using ASP.NET/IIS, there are some ways to schedule asynchronous operations. While I've never personally tried to make such recurrent operations, I imagine it would be feasible. Look at things like QueueBackgroundWorkItem, and consider using a timer in between operations.

    That being said, ASP.NET and IIS are fundamentally about responding to HTTP requests as well, and hence are not (in my opinion) the right place to schedule and run recurring tasks. If your hosting provider doesn't allow access to the base machine, you might not have a choice, though you should still consider whether it would be possible to launch the operation from a different server altogether.

    Now as for the technology to use for that kind of functionality; I'd say the Windows Server scheduler is as good a place as any to start (or *nix cron), though you may find all kinds of services to do that on all kinds of platforms (not just dedicated machines). For example, the Azure platform has WebJobs which allow you to schedule HTTP requests on Azure Web Sites, if that works for you.

    You may find this article interesting, as it refers to these methods.