Woof.Service
1.0.0
Prefix Reserved
This package was Windows only, new Woof.ServiceInstaller is compatible with both Windows and Linux. Also it's much easier to use and compatible with modern dependencies.
dotnet add package Woof.Service --version 1.0.0
NuGet\Install-Package Woof.Service -Version 1.0.0
<PackageReference Include="Woof.Service" Version="1.0.0" />
<PackageVersion Include="Woof.Service" Version="1.0.0" />
<PackageReference Include="Woof.Service" />
paket add Woof.Service --version 1.0.0
#r "nuget: Woof.Service, 1.0.0"
#:package Woof.Service@1.0.0
#addin nuget:?package=Woof.Service&version=1.0.0
#tool nuget:?package=Woof.Service&version=1.0.0
Woof.Service quick usage guide
To create Windows Service with WCF REST API using Woof.Service
Start new
.NET Framework Console Application.Edit
Application/Assembly Information, fill every fied, make sureTitleandProductfields are not the same.The
Titlefield will be used as service display name, theProductas the service strong name,Companyas Windows log name.Get
Woof.ServiceInstall-Package Woof.Service -Version 1.0.2Create new
ServiceInstaller.csfile in main directory with following content:using Woof.ServiceEx; public sealed class ServiceInstaller : ServiceInstallerEx { } public sealed class ServiceProcessInstaller : ServiceProcessInstallerEx { }Create
Messagesdirectory.Create empty
Service.resxfile.Create
ServiceUriproperty (inApplicationscope) inProperties.Settings, set it to something like "http://localhost:8080/myService".Create sample web service class
WebService.cs:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ServiceModel; using System.ServiceModel.Web; using Woof.ServiceEx.Wcf; using System.IO; namespace ServiceTest { [ServiceContract] class WebService { [OperationContract, WebGet(UriTemplate = "hello")] public string HelloWorld(string sessionName) { return "Hello world!"; } } }Create main service class
Service.csextendingServiceBaseEx:using System; using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; using Woof.ServiceEx; using Woof.ServiceEx.Wcf; namespace ServiceTest { class Service : ServiceBaseEx { public new static Service Instance => ServiceBaseEx.Instance as Service; private WebServiceHost<WebService> Host; public Service() : base(Messages.Service.ResourceManager) { } protected override void OnStart(string[] args) { base.OnStart(args); Host = new WebServiceHost<WebService>(new Uri(Properties.Settings.Default.ServiceUri)); Host.Open(); } protected override void OnStop() { base.OnStop(); Host?.Close(); Host = null; } } }Edit
Program.csfile like this:using Woof.ServiceEx; namespace ServiceTest { class Program { static int Main(string[] args) => new ServiceConsole<Service>(args).ReturnValue; } }Compile...
Restart Visual Studio in Administrator mode (required for service installation and WCF hosting).
Test with
-tswitch, install with-iswitch, uninstall with-uswitch. More help with-hswitch.Refer to
Woof.ServiceEx.ServiceBaseEx.Signal()andWoof.ServiceEx.ServiceBaseEx.WriteEvent()XML documentation to write to the service log correctly.Use
Messages\Service.resxresource file to define standard localized event messages like:Name Value Comment I1001 My dummy info event message W2001 My dummy warning event message E3001 My dummy error event message Use
ResXManagerextension to localize the messages.The event names must consist of severity character being one of
'I','W', or'E'and numeric event identifier.The message values can contain
{0}...{n}parameter placeholders in this exact format.The pre-configured event messages are available via
Signal()method.For all other events use
WriteEvent()method with0as event identifier.RTFM (Read The Friendly Manual, meaning XML documentation) to explore advanced features like
CORSsupport.WARNING: Consider
CurrentDirectoryis set toC:\Windows\System32when refering to any files.To refer to a file in service
exedirectory use following:var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);Note the service started as
LocalSystemuser cannot use GUI, however user interaction is possible using inter-process communication available inWoof.Corepackage,Woof.SystemExnamespace.WPForWinFormsapplication can interact with the service.
Q&A
- Is there a easier or simpler way of doing this?
- Nope. Not for now but stay tuned, maybe a sample package / project template will be released soon.
- How safe and stable are those libraries?
- Tested for years on real production server environments.
- .NET Core...?
- Nope. Windows OS (desktop / server) is required.
Disclaimer
Installing a Windows Service on a server is a serious thing. Be warned you can do some serious damage to the system using this code. Get a testing environment (like your local PC) to test the service properly before deploying to production. CodeDog Ltd. is not responsible for any damage caused using this library. You are.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net471 is compatible. net472 was computed. net48 was computed. net481 was computed. |
-
- System.Security.AccessControl (>= 4.5.0)
- System.Security.Principal.Windows (>= 4.5.0)
- Woof.Core (>= 1.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|
Initial release.