WCF与Windows服务通信

WCF与Windows服务通信,windows,wcf,service,Windows,Wcf,Service,请问,有人能给我一些建议吗?我创建了一个WCF库,该库通过外部WCF客户端实现作业的端点网络管道。但我不知道如何在不使用WCF客户机-服务器机制的情况下从库中进行数据交换。如何在windows服务中放置或获取运行WCF服务的数据?例如,我想在事件日志中注册WCF错误,或者为服务提供参数,以便为连接到WCF的客户端传输这些错误 在我的项目中,我需要创建Silverlight或WPF客户端,以便在我的工厂中实时进行工业监控。为此,我想在我的OPC客户端上使用wcf服务中的双工通道 我的Windows

请问,有人能给我一些建议吗?我创建了一个WCF库,该库通过外部WCF客户端实现作业的端点网络管道。但我不知道如何在不使用WCF客户机-服务器机制的情况下从库中进行数据交换。如何在windows服务中放置或获取运行WCF服务的数据?例如,我想在事件日志中注册WCF错误,或者为服务提供参数,以便为连接到WCF的客户端传输这些错误

在我的项目中,我需要创建Silverlight或WPF客户端,以便在我的工厂中实时进行工业监控。为此,我想在我的OPC客户端上使用wcf服务中的双工通道

我的Windows服务项目中有两个对象。一个对象是OPC客户端和数据库客户端。如果我用代码创建这个对象,一切都很好。另一个对象是WCF服务库,它具有用于外部连接到此服务的net.pipe绑定。好啊我在代码中定义:

// window service class   
 public partial class SyncSiemensService : ServiceBase
    {
        private OpcServiceClass opcServer = new OpcServiceClass();

        public SyncSiemensService()
        {
        InitializeComponent();
        }

    protected override void OnStart(string[] args)
    {
              // OPC client- database client object
              opcServer.Start();

             // WCF interface for external communication
             // with this windows service
              using (ServiceHost host = new ServiceHost(typeof(DuplexPipeWcfService)))
                         {
                             host.Open();
                             eventLog.WriteEntry("<Bla-Bla-Bla", EventLogEntryType.Information);
                         }
    }
}
字符串行-opc对象的外部数据

还有他的回电

public interface IDuplexPipeWcfServiceCallback
{
    [OperationContract(IsOneWay = true)]
    void ActualValuesUpdate(WcfDuplexActualValues value);
}
但“WcfDuplexActualValues值”在矿井赋存中-数据来自OPC对象,用于WCF中的外部连接。现在我不知道,如果不使用opc对象和WCF服务库之间的客户端服务通信,如何从opc对象检索数据


非常感谢

您的OnStart方法打开主机,然后立即再次关闭

 public partial class SyncSiemensService : ServiceBase
    {
        private ServiceHost _host;
        private OpcServiceClass opcServer = new OpcServiceClass();

        public SyncSiemensService()
        {
        InitializeComponent();
        }

 protected override void OnStart(string[] args)
 {
          // OPC client- database client object
          opcServer.Start();

         // WCF interface for external communication
         // with this windows service
          _host = new ServiceHost(typeof(DuplexPipeWcfService)))

         _host.Open();
        eventLog.WriteEntry("<Bla-Bla-Bla", EventLogEntryType.Information);

 }

}
公共部分类SyncSiemensService:ServiceBase
{
私有服务主机_主机;
私有OpcServiceClass opcServer=新OpcServiceClass();
公共同步服务()
{
初始化组件();
}
启动时受保护的覆盖无效(字符串[]args)
{
//OPC客户端-数据库客户端对象
optserver.Start();
//用于外部通信的WCF接口
//使用此windows服务
_主机=新服务主机(类型(DuplexPipeWcfService)))
_host.Open();

WriteEntry(您的OnStart方法打开主机,然后立即再次关闭它

 public partial class SyncSiemensService : ServiceBase
    {
        private ServiceHost _host;
        private OpcServiceClass opcServer = new OpcServiceClass();

        public SyncSiemensService()
        {
        InitializeComponent();
        }

 protected override void OnStart(string[] args)
 {
          // OPC client- database client object
          opcServer.Start();

         // WCF interface for external communication
         // with this windows service
          _host = new ServiceHost(typeof(DuplexPipeWcfService)))

         _host.Open();
        eventLog.WriteEntry("<Bla-Bla-Bla", EventLogEntryType.Information);

 }

}
公共部分类SyncSiemensService:ServiceBase
{
私有服务主机_主机;
私有OpcServiceClass opcServer=新OpcServiceClass();
公共同步服务()
{
初始化组件();
}
启动时受保护的覆盖无效(字符串[]args)
{
//OPC客户端-数据库客户端对象
optserver.Start();
//用于外部通信的WCF接口
//使用此windows服务
_主机=新服务主机(类型(DuplexPipeWcfService)))
_host.Open();

eventLog.WriteEntry(我不能100%确定我是否正确理解了您的问题,但我认为您正在尝试在OpcServiceClass实例和DuplexPipeWcfService之间交换数据,而不使用WCF

通过自己创建实例,您可以使用另一种方式托管服务:

protected override void OnStart(string[] args)
 {
          // OPC client- database client object
          opcServer.Start();

          var serviceInstance = new DuplexPipeWcfService();
          _host = new ServiceHost(serviceInstance)

         _host.Open();
        eventLog.WriteEntry("<Bla-Bla-Bla", EventLogEntryType.Information);
 }

我不能100%确定我是否正确理解了您的问题,但我认为您正在尝试在不使用WCF的情况下在OpcServiceClass实例和DuplexPipeWcfService之间交换数据

通过自己创建实例,您可以使用另一种方式托管服务:

protected override void OnStart(string[] args)
 {
          // OPC client- database client object
          opcServer.Start();

          var serviceInstance = new DuplexPipeWcfService();
          _host = new ServiceHost(serviceInstance)

         _host.Open();
        eventLog.WriteEntry("<Bla-Bla-Bla", EventLogEntryType.Information);
 }

是否可以添加有关如何托管服务的其他信息?在WAS中,在Windows服务中自托管?是。我使用Windows服务托管Wcf服务。是否可以添加有关如何托管服务的其他信息?在WAS中,在Windows服务中自托管?是。我使用Windows服务托管Wcf服务。是。我的代码出错。谢谢。但是我如何才能将数据从opcServer发送到_主机并接收回来。是的。我的代码出错。谢谢。但是我如何才能将数据从opcServer发送到_主机并接收回来。
OpcServiceClass.Start(IDuplexPipeWcfServiceCallback wcfService)