简体   繁体   中英

Convert .NET Windows Service to Azure Web Job

I have a .NET Windows Service and would like to convert to Azure Web Jobs. Please let me know if I can host it as an Azure Web Jobs or a recommendation to convert.

You can't unfortunately directly host Windows Services in Azure PaaS solutions, unless it is built using TopShelf . Your options are:

  1. Use Azure Virtual Machine to host the Windows Service
  2. Convert the Windows Service so that it can be hosted in Azure PaaS

For conversion the simplest plan is usually the following:

  1. Create a new .NET Console application
  2. Move all the logic from your Windows Service into the .NET Console app
  3. Make the console app work so that once you run it, it executes the logic and exits. So no while loop which keeps the console app running forever.
  4. Publish the console app as a Web Job. You can publish it directly from Visual Studio or upload it using Azure Portal.
  5. Schedule the web job to execute when needed.

You can skip the conversion part if your service uses TopShelf.

If your Windows Service is doing something else than just executing simple logic, for example it hosts WCF or Web Api, the easiest option usually is to convert it into a web app.

You could convert your service to a console application and run it as a continuous web job. Simply put a run.cmd inside the same directory that will start your .exe file (see Run Background tasks with WebJobs in Azure App Service ).

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