天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
2.3 KiB

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.ServiceModel;
using System.Configuration;
using System.ServiceModel.Channels;
using System.Threading;
namespace OpcProcessWinService
{
partial class OpcProcessService : ServiceBase
{
public OpcProcessService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
// TODO: 在此处添加代码以启动服务。
//装配数据工厂
QMFrameWork.Data.DataFactory.Configure(true);
ParaInit.InitParameter();
NetTcpBinding bind = new NetTcpBinding();
string serverIP = ConfigurationManager.AppSettings["ServerAddressIP"];
Uri uri = new Uri(serverIP);//从配置文D:\项目文件夹\FJC_CC_B9\truck\B9\ServicesCenter\WCF\OpcServerHost\App.config件中读取服务的Url
ServiceHost host = new ServiceHost(typeof(OpcProcessWinService.OpcService), uri);
////if中的代码可以没有,但是如果想利用Svctuil.exe生成代理类的时候,就需要下面的代码,否则将会报错,无法解析元数据
if (host.Description.Behaviors.Find<System.ServiceModel.Description.ServiceMetadataBehavior>() == null)
{
BindingElement metaElement = new TcpTransportBindingElement();
CustomBinding metaBind = new CustomBinding(metaElement);
host.Description.Behaviors.Add(new System.ServiceModel.Description.ServiceMetadataBehavior());
host.AddServiceEndpoint(typeof(System.ServiceModel.Description.IMetadataExchange), metaBind, "MEX");
}
host.Open();
//测试代码,异步调用从服务端向客户端推送信息
//Class1 c1 = new Class1();
//OpcProcessWinService.Class1.DelegateName dn = new OpcProcessWinService.Class1.DelegateName(c1.Test);
//AsyncCallback acb = new AsyncCallback(c1.CallBackMethod);
//dn.BeginInvoke(acb, dn);
}
protected override void OnStop()
{
// TODO: 在此处添加代码以执行停止服务所需的关闭操作。
}
}
}