Пример #1
0
        //internal void ReleasePerformanceCounters()
        //{
        //    if (PerformanceCounters.PerformanceCountersEnabled)
        //    {
        //        PerformanceCounters.ReleasePerformanceCountersForEndpoint(this.perfCounterId, this.perfCounterBaseId);
        //    }
        //}

        //internal bool SetPerfCounterId()
        //{
        //    Uri keyUri = null;
        //    if (null != this.ListenUri)
        //    {
        //        keyUri = this.ListenUri;
        //    }
        //    else
        //    {
        //        EndpointAddress endpointAddress = this.EndpointAddress;
        //        if (null != endpointAddress)
        //        {
        //            keyUri = endpointAddress.Uri;
        //        }
        //    }

        //    if (null != keyUri)
        //    {
        //        this.perfCounterBaseId = keyUri.AbsoluteUri.ToUpperInvariant();
        //        this.perfCounterId = this.perfCounterBaseId + "/" + contractName.ToUpperInvariant();

        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

        void ThrowIfDisposedOrImmutable()
        {
            ChannelDispatcher channelDispatcher = this.channelDispatcher;

            if (channelDispatcher != null)
            {
                channelDispatcher.ThrowIfDisposedOrImmutable();
            }
        }
Пример #2
0
        internal DispatchRuntime(ClientRuntime proxyRuntime, SharedRuntimeState shared)
            : this(shared)
        {
            this.proxyRuntime       = proxyRuntime ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(proxyRuntime));
            instanceProvider        = new CallbackInstanceProvider();
            channelDispatcher       = new ChannelDispatcher(shared);
            instanceContextProvider = InstanceContextProviderBase.GetProviderForMode(InstanceContextMode.PerSession, this);

            Fx.Assert(!shared.IsOnServer, "Client constructor called on server?");
        }
Пример #3
0
        internal void Attach(ChannelDispatcher channelDispatcher)
        {
            if (ChannelDispatcher != null)
            {
                Exception error = new InvalidOperationException(SR.SFxEndpointDispatcherMultipleChannelDispatcher0);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
            }

            ChannelDispatcher = channelDispatcher ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(channelDispatcher));
            // TODO: Plumb through the listening Uri
            //listenUri = channelDispatcher.Listener?.Uri;
        }
Пример #4
0
        internal ErrorHandlingAcceptor(IListenerBinder binder, ChannelDispatcher dispatcher)
        {
            if (binder == null)
            {
                Fx.Assert("binder is null");
            }
            if (dispatcher == null)
            {
                Fx.Assert("dispatcher is null");
            }

            this.binder     = binder;
            this.dispatcher = dispatcher;
        }
Пример #5
0
 internal ErrorBehavior(ChannelDispatcher channelDispatcher)
 {
     if (channelDispatcher?.ErrorHandlers == null)
     {
         Handlers = EmptyArray <IErrorHandler> .Allocate(0);
     }
     else
     {
         Handlers = EmptyArray <IErrorHandler> .ToArray(channelDispatcher.ErrorHandlers);
     }
     _debug = channelDispatcher.IncludeExceptionDetailInFaults;
     //isOnServer = channelDispatcher.IsOnServer;
     _isOnServer     = true;
     _messageVersion = channelDispatcher.MessageVersion;
 }
Пример #6
0
        internal ChannelHandler(MessageVersion messageVersion, IChannelBinder binder, ServiceThrottle throttle,
                                ServiceDispatcher serviceDispatcher, bool wasChannelThrottled, SessionIdleManager idleManager)
        {
            ChannelDispatcher channelDispatcher = serviceDispatcher.ChannelDispatcher;

            _serviceDispatcher   = serviceDispatcher;
            _messageVersion      = messageVersion;
            _isManualAddressing  = channelDispatcher.ManualAddressing;
            _binder              = binder;
            _throttle            = throttle;
            _wasChannelThrottled = wasChannelThrottled;
            _host         = channelDispatcher.Host;
            _duplexBinder = binder as DuplexChannelBinder;
            _hasSession   = binder.HasSession;
            _isConcurrent = ConcurrencyBehavior.IsConcurrent(channelDispatcher, _hasSession);

            // TODO: Work out if MultipleReceiveBinder is necessary
            //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)
            {
                _binder = new BufferedReceiveBinder(_binder);
            }

            _idleManager = idleManager;

            if (_binder.HasSession)
            {
                _sessionOpenNotification = _binder.Channel.GetProperty <SessionOpenNotification>();
                _needToCreateSessionOpenNotificationMessage = _sessionOpenNotification != null && _sessionOpenNotification.IsEnabled;
            }

            //_requestInfo = new RequestInfo(this);

            // TODO: Wire up lifetime management in place of listener state
            //if (this.listener.State == CommunicationState.Opened)
            //{
            _serviceDispatcher.ChannelDispatcher.Channels.IncrementActivityCount();
            _incrementedActivityCountInConstructor = true;
            //}
        }
Пример #7
0
        internal void Detach(ChannelDispatcher channelDispatcher)
        {
            if (channelDispatcher == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(channelDispatcher));
            }

            if (this.channelDispatcher != channelDispatcher)
            {
                Exception error = new InvalidOperationException(SR.SFxEndpointDispatcherDifferentChannelDispatcher0);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(error);
            }

            //this.ReleasePerformanceCounters();
            this.channelDispatcher = null;
        }
        void TransferChannelFromPendingList(MessageRpc rpc)
        {
            if (rpc.Channel.IsPending)
            {
                rpc.Channel.IsPending = false;

                ChannelDispatcher        channelDispatcher = rpc.Channel.ChannelDispatcher;
                IInstanceContextProvider provider          = InstanceBehavior.InstanceContextProvider;

                if (!InstanceContextProviderBase.IsProviderSessionful(provider) &&
                    !InstanceContextProviderBase.IsProviderSingleton(provider))
                {
                    IChannel proxy = rpc.Channel.Proxy as IChannel;
                    if (!rpc.InstanceContext.IncomingChannels.Contains(proxy))
                    {
                        channelDispatcher.Channels.Add(proxy);
                    }
                }

                // TODO: Do we need to keep track of pending channels with the new hosting model?
                //channelDispatcher.PendingChannels.Remove(rpc.Channel.Binder.Channel);
            }
        }
Пример #9
0
        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(nameof(listenerBinder));
            }

            this.channelDispatcher = channelDispatcher;
            if (!((this.channelDispatcher != null)))
            {
                Fx.Assert("ListenerHandler.ctor: (this.channelDispatcher != null)");
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(channelDispatcher));
            }

            this.host = host;
            if (!((this.host != null)))
            {
                Fx.Assert("ListenerHandler.ctor: (this.host != null)");
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(host));
            }

            //this.throttle = throttle;
            //if (!((this.throttle != null)))
            //{
            //    Fx.Assert("ListenerHandler.ctor: (this.throttle != null)");
            //    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(throttle));
            //}

            this.timeouts = timeouts;

            //endpoints = channelDispatcher.EndpointDispatcherTable;
            acceptor           = new ErrorHandlingAcceptor(listenerBinder, channelDispatcher);
            closingTokenSource = new CancellationTokenSource();
        }
Пример #10
0
 public ServiceDispatcher(ChannelDispatcher channelDispatcher)
 {
     ChannelDispatcher = channelDispatcher;
     // TODO: Maybe make lazy
     _requestReplyCorrelator = new RequestReplyCorrelator();
 }
Пример #11
0
 internal ChannelDispatcherBehaviorCollection(ChannelDispatcher outer)
     : base(outer.ThisLock)
 {
     _outer = outer;
 }
Пример #12
0
 internal EndpointDispatcherCollection(ChannelDispatcher owner)
     : base(owner.ThisLock)
 {
     _owner = owner;
 }
Пример #13
0
 internal ErrorHandlingReceiver(IChannelBinder binder, ChannelDispatcher dispatcher)
 {
     this.binder     = binder;
     this.dispatcher = dispatcher;
 }
Пример #14
0
            public object Invoke(object instance, object[] inputs, out object[] outputs)
            {
                outputs = EmptyArray <object> .Allocate(0);

                Message message = inputs[0] as Message;

                if (message == null)
                {
                    return(null);
                }

                string action = message.Headers.Action;

                //if (DiagnosticUtility.ShouldTraceInformation)
                //{
                //    TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.UnhandledAction,
                //        SR.TraceCodeUnhandledAction,
                //        new StringTraceRecord("Action", action),
                //        this, null, message);
                //}

                FaultCode code = FaultCode.CreateSenderFaultCode(AddressingStrings.ActionNotSupported,
                                                                 message.Version.Addressing.Namespace);
                string      reasonText = SR.Format(SR.SFxNoEndpointMatchingContract, action);
                FaultReason reason     = new FaultReason(reasonText);

                FaultException exception = new FaultException(reason, code);

                ErrorBehavior.ThrowAndCatch(exception);

                ServiceChannel serviceChannel = OperationContext.Current.InternalServiceChannel;

                OperationContext.Current.OperationCompleted +=
                    delegate(object sender, EventArgs e)
                {
                    ChannelDispatcher channelDispatcher = dispatchRuntime.ChannelDispatcher;
                    if (!channelDispatcher.HandleError(exception) && serviceChannel.HasSession)
                    {
                        try
                        {
                            var helper = new TimeoutHelper(ChannelHandler.CloseAfterFaultTimeout);
                            serviceChannel.CloseAsync(helper.GetCancellationToken()).GetAwaiter().GetResult();
                        }
                        catch (Exception ex)
                        {
                            if (Fx.IsFatal(ex))
                            {
                                throw;
                            }
                            channelDispatcher.HandleError(ex);
                        }
                    }
                };

                if (dispatchRuntime.shared.EnableFaults)
                {
                    MessageFault fault = MessageFault.CreateFault(code, reason, action);
                    return(Message.CreateMessage(message.Version, fault, message.Version.Addressing.DefaultFaultAction));
                }
                else
                {
                    OperationContext.Current.RequestContext.CloseAsync().GetAwaiter().GetResult();
                    OperationContext.Current.RequestContext = null;
                    return(null);
                }
            }