【问题标题】:Events don't get hit WCF Service implementation事件未命中 WCF 服务实现
【发布时间】:2012-07-13 23:30:40
【问题描述】:

我有一个 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,它是一个单例实例。感谢您就我没有引用正确实例的原因提供的任何帮助/见解。

【问题讨论】:

    标签: c# wcf event-handling servicecontract


    【解决方案1】:

    经过大量阅读,我注意到我在客户端代码中的错误:

                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 调用服务上的方法时,会引发所有事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      • 2010-12-25
      • 2014-11-09
      • 2012-07-16
      相关资源
      最近更新 更多