WebService.cs
1.3 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
43
44
45
46
47
using BLL;
using System;
using System.ServiceModel.Web;
namespace SmartScan
{
public static class WebService
{
private static WebServiceHost _serviceHost;
public static bool IsOpen { private set; get; }
public static void Open()
{
try
{
string url = BLLCommon.config.WebService;
if (string.IsNullOrWhiteSpace(url))
{
Model.LogNet.log.Info("WebService没有配置,不开启");
return;
}
WebCallWork service = new();
_serviceHost = new(service, new Uri(url));
_serviceHost.Open();
Model.LogNet.log.Info("Web服务已开启,URL=" + url);
IsOpen = true;
}
catch (Exception ex)
{
Model.LogNet.log.Error("Open", ex);
IsOpen = false;
}
}
public static void Close()
{
if (_serviceHost != null)
{
if (_serviceHost.State != System.ServiceModel.CommunicationState.Faulted)
_serviceHost.Close();
}
Model.LogNet.log.Info("Web服务已关闭");
}
}
}