schangxiang@126.com
2025-09-09 3d8966ba2c81e7e0365c8b123e861d18ee4f94f5
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using siemensSapService.orm;
 
namespace siemensSapService
{
    public partial class Service1 : ServiceBase
    {
        #region 开启服务流程
        //1.cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
        //2.InstallUtil.exe  E:\ximenzi\wms\siemensSapService\siemensSapService\bin\Debug\siemensSapService.exe 找到自己的服务地址
        //启动服务 net start IWareCC
        //停止服务 net stop  IWareCC
        //卸载服务 sc delete IWareCC
        #endregion
        public Service1()
        {
            InitializeComponent();
        }
        ServiceHost aspService;//声明WCF变量
        protected override void OnStart(string[] args)
        {
            aspService = new ServiceHost(typeof(siemensSapService.wcf.sapWcf));
            aspService.Open();//开启wcf服务
            
        }
 
        protected override void OnStop()
        {
            CloseWcf(aspService);//关闭WCF服务
          
        }
 
 
 
        ///<summary>
        ///关闭WCF
        ///</summary>
        ///<param name="host">需要关闭的WCF</param>
        private void CloseWcf(ServiceHost host)
        {
            if (host != null)
            {
                host.Close();
            }
        }
 
        /// <summary>
        /// 关闭线程
        /// </summary>
        /// <param name="thread">需要关闭的线程</param>
        private void CloseThread(Thread thread)
        {
            if (thread != null)
            {
                thread.Abort();
            }
          
        }
 
    }
}