0

我有一个 WCF 服务接口、一个实现合同的类和一个托管 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 回答