0

誰かアドバイスしてもらえますか?外部WCFクライアントを使用してジョブのエンドポイントネットパイプを実現するWCFライブラリを作成します。libをWindowsサービスに配置しました。しかし、WCFクライアントサーバーメカニズムを使用せずにライブラリからデータ交換を行う方法がわかりません。Windowsサービスで実行中のWCFサービスからデータを配置または取得するにはどうすればよいですか?たとえば、WCFエラーをイベントログに登録したり、WCFに接続されているクライアントに転送するためのパラメーターをサービスに提供したりします。

私のプロジェクトでは、プラントの産業用監視用にSilverlightまたはWPFクライアントをリアルタイムで作成する必要があります。このために、OPCクライアントのwcfサービスでデュプレックスチャネルを使用したいと思います

Windowsサービスプロジェクトに2つのオブジェクトがあります。1つのオブジェクトはOPCクライアントとデータベースクライアントです。このオブジェクトをコードで作成すると、すべてが正常に機能します。もう1つのオブジェクトは、このサービスへの外部接続用のnet.pipeバインディングを備えたWCFサービスライブラリです。Ok。私は自分のコードで次のように定義します。

// 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);
                         }
    }
}

WCFサービス

    [OperationContract(IsOneWay = true)]
    void GetActValuesFromLine(string line);

文字列行-opcオブジェクトの外部データ

と彼のコールバック

public interface IDuplexPipeWcfServiceCallback
{
    [OperationContract(IsOneWay = true)]
    void ActualValuesUpdate(WcfDuplexActualValues value);
}

しかし、私のオカレンスの「WcfDuplexActualValuesvalue」-WCFの外部接続用のOPCオブジェクトからのデータ。そして今、私は、OPCオブジェクトとWCFサービスライブラリ間のクライアントサービス通信を使用せずに、opcオブジェクトからデータを取得する方法を知りません。

どうもありがとう

4

2 に答える 2

2

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);

 }

}

開いたままにし、サービスをシャットダウンするときにのみ破棄する必要があります。

于 2012-08-29T13:15:50.370 に答える
1

あなたの質問を正しく理解しているかどうかは 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);
 }

これで両方のインスタンスが作成され、参照を渡すことでデータを交換できます。たとえば、OpcServiceClass のコンストラクターを次のように変更できます。

protected override void OnStart(string[] args)
 {
          var serviceInstance = new DuplexPipeWcfService();
          opcServer.Start(serviceInstance );

          _host = new ServiceHost(serviceInstance)

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

IDuplexPipeWcfServiceCallback タイプのオブジェクトを取得するには、OpcServiceClass.Start() メソッドのシグネチャを変更するだけで済みます。このようにして、WCF オーバーヘッドなしで DuplexPipeWcfService と通信できます。

署名を次のように変更します。

OpcServiceClass.Start(IDuplexPipeWcfServiceCallback wcfService)
于 2012-08-29T16:22:26.590 に答える