internal ListenerHandler(IListenerBinder listenerBinder, System.ServiceModel.Dispatcher.ChannelDispatcher channelDispatcher, ServiceHostBase host, ServiceThrottle throttle, IDefaultCommunicationTimeouts timeouts) { this.listenerBinder = listenerBinder; if (this.listenerBinder == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("listenerBinder"); } this.channelDispatcher = channelDispatcher; if (this.channelDispatcher == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channelDispatcher"); } this.host = host; if (this.host == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("host"); } this.throttle = throttle; if (this.throttle == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("throttle"); } this.timeouts = timeouts; this.endpoints = channelDispatcher.EndpointDispatcherTable; this.acceptor = new ErrorHandlingAcceptor(listenerBinder, channelDispatcher); }
protected override void OnClosed() { base.OnClosed(); System.ServiceModel.Dispatcher.ServiceThrottle serviceThrottle = this.serviceThrottle; if (serviceThrottle != null) { serviceThrottle.DeactivateInstanceContext(); } }
void StartLoop() { // FIXME: not sure if it should be filled here. if (ServiceThrottle == null) { ServiceThrottle = new ServiceThrottle(this); } loop_manager.Start(); }
protected ServiceHostBase() { TraceUtility.SetEtwProviderId(); this.baseAddresses = new UriSchemeKeyedCollection(base.ThisLock); this.channelDispatchers = new ChannelDispatcherCollection(this, base.ThisLock); this.extensions = new ExtensionCollection <ServiceHostBase>(this, base.ThisLock); this.instances = new InstanceContextManager(base.ThisLock); this.serviceThrottle = new System.ServiceModel.Dispatcher.ServiceThrottle(this); base.TraceOpenAndClose = true; base.Faulted += new EventHandler(this.OnServiceHostFaulted); }
protected override void OnOpened() { ThrowIfNotAttachedToHost(); base.OnOpened(); if (TD.ListenerOpenStopIsEnabled()) { TD.ListenerOpenStop(this.eventTraceActivity); this.eventTraceActivity = null; // clear this since we don't need this anymore. } this.errorBehavior = new ErrorBehavior(this); this.filterTable = new EndpointDispatcherTable(this.ThisLock); for (int i = 0; i < this.endpointDispatchers.Count; i++) { EndpointDispatcher endpoint = this.endpointDispatchers[i]; // Force a build of the runtime to catch any unexpected errors before we are done opening. endpoint.DispatchRuntime.GetRuntime(); // Lock down the DispatchRuntime. endpoint.DispatchRuntime.LockDownProperties(); this.filterTable.AddEndpoint(endpoint); if ((this.addressTable != null) && (endpoint.OriginalAddress != null)) { this.addressTable.Add(endpoint.AddressFilter, endpoint.OriginalAddress, endpoint.FilterPriority); } if (DiagnosticUtility.ShouldTraceInformation) { this.TraceEndpointLifetime(endpoint, TraceCode.EndpointListenerOpen, SR.GetString(SR.TraceCodeEndpointListenerOpen)); } } ServiceThrottle throttle = this.serviceThrottle; if (throttle == null) { throttle = this.host.ServiceThrottle; } IListenerBinder binder = ListenerBinder.GetBinder(this.listener, this.messageVersion); this.listenerHandler = new ListenerHandler(binder, this, this.host, throttle, this.timeouts); this.listenerHandler.Open(); // This never throws, which is why it's ok for it to happen in OnOpened }
void Initialize(SharedRuntimeState shared) { this.shared = shared; this.endpointDispatchers = new EndpointDispatcherCollection(this); this.channelInitializers = this.NewBehaviorCollection <IChannelInitializer>(); this.channels = new CommunicationObjectManager <IChannel>(this.ThisLock); this.pendingChannels = new SynchronizedChannelCollection <IChannel>(this.ThisLock); this.errorHandlers = new Collection <IErrorHandler>(); this.isTransactedReceive = false; this.asynchronousTransactedAcceptEnabled = false; this.receiveSynchronously = false; this.serviceThrottle = null; this.transactionTimeout = TimeSpan.Zero; this.maxPendingReceives = MultipleReceiveBinder.MultipleReceiveDefaults.MaxPendingReceives; if (this.listener != null) { this.listener.Faulted += new EventHandler(OnListenerFaulted); } }
static Type MaybeCreateListener(bool actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, out IChannelListener result, bool supportContextSession) { // if actuallyCreate is true, then this behaves like CreateListener() // else this behaves like CanCreateListener() // result is channel type that was (would be) created, null if can't create // // Ugly API helps refactor common code in these two similar-but-different methods result = null; for (int i = 0; i < supportedChannels.Length; i++) { Type channelType = supportedChannels[i]; if (channelType == typeof(IInputChannel)) { if (binding.CanBuildChannelListener<IInputChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IInputChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IInputChannel); } } if (channelType == typeof(IReplyChannel)) { if (binding.CanBuildChannelListener<IReplyChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IReplyChannel); } } if (channelType == typeof(IDuplexChannel)) { if (binding.CanBuildChannelListener<IDuplexChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IDuplexChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IDuplexChannel); } } if (channelType == typeof(IInputSessionChannel)) { if (binding.CanBuildChannelListener<IInputSessionChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IInputSessionChannel); } } if (channelType == typeof(IReplySessionChannel)) { if (binding.CanBuildChannelListener<IReplySessionChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IReplySessionChannel); } } if (channelType == typeof(IDuplexSessionChannel)) { if (binding.CanBuildChannelListener<IDuplexSessionChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IDuplexSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IDuplexSessionChannel); } } } // If the binding does not support the type natively, try to adapt for (int i = 0; i < supportedChannels.Length; i++) { Type channelType = supportedChannels[i]; // For SessionMode.Allowed or SessionMode.NotAllowed we will accept session-ful variants as well and adapt them if (channelType == typeof(IInputChannel)) { if (binding.CanBuildChannelListener<IInputSessionChannel>(parameters)) { if (actuallyCreate) { IChannelListener<IInputSessionChannel> temp = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); result = DatagramAdapter.GetInputListener(temp, throttle, binding); } return typeof(IInputSessionChannel); } } if (channelType == typeof(IReplyChannel)) { if (binding.CanBuildChannelListener<IReplySessionChannel>(parameters)) { if (actuallyCreate) { IChannelListener<IReplySessionChannel> temp = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); result = DatagramAdapter.GetReplyListener(temp, throttle, binding); } return typeof(IReplySessionChannel); } } if (supportContextSession) { // and for SessionMode.Required, it is possible that the InstanceContextProvider is handling the session management, so // accept datagram variants if that is the case if (channelType == typeof(IReplySessionChannel)) { if (binding.CanBuildChannelListener<IReplyChannel>(parameters) && binding.GetProperty<IContextSessionProvider>(parameters) != null) { if (actuallyCreate) { result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IReplyChannel); } } } } return null; }
static internal Type MaybeCreateListener(bool actuallyCreate, Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, out IChannelListener result) { return MaybeCreateListener(actuallyCreate, supportedChannels, binding, parameters, listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, throttle, out result, false); }
internal ChannelHandler(MessageVersion messageVersion, IChannelBinder binder, ServiceThrottle throttle, ListenerHandler listener, bool wasChannelThrottled, WrappedTransaction acceptTransaction, 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.sendAsynchronously = channelDispatcher.SendAsynchronously; this.duplexBinder = binder as DuplexChannelBinder; this.hasSession = binder.HasSession; this.isConcurrent = ConcurrencyBehavior.IsConcurrent(channelDispatcher, this.hasSession); if (channelDispatcher.MaxPendingReceives > 1) { // We need to preserve order if the ChannelHandler is not concurrent. 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; Fx.Assert((this.idleManager != null) == (this.binder.HasSession && this.listener.ChannelDispatcher.DefaultCommunicationTimeouts.ReceiveTimeout != TimeSpan.MaxValue), "idle manager is present only when there is a session with a finite receive timeout"); if (channelDispatcher.IsTransactedReceive && !channelDispatcher.ReceiveContextEnabled) { receiveSynchronously = true; receiveWithTransaction = true; if (channelDispatcher.MaxTransactedBatchSize > 0) { int maxConcurrentBatches = 1; if (null != throttle && throttle.MaxConcurrentCalls > 1) { maxConcurrentBatches = throttle.MaxConcurrentCalls; foreach (EndpointDispatcher endpointDispatcher in channelDispatcher.Endpoints) { if (ConcurrencyMode.Multiple != endpointDispatcher.DispatchRuntime.ConcurrencyMode) { maxConcurrentBatches = 1; break; } } } this.sharedTransactedBatchContext = new SharedTransactedBatchContext(this, channelDispatcher, maxConcurrentBatches); this.isMainTransactedBatchHandler = true; this.throttle = null; } } else if (channelDispatcher.IsTransactedReceive && channelDispatcher.ReceiveContextEnabled && channelDispatcher.MaxTransactedBatchSize > 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.IncompatibleBehaviors))); } if (this.binder.HasSession) { this.sessionOpenNotification = this.binder.Channel.GetProperty<SessionOpenNotification>(); this.needToCreateSessionOpenNotificationMessage = this.sessionOpenNotification != null && this.sessionOpenNotification.IsEnabled; } this.acceptTransaction = acceptTransaction; this.requestInfo = new RequestInfo(this); if (this.listener.State == CommunicationState.Opened) { this.listener.ChannelDispatcher.Channels.IncrementActivityCount(); this.incrementedActivityCountInConstructor = true; } }
public ThrottleInfo(ServiceThrottle throttle) { MaxConcurrentCalls = throttle.MaxConcurrentCalls; MaxConcurrentInstances = throttle.MaxConcurrentInstances; MaxConcurrentSessions = throttle.MaxConcurrentSessions; }
internal ListenerHandler(IListenerBinder listenerBinder, ChannelDispatcher channelDispatcher, ServiceHostBase host, ServiceThrottle throttle, IDefaultCommunicationTimeouts timeouts) { this.listenerBinder = listenerBinder; if (!((this.listenerBinder != null))) { Fx.Assert("ListenerHandler.ctor: (this.listenerBinder != null)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("listenerBinder"); } this.channelDispatcher = channelDispatcher; if (!((this.channelDispatcher != null))) { Fx.Assert("ListenerHandler.ctor: (this.channelDispatcher != null)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("channelDispatcher"); } this.host = host; if (!((this.host != null))) { Fx.Assert("ListenerHandler.ctor: (this.host != null)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("host"); } this.throttle = throttle; if (!((this.throttle != null))) { Fx.Assert("ListenerHandler.ctor: (this.throttle != null)"); throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("throttle"); } this.timeouts = timeouts; this.endpoints = channelDispatcher.EndpointDispatcherTable; this.acceptor = new ErrorHandlingAcceptor(listenerBinder, channelDispatcher); }
private static System.Type MaybeCreateListener(bool actuallyCreate, System.Type[] supportedChannels, Binding binding, BindingParameterCollection parameters, Uri listenUriBaseAddress, string listenUriRelativeAddress, ListenUriMode listenUriMode, ServiceThrottle throttle, out IChannelListener result, bool supportContextSession) { result = null; for (int i = 0; i < supportedChannels.Length; i++) { System.Type type = supportedChannels[i]; if ((type == typeof(IInputChannel)) && binding.CanBuildChannelListener<IInputChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IInputChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IInputChannel); } if ((type == typeof(IReplyChannel)) && binding.CanBuildChannelListener<IReplyChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IReplyChannel); } if ((type == typeof(IDuplexChannel)) && binding.CanBuildChannelListener<IDuplexChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IDuplexChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IDuplexChannel); } if ((type == typeof(IInputSessionChannel)) && binding.CanBuildChannelListener<IInputSessionChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IInputSessionChannel); } if ((type == typeof(IReplySessionChannel)) && binding.CanBuildChannelListener<IReplySessionChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IReplySessionChannel); } if ((type == typeof(IDuplexSessionChannel)) && binding.CanBuildChannelListener<IDuplexSessionChannel>(parameters)) { if (actuallyCreate) { result = binding.BuildChannelListener<IDuplexSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IDuplexSessionChannel); } } for (int j = 0; j < supportedChannels.Length; j++) { System.Type type2 = supportedChannels[j]; if ((type2 == typeof(IInputChannel)) && binding.CanBuildChannelListener<IInputSessionChannel>(parameters)) { if (actuallyCreate) { IChannelListener<IInputSessionChannel> inner = binding.BuildChannelListener<IInputSessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); result = DatagramAdapter.GetInputListener(inner, throttle, binding); } return typeof(IInputSessionChannel); } if ((type2 == typeof(IReplyChannel)) && binding.CanBuildChannelListener<IReplySessionChannel>(parameters)) { if (actuallyCreate) { IChannelListener<IReplySessionChannel> listener2 = binding.BuildChannelListener<IReplySessionChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); result = DatagramAdapter.GetReplyListener(listener2, throttle, binding); } return typeof(IReplySessionChannel); } if ((supportContextSession && (type2 == typeof(IReplySessionChannel))) && (binding.CanBuildChannelListener<IReplyChannel>(parameters) && (binding.GetProperty<IContextSessionProvider>(parameters) != null))) { if (actuallyCreate) { result = binding.BuildChannelListener<IReplyChannel>(listenUriBaseAddress, listenUriRelativeAddress, listenUriMode, parameters); } return typeof(IReplyChannel); } } return null; }
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; } }