public async Task <IServiceChannelDispatcher> CreateServiceChannelDispatcherAsync(IChannel channel) { ServiceChannel.SessionIdleManager sessionIdleManager = channel.GetProperty <ServiceChannel.SessionIdleManager>(); IChannelBinder binder = null; if (channel is IReplyChannel) { ReplyChannelBinder rcbinder = channel.GetProperty <ReplyChannelBinder>(); rcbinder.Init(channel as IReplyChannel, BaseAddress); binder = rcbinder; } else if (channel is IDuplexSessionChannel) { DuplexChannelBinder dcbinder = channel.GetProperty <DuplexChannelBinder>(); dcbinder.Init(channel as IDuplexSessionChannel, _requestReplyCorrelator, BaseAddress); binder = dcbinder; } else if (channel is IInputChannel) { InputChannelBinder icbinder = channel.GetProperty <InputChannelBinder>(); icbinder.Init(channel as IInputChannel, BaseAddress); binder = icbinder; } // TODO: Wire up wasChannelThrottled var channelHandler = new ChannelHandler(Binding.MessageVersion, binder, channel.GetProperty <ServiceThrottle>(), this, /*wasChannelThrottled*/ false, sessionIdleManager); IServiceChannelDispatcher channelDispatcher = channelHandler.GetDispatcher(); // channel.ChannelDispatcher = channelDispatcher; await channelHandler.OpenAsync(); return(channelDispatcher); }
private bool TransactedAccept(out Transaction tx) { tx = null; try { tx = TransactionBehavior.CreateTransaction(this.ChannelDispatcher.TransactionIsolationLevel, this.ChannelDispatcher.TransactionTimeout); IChannelBinder channelBinder = null; using (TransactionScope scope = new TransactionScope(tx)) { TimeSpan timeout = TimeoutHelper.Min(this.ChannelDispatcher.TransactionTimeout, this.ChannelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); if (!this.acceptor.TryAccept(TransactionBehavior.NormalizeTimeout(timeout), out channelBinder)) { return(false); } scope.Complete(); } if (channelBinder != null) { this.channel = new ListenerChannel(channelBinder); this.idleManager = ServiceChannel.SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); return(true); } this.AcceptedNull(); tx = null; return(false); } catch (CommunicationException exception) { if (null != tx) { try { tx.Rollback(); } catch (TransactionException exception2) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information); } } } tx = null; if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } return(false); } catch (TransactionException exception3) { tx = null; if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information); } return(false); } }
private void Dispatch() { ListenerChannel channel = this.channel; ServiceChannel.SessionIdleManager idleManager = this.idleManager; this.channel = null; this.idleManager = null; try { if (channel != null) { ChannelHandler handler = new ChannelHandler(this.listenerBinder.MessageVersion, channel.Binder, this.throttle, this, channel.Throttle != null, this.wrappedTransaction, idleManager); if (!channel.Binder.HasSession) { this.channelDispatcher.Channels.Add(channel.Binder.Channel); } if (channel.Binder is DuplexChannelBinder) { DuplexChannelBinder binder = channel.Binder as DuplexChannelBinder; binder.ChannelHandler = handler; binder.DefaultCloseTimeout = this.DefaultCloseTimeout; if (this.timeouts == null) { binder.DefaultSendTimeout = ServiceDefaults.SendTimeout; } else { binder.DefaultSendTimeout = this.timeouts.SendTimeout; } } ChannelHandler.Register(handler); channel = null; idleManager = null; } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.HandleError(exception); } finally { if (channel != null) { channel.Binder.Channel.Abort(); if ((this.throttle != null) && this.channelDispatcher.Session) { this.throttle.DeactivateChannel(); } if (idleManager != null) { idleManager.CancelTimer(); } } } }
private void CancelPendingIdleManager() { ServiceChannel.SessionIdleManager idleManager = this.idleManager; if (idleManager != null) { idleManager.CancelTimer(); } }
private bool HandleEndAccept(IAsyncResult result) { this.channel = this.CompleteAccept(result); if (this.channel != null) { this.idleManager = ServiceChannel.SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); return(this.AcquireThrottle()); } this.DoneAccepting(); return(true); }
private bool TransactedAccept(out Transaction tx) { tx = null; try { tx = TransactionBehavior.CreateTransaction(this.ChannelDispatcher.TransactionIsolationLevel, this.ChannelDispatcher.TransactionTimeout); IChannelBinder channelBinder = null; using (TransactionScope scope = new TransactionScope(tx)) { TimeSpan timeout = TimeoutHelper.Min(this.ChannelDispatcher.TransactionTimeout, this.ChannelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); if (!this.acceptor.TryAccept(TransactionBehavior.NormalizeTimeout(timeout), out channelBinder)) { return false; } scope.Complete(); } if (channelBinder != null) { this.channel = new ListenerChannel(channelBinder); this.idleManager = ServiceChannel.SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); return true; } this.AcceptedNull(); tx = null; return false; } catch (CommunicationException exception) { if (null != tx) { try { tx.Rollback(); } catch (TransactionException exception2) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information); } } } tx = null; if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } return false; } catch (TransactionException exception3) { tx = null; if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception3, TraceEventType.Information); } return false; } }
private bool HandleEndAccept(IAsyncResult result) { this.channel = this.CompleteAccept(result); if (this.channel != null) { this.idleManager = ServiceChannel.SessionIdleManager.CreateIfNeeded(this.channel.Binder, this.channelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout); return this.AcquireThrottle(); } this.DoneAccepting(); return true; }
private void Dispatch() { ListenerChannel channel = this.channel; ServiceChannel.SessionIdleManager idleManager = this.idleManager; this.channel = null; this.idleManager = null; try { if (channel != null) { ChannelHandler handler = new ChannelHandler(this.listenerBinder.MessageVersion, channel.Binder, this.throttle, this, channel.Throttle != null, this.wrappedTransaction, idleManager); if (!channel.Binder.HasSession) { this.channelDispatcher.Channels.Add(channel.Binder.Channel); } if (channel.Binder is DuplexChannelBinder) { DuplexChannelBinder binder = channel.Binder as DuplexChannelBinder; binder.ChannelHandler = handler; binder.DefaultCloseTimeout = this.DefaultCloseTimeout; if (this.timeouts == null) { binder.DefaultSendTimeout = ServiceDefaults.SendTimeout; } else { binder.DefaultSendTimeout = this.timeouts.SendTimeout; } } ChannelHandler.Register(handler); channel = null; idleManager = null; } } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } this.HandleError(exception); } finally { if (channel != null) { channel.Binder.Channel.Abort(); if ((this.throttle != null) && this.channelDispatcher.Session) { this.throttle.DeactivateChannel(); } if (idleManager != null) { idleManager.CancelTimer(); } } } }
internal ChannelHandler(MessageVersion messageVersion, IChannelBinder binder, ServiceThrottle throttle, ListenerHandler listener, bool wasChannelThrottled, WrappedTransaction acceptTransaction, ServiceChannel.SessionIdleManager idleManager) { ChannelDispatcher channelDispatcher = listener.ChannelDispatcher; this.messageVersion = messageVersion; this.isManualAddressing = channelDispatcher.ManualAddressing; this.binder = binder; this.throttle = throttle; this.listener = listener; this.wasChannelThrottled = wasChannelThrottled; this.host = listener.Host; this.receiveSynchronously = channelDispatcher.ReceiveSynchronously; this.duplexBinder = binder as DuplexChannelBinder; this.hasSession = binder.HasSession; this.isConcurrent = ConcurrencyBehavior.IsConcurrent(channelDispatcher, this.hasSession); if (channelDispatcher.MaxPendingReceives > 1) { this.binder = new MultipleReceiveBinder(this.binder, channelDispatcher.MaxPendingReceives, !this.isConcurrent); } if (channelDispatcher.BufferedReceiveEnabled) { this.binder = new BufferedReceiveBinder(this.binder); } this.receiver = new ErrorHandlingReceiver(this.binder, channelDispatcher); this.idleManager = idleManager; if (!channelDispatcher.IsTransactedReceive || channelDispatcher.ReceiveContextEnabled) { if ((channelDispatcher.IsTransactedReceive && channelDispatcher.ReceiveContextEnabled) && (channelDispatcher.MaxTransactedBatchSize > 0)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("IncompatibleBehaviors"))); } } else { this.receiveSynchronously = true; this.receiveWithTransaction = true; if (channelDispatcher.MaxTransactedBatchSize > 0) { int maxConcurrentBatches = 1; if ((throttle != null) && (throttle.MaxConcurrentCalls > 1)) { maxConcurrentBatches = throttle.MaxConcurrentCalls; foreach (EndpointDispatcher dispatcher2 in channelDispatcher.Endpoints) { if (ConcurrencyMode.Multiple != dispatcher2.DispatchRuntime.ConcurrencyMode) { maxConcurrentBatches = 1; break; } } } this.sharedTransactedBatchContext = new SharedTransactedBatchContext(this, channelDispatcher, maxConcurrentBatches); this.isMainTransactedBatchHandler = true; this.throttle = null; } } this.acceptTransaction = acceptTransaction; this.requestInfo = new RequestInfo(this); if (!this.hasSession && (this.listener.State == CommunicationState.Opened)) { this.listener.ChannelDispatcher.Channels.IncrementActivityCount(); this.incrementedActivityCountInConstructor = true; } }