mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 21:10:32 +01:00
Page:
WireMock as a Windows Service
Pages
Admin API Reference
Compatibility WireMock.org
Conflict on Microsoft.CodeAnalysis.CSharp
Cors
Could not load file or assembly RestEase
Development Information
Faults
FluentAssertions
Home
KestrelServerOptions
Mapping
MimeKit and MimeKitLite
MyGet preview versions
Pact
Proxying
References
RegexExtended
Request Matcher FormUrlEncodedMatcher
Request Matchers
Request Matching CSharpCode
Request Matching GraphQLMatcher
Request Matching JsonMatcher
Request Matching JsonPartialMatcher
Request Matching JsonPartialWildcardMatcher
Request Matching JsonPathMatcher
Request Matching MimePartMatcher
Request Matching ProtoBuf
Request Matching Tips
Request Matching
Response Templating
Scenarios and States
Settings
Stubbing
Using HTTPS (SSL)
Using WireMock in UnitTests
Using WireMock.Net.Aspire
Using WireMock.Net.Testcontainers
Webhook
What Is WireMock.Net
WireMock as a (Azure) Web App
WireMock as a Windows Service
WireMock as a standalone process
WireMock as dotnet tool
WireMock commandline parameters
WireMock.Org
Xamarin Could not load file or assembly
Clone
4
WireMock as a Windows Service
Stef Heyenrath edited this page 2020-01-25 09:44:02 +01:00
Table of Contents
It's also possible to wrap WireMock in a Windows Service.
Program.cs
Create a Program.cs with the following content:
public static class Program
{
#region Nested classes to support running as service
public const string ServiceName = "Wiremock.Net.Service";
public class Service : ServiceBase
{
public Service()
{
ServiceName = Program.ServiceName;
}
protected override void OnStart(string[] args)
{
Start();
}
protected override void OnStop()
{
Program.Stop();
}
}
#endregion
private static WireMockServer _server;
static void Main(string[] args)
{
// running as service
if (!Environment.UserInteractive)
{
using (var service = new Service())
{
ServiceBase.Run(service);
}
}
else
{
// running as console app
Start();
Console.WriteLine("Press any key to stop...");
Console.ReadKey(true);
Stop();
}
}
private static void Start()
{
_server = StandAloneApp.Start(new FluentMockServerSettings
{
Urls = new[] { "http://*:9091/" },
StartAdminInterface = true,
ReadStaticMappings = true,
Logger = new WireMockConsoleLogger()
});
}
private static void Stop()
{
_server.Stop();
}
}
When you start the exe file in Visual Studio or from the commandline, the application will behave same like WireMock-as a standalone process.
Example
For a full working example which also provides an Installer and batch-files to
- Install
- Start
- Stop
- Uninstall
the service, see examples/WireMock.Net.Service.
Pages
- Home
- What is WireMock.Net
- WireMock.Org
- References
- Settings
- Admin REST API
- Proxying
- Stubbing
- Webhook
- Request Matching
- Response Templating
- Unit Testing
- Using WireMock
- Advanced
- Errors