public bool Start(HostControl hostControl) { #region Настройка из кода //_ordersHost = ServiceHostHelper.ConfigureServiceHost(_ordersHost, ContractDescription.GetContract(typeof(IOrderService)), String.Empty); //_productsHost = ServiceHostHelper.ConfigureServiceHost(_productsHost, ContractDescription.GetContract(typeof(IProductService)), String.Empty); //_categoriesHost = ServiceHostHelper.ConfigureServiceHost(_categoriesHost, ContractDescription.GetContract(typeof(ICategoryService)), String.Empty, true); #endregion var ordersResetEvent = new ManualResetEvent(false); var catResetEvent = new ManualResetEvent(false); var prodResetEvent = new ManualResetEvent(false); _ordersHost.BeginOpen(ar => { _ordersHost.EndOpen(ar); ordersResetEvent.Set(); }, null); _productsHost.BeginOpen(ar => { _productsHost.EndOpen(ar); prodResetEvent.Set(); }, null); _categoriesHost.BeginOpen(ar => { _categoriesHost.EndOpen(ar); catResetEvent.Set(); }, null); WaitHandle.WaitAll(new WaitHandle[] { ordersResetEvent, catResetEvent, prodResetEvent }); return(true); }
/// <summary> /// 启动监听 /// </summary> /// <returns>公告监听器接口</returns> public IAnnouncementMonitor <T> Start() { if (announcementService != null && announcementServiceHost.State != CommunicationState.Closed) { throw new InvalidProgramException("This announcement service has been opened."); } this.announcementService = new AnnouncementService(); // add event handlers this.announcementService.OnlineAnnouncementReceived += new EventHandler <AnnouncementEventArgs>(this.OnOnlineAnnouncement); this.announcementService.OfflineAnnouncementReceived += new EventHandler <AnnouncementEventArgs>(this.OnOfflineAnnouncement); // create the service host with a singleton this.announcementServiceHost = new ServiceHost(this.announcementService); // add the announcement endpoint this.announcementServiceHost.AddServiceEndpoint(new UdpAnnouncementEndpoint()); // open the host async this.announcementServiceHost.BeginOpen( (result) => { announcementServiceHost.EndOpen(result); }, null); return(this); }
public Main(String [] args) : this() { try { using (ChannelFactory <DNRIService> serviceFactory = new ChannelFactory <DNRIService>(new NetNamedPipeBinding(), new EndpointAddress(PipeService))) { var channel = serviceFactory.CreateChannel(); if (channel.IsOnline()) { foreach (var argument in args) { var argTrim = argument.Trim(); if (argTrim.EndsWith(".dnt")) { channel.OpenDnt(argument); } else if (argTrim.EndsWith(".pak")) { channel.OpenPak(argument); } } channel.Activate(); Close(); } } } catch { @this = new ServiceHost(this, new Uri(PipeName)); @this.AddServiceEndpoint(typeof(DNRIService), new NetNamedPipeBinding(), PipeService); @this.BeginOpen((IAsyncResult ar) => @this.EndOpen(ar), null); foreach (var argument in args) { var argTrim = argument.Trim(); if (argTrim.EndsWith(".dnt")) { OpenDnt(argument); } else if (argTrim.EndsWith(".pak")) { OpenPak(argument); } } } }
private void OnOpen(IAsyncResult result) { ServiceHost service = (ServiceHost)result.AsyncState; service.EndOpen(result); }
/// <summary> /// Completes an asynchronous operation to open a communication object. /// </summary> /// <param name="result">The System.IAsyncResult that is returned by a call to the System.ServiceModel.ICommunicationObject.BeginOpen method.</param> public void EndOpen(IAsyncResult result) { ServiceHost.EndOpen(result); }
void OnOpen(IAsyncResult ar) { ServiceHost service = (ServiceHost)ar.AsyncState; service.EndOpen(ar); }