简体   繁体   中英

Wep Api or WCF to run scheduled long-running tasks

I'm developing a Client/Server applications (C#, Winforms for GUI). We have a module to perform tasks to import / export data from the database to other external sources. Activities are managed by users using any client station. The next step will be to allow the schedule to automatically execute tasks (eg, X start time and repetition every hour, daily or weekly or monthly time, and so on). Each tasks allows to import or export a large amount of data with any datasources (excel. access or dbms), therefore they are long-running activities.

Now the DLL that implements this logic is distributed to each client station. This is not a good solution because we have to install all the potential requirements in each client (for example driver ado / oledb / odbc for all managed dbms).

I have to move this logic to the server station. In each client I want to see the tasks progress, stop or start any tasks, or change the schedule table and restart the process.

I'm considering what is the best solution. Realize a Web API or WCF . Probably WCF because service-oriented, but I've seen projects or articles with Web APIs combined with libraries like Quartz or Hangfire. I'm also considering whether it is better to use a Windows service and to host WCF inside it.

What is the best solution? or are there any other solutions I'm not considering? Thank you

EDIT: From any client workstation the user can schedule all tasks to be executed depending by the applied settings (frequence time, repeat each day/week/month). Probably I should use a windows service because when the server machine is automatically switch on, this service must be automatically started and check if there are tasks to run. At the same time the user can decide to run manually any task without schedule it and, in this case, it will be queued and processed when it is his turn. Now I'm thinking to host a WCF service into a Windows service in the server machine. Automatically I will start a background worker to check the scheduled tasks to run. In addition all clients can invoke a method to start one or more tasks. To notify the progress to all clients I'll use Contract Duplex.

You will need to compare between WCF and Web API and Choosing which technology to use according to your requirements.

If you just need HTTP only as transport protocols and Lightweight web-hosted services go with Web API.

And I will recommend Hangfire as it has many features than Windows service like Distributed, Persistent and Also, it's out of the box Dashboard that shows you all your scheduled, processing, succeeded and failed jobs.

Check also this article about Runing Background Tasks in ASP.NET

if this is an internal application and clients are using winforms, behind the scenes you can make gets/posts to web api endpoints -- this allows users to retrieve/export data without having to install database drivers

web api driven imo, not very familiar with windows services, but one of the benefits i'm seeing is that the service can still be running on reboot

feel free to reach out to me directly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM