0

私は WCF Service インターフェイス、コントラクトを実装するクラス、およびホスティングの winforms アプリケーションを持っています。これにより、WCF サーバーに接続するワーカー プロセスが開始され、イベントがトリガーされます。クライアント ワーカー プロセスでは、メソッドの呼び出しに問題はありません。続いて、添付されたイベント ハンドラーが Windows フォーム アプリケーション内でも呼び出されることを期待していますが、これは発生していません。

                    xWCFService xWCFService = new xWCFService();
                    xWCFService.eventWorkerProcessStart += new EventHandler<WorkerProcessProgressChangedEventArgs>(xWCFService_eventWorkerProcessStart);
                    xWCFService.eventWorkerProcessStop += new EventHandler<WorkerProcessProgressChangedEventArgs>(xWCFService_eventWorkerProcessStop);
                    xWCFService.eventWorkerProcessUpdateProgress += new EventHandler<WorkerProcessProgressChangedEventArgs>(xWCFService_eventWorkerProcessUpdateProgress);
                    xWCFService.eventWorkerProcessError += new EventHandler<WorkerProcessProgressChangedEventArgs>(xWCFService_eventWorkerProcessError);


                    ServiceHost xServiceHost = new ServiceHost(xWCFService, new Uri(serviceAddress));

                    xServiceHost.AddServiceEndpoint(typeof(IxWCFServiceContract), new NetTcpBinding(), address);
                    xServiceHost.Open();

Service クラスのインスタンスを servicehost に渡していますが、これはシングルトン インスタンスです。正しいインスタンスを参照していない理由について提供できるヘルプ/洞察に感謝します。

4

1 に答える 1

0

よく読んだ後、クライアント側のコードに間違いがあることに気づきました。

            static xWCFService xwcfService = new xWCFService();

           ....
       {
            EndpointAddress endPoint = new EndpointAddress(new Uri(string.Format(xWCFServerBaseAddress, address) + address));
            Binding binding = new NetTcpBinding();
            xChannelFactory = new ChannelFactory<IxWCFServiceChannel>(binding, endPoint);
            xChannelFactory.Open();
            xServiceChannel = xChannelFactory.CreateChannel();
            xServiceChannel.Open();

            **xwcfService.WorkerProcessStartedParsing(strGuidClientIdentifier);**

この最後の行は私の間違いでした。サービス実装クラスのインスタンスを介してサービスの呼び出しを呼び出していました。xServiceChannelを使用してサービスのメソッドを呼び出すと、すべてのイベントが発生しました。

于 2012-07-14T23:08:33.653 に答える