-
Notifications
You must be signed in to change notification settings - Fork 16
/
Service1.cs
42 lines (37 loc) · 1.12 KB
/
Service1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Web.Http;
using System.Web.Http.SelfHost;
namespace WebApi.Service.Print
{
public partial class PrintApiService : ServiceBase
{
private HttpSelfHostServer _server;
private readonly HttpSelfHostConfiguration _config;
public const string ServiceAddress = "http://localhost:599";
public PrintApiService()
{
InitializeComponent();
_config = new HttpSelfHostConfiguration(ServiceAddress);
_config.Routes.MapHttpRoute("Default",
"{controller}/{id}",
new { controller = "Start", id = RouteParameter.Optional });
}
protected override void OnStart(string[] args)
{
_server = new HttpSelfHostServer(_config);
_server.OpenAsync();
}
protected override void OnStop()
{
_server.CloseAsync().Wait();
_server.Dispose();
}
}
}