WebService.cs
2.8 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Runtime.Serialization;
using System.ServiceModel.Activation;
using System;
namespace BLL
{
[ServiceContract(Name = "Services")]
internal interface IWebService
{
[OperationContract]
[WebGet(UriTemplate = "CreateEmptyRecycleTask?emptyStation={line}", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
Result CreateEmptyRecycleTask(string line);
}
[DataContract]
internal class Result
{
[DataMember]
public string Succeed { get; set; }
[DataMember]
public string ResultData { get; set; }
[DataMember]
public string ErrorMessage { get; set; }
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single, IncludeExceptionDetailInFaults = true)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
internal class ClsWebService : IWebService
{
internal ClsWebService()
{
}
public Result CreateEmptyRecycleTask(string line)
{
AGVControl.Common.log.Info("WebService Request emptyStation=" + line);
Result res;
if (AGVControl.Common.agvProductionLine.TryGetValue(line, out string value))
{
res = new Result() { Succeed = "true", ResultData = "", ErrorMessage = "" };
AGVControl.Common.log.Info("WebService Response OK");
//加到任务
AGVControl.Common.linePlace.Add(value);
}
else
{
res = new Result() { Succeed = "false", ResultData = "", ErrorMessage = "Not find " + line };
AGVControl.Common.log.Info("WebService Response false");
}
return res;
}
}
public class WebService
{
private WebServiceHost _serviceHost;
public void Open(string url)
{
try
{
ClsWebService service = new ClsWebService();
_serviceHost = new WebServiceHost(service, new Uri(url));
_serviceHost.Open();
AGVControl.Common.log.Info("Web服务已开启");
}
catch (Exception ex)
{
AGVControl.Common.log.Error("Open", ex);
}
}
public void Close()
{
try
{
_serviceHost.Close();
AGVControl.Common.log.Info("Web服务已关闭");
}
catch (Exception ex)
{
AGVControl.Common.log.Error("Close", ex);
}
}
}
}