bool TransactedAccept(out Transaction tx) { tx = null; try { tx = TransactionBehavior.CreateTransaction(this.ChannelDispatcher.TransactionIsolationLevel, this.ChannelDispatcher.TransactionTimeout); IChannelBinder binder = null; using (TransactionScope scope = new TransactionScope(tx)) { TimeSpan acceptTimeout = TimeoutHelper.Min(this.ChannelDispatcher.TransactionTimeout, this.ChannelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); if (!this.acceptor.TryAccept(TransactionBehavior.NormalizeTimeout(acceptTimeout), out binder)) { return(false); } scope.Complete(); } if (null != binder) { this.channel = new ListenerChannel(binder); this.idleManager = SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); return(true); } else { this.AcceptedNull(); tx = null; return(false); } } catch (CommunicationException e) { if (null != tx) { try { tx.Rollback(); } catch (TransactionException ex) { DiagnosticUtility.TraceHandledException(ex, TraceEventType.Information); } } tx = null; DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); return(false); } catch (TransactionException e) { tx = null; DiagnosticUtility.TraceHandledException(e, TraceEventType.Information); return(false); } }
bool HandleEndAccept(IAsyncResult result) { this.channel = this.CompleteAccept(result); if (this.channel != null) { Fx.Assert(this.idleManager == null, "There cannot be an existing idle manager"); this.idleManager = SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); } else { this.DoneAccepting(); return(true); } return(this.AcquireThrottle()); }