Windows hosted services




















You can configure a Windows service process to start automatically when the computer starts, making it a suitable hosting environment for "always on" applications. For more information about Windows service applications, see Windows Service Applications.

In particular, WCF services are long-running server executables that do not interact directly with the user and therefore do not implement any form of user interface.

As such, hosting WCF services inside of a Windows service application is one option for building robust, long-running, WCF applications. You should consider using Windows service applications under the following conditions:.

Your application requires explicit activation. For example, you should use Windows services when your application must start automatically when the server starts instead of being dynamically started in response to the first incoming message. The process that hosts your application must remain running once started. A folder for the ContosoWorker app is created automatically when the command is executed.

An app based on the Worker Service template uses the Microsoft. Worker SDK and has an explicit package reference to the Microsoft. Hosting package. For example, see the sample app's project file BackgroundTasksSample. For web apps that use the Microsoft. Web SDK, the Microsoft. Hosting package is referenced implicitly from the shared framework. An explicit package reference in the app's project file isn't required. The IHostedService interface defines two methods for objects that are managed by the host:.

StartAsync CancellationToken contains the logic to start the background task. StartAsync is called before :. StartAsync should be limited to short running tasks because hosted services are run sequentially, and no further services are started until StartAsync runs to completion. The cancellation token has a default five second timeout to indicate that the shutdown process should no longer be graceful.

When cancellation is requested on the token:. However, tasks aren't abandoned after cancellation is requested—the caller awaits all tasks to complete. If the app shuts down unexpectedly for example, the app's process fails , StopAsync might not be called.

Therefore, any methods called or operations conducted in StopAsync might not occur. The hosted service is activated once at app startup and gracefully shut down at app shutdown. If an error is thrown during background task execution, Dispose should be called even if StopAsync isn't called.

BackgroundService is a base class for implementing a long running IHostedService. ExecuteAsync CancellationToken is called to run the background service. The implementation returns a Task that represents the entire lifetime of the background service. The starter Personal plan may only support one website, but you're allowed unlimited subdomains, emails, MySQL and Microsoft SQL Server databases, and unmetered bandwidth and disk space. NET up to 4. This won't matter to everyone, but check your technical Windows requirements before you sign up.

HostGator's dedicated plans are a little more up-to-date, though still lagging behind some of the competition, with Windows Server R2, IIS 8. NET from 2. Be sure to carefully check the small print, though — you might have to sign up for three years to get these prices, and large introductory discounts mean that you could pay more than double on renewal.

Liquid Web is a popular provider of high-end professional web hosting services, and its current range includes some very capable Windows products. The company's Cloud VPS range hosts your web space across multiple devices to improve performance and scalability, delivering what Liquid Web claims is the "fastest managed VPS hosting on the planet". Unusual touches include a choice of SQL Server versions.

For even more control, you could opt for one of Liquid Web's Private Cloud Servers, although these are primarily made for organizations considering the price. These give you all the power of a Cloud Dedicated Server, but also allow for creating, managing and using custom VPS instances separate virtual servers. Liquid Web may charge a Windows license fee on top of that, but you'll only pay once per Cloud Server. This allows you to create as many Windows-based VPS instances as you need, at no extra cost.

Interestingly, if you remove all Windows instances then the license fee will no longer be charged, a handy money-saver for users who only need Windows support occasionally. Whatever product you choose can be fully managed by Liquid Web's excellent support team, another company highlight.

The ASP. To use the template as a basis for a Windows Service app:. Use the Worker Service worker template with the dotnet new command from a command shell. In the following example, a Worker Service app is created named ContosoWorker. A folder for the ContosoWorker app is created automatically when the command is executed.

The app requires a package reference for Microsoft. UseWindowsService is called when building the host. If the app is running as a Windows Service, the method:.

NET Core 2. For information and advice on deployment scenarios, see. NET Core application deployment. If the service only executes background tasks for example, hosted services , specify the Worker SDK in the project file:.

Framework-dependent deployment FDD relies on the presence of a shared system-wide version of. NET Core on the target system. If using the Web SDK , a web. To disable the creation of the web. Self-contained deployment SCD doesn't rely on the presence of a shared framework on the host system. The runtime and the app's dependencies are deployed with the app. For more information, see. To create a user account for a service, use the New-LocalUser cmdlet from an administrative PowerShell 6 command shell.

Provide a strong password when prompted. For more information, see Microsoft. LocalAccounts and Service User Accounts.

An alternative approach to managing users when using Active Directory is to use Managed Service Accounts. Use PowerShell commands to register a service. From an administrative PowerShell 6 command shell, execute the following commands:. Services that interact with requests from the Internet or a corporate network and are behind a proxy or load balancer might require additional configuration. For more information, see Configure ASP. NET Core to work with proxy servers and load balancers.

By default, ASP. Use of the ASP. The system32 folder isn't a suitable location to store a service's files for example, settings files. Use one of the following approaches to maintain and access a service's assets and settings files.



0コメント

  • 1000 / 1000