/// <summary> /// open the p2p channel and register for online and offline events /// </summary> /// <param name="endpointConfigName">The configuration name used for the endpoint</param> private void OpenCore(string endpointConfigName) { callbackInstance = new SynchronizationCallback(businessLogic, synchronizationMode, reSyncInterval); //Open p2p channel channelFactory = new DuplexChannelFactory <ISynchronizedState>(callbackInstance, endpointConfigName); channelFactory.Closing += InvokeCommunicationStateChanged; channelFactory.Closed += InvokeCommunicationStateChanged; channelFactory.Faulted += InvokeCommunicationStateChanged; channelFactory.Opened += InvokeCommunicationStateChanged; channelFactory.Opening += InvokeCommunicationStateChanged; if (UseGenericResolver) { channelFactory.AddGenericResolver(); } channelFactory.BeginOpen(ar => { try { channelFactory.EndOpen(ar); } catch (Exception exception) { LogManager.GetCurrentClassLogger().Fatal(exception); return; } synchronizedStateProxy = channelFactory.CreateChannel(); channel = new ChannelWrapper((IClientChannel)synchronizedStateProxy); callbackInstance.Proxy = synchronizedStateProxy; RegisterProxyEvent(channel); /* * both receive online event but then the second participant receive Exception: * "Cannot make a call on this channel because a call to Open() is in progress." * when calling SynchronizationCallback.BeginSynchronization() from Online event handler , * this is because of issue of raising the Online event prior to the Opened state set. **/ //The Online event not raised on the first participant that is already registered channel.BeginOpen(ar2 => { try { channel.EndOpen(ar2); LogManager.GetCurrentClassLogger().Debug("channel opened"); } catch (Exception exception) { LogManager.GetCurrentClassLogger().Fatal(exception); } }, null); }, null); }