WebServer.cs
1.1 KB
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.ServiceModel;
using System.ServiceModel.Web;
namespace ScanCodeServer
{
public static class WebServer
{
private static WebServiceHost _serviceHost;
public static bool IsOpen { private set; get; }
public static void Open(string url)
{
try
{
WebWork service = new WebWork();
_serviceHost = new WebServiceHost(service, new Uri(url));
_serviceHost.Open();
Common.log.Info("Web服务已开启,URL=" + url);
IsOpen = true;
}
catch (Exception ex)
{
Common.log.Error("WebService Open", ex);
IsOpen = false;
}
}
public static void Close()
{
if (_serviceHost != null)
{
if (_serviceHost.State != System.ServiceModel.CommunicationState.Faulted)
_serviceHost.Close();
}
Common.log.Info("Web服务已关闭");
}
}
}