internal bool AcquireCall(ChannelHandler channel)
 {
     lock (this.ThisLock)
     {
         return this.PrivateAcquireCall(channel);
     }
 }
 internal bool AcquireInstanceContextAndDynamic(ChannelHandler channel, bool acquireInstanceContextThrottle)
 {
     lock (this.ThisLock)
     {
         if (!acquireInstanceContextThrottle)
         {
             return this.PrivateAcquireDynamic(channel);
         }
         return (this.PrivateAcquireInstanceContext(channel) && this.PrivateAcquireDynamic(channel));
     }
 }
 internal void DispatchStarted()
 {
     lock (this.thisLock)
     {
         this.currentConcurrentDispatches++;
         if ((this.currentConcurrentDispatches == this.currentConcurrentBatches) && (this.currentConcurrentBatches < this.maxConcurrentBatches))
         {
             TransactedBatchContext context = new TransactedBatchContext(this);
             this.currentConcurrentBatches++;
             ChannelHandler handler = new ChannelHandler(this.handler, context);
             ChannelHandler.Register(handler);
         }
     }
 }
 internal SharedTransactedBatchContext(ChannelHandler handler, ChannelDispatcher dispatcher, int maxConcurrentBatches)
 {
     this.handler = handler;
     this.maxBatchSize = dispatcher.MaxTransactedBatchSize;
     this.maxConcurrentBatches = maxConcurrentBatches;
     this.currentBatchSize = dispatcher.MaxTransactedBatchSize;
     this.currentConcurrentBatches = 0;
     this.currentConcurrentDispatches = 0;
     this.successfullCommits = 0;
     this.isBatching = true;
     this.isolationLevel = dispatcher.TransactionIsolationLevel;
     this.txTimeout = TransactionBehavior.NormalizeTimeout(dispatcher.TransactionTimeout);
     this.BatchingStateChanged(this.isBatching);
 }
 public IAsyncResult BeginComplete(TimeSpan timeout, Transaction transaction, ChannelHandler channelHandler, AsyncCallback callback, object state)
 {
     IAsyncResult result = null;
     if (transaction != null)
     {
         using (TransactionScope scope = new TransactionScope(transaction))
         {
             TransactionOutcomeListener.EnsureReceiveContextAbandonOnTransactionRollback(this.receiveContext, transaction, channelHandler);
             result = this.receiveContext.BeginComplete(timeout, callback, state);
             scope.Complete();
             return result;
         }
     }
     return this.receiveContext.BeginComplete(timeout, callback, state);
 }
 internal ChannelHandler(ChannelHandler handler, TransactedBatchContext context)
 {
     this.messageVersion = handler.messageVersion;
     this.isManualAddressing = handler.isManualAddressing;
     this.binder = handler.binder;
     this.listener = handler.listener;
     this.wasChannelThrottled = handler.wasChannelThrottled;
     this.host = handler.host;
     this.receiveSynchronously = true;
     this.receiveWithTransaction = true;
     this.duplexBinder = handler.duplexBinder;
     this.hasSession = handler.hasSession;
     this.isConcurrent = handler.isConcurrent;
     this.receiver = handler.receiver;
     this.sharedTransactedBatchContext = context.Shared;
     this.transactedBatchContext = context;
     this.requestInfo = new RequestInfo(this);
 }
 bool PrivateAcquireCall(ChannelHandler channel)
 {
     return (this.calls == null) || this.calls.Acquire(channel);
 }
 public static void EnsureReceiveContextAbandonOnTransactionRollback(ReceiveContext receiveContext, Transaction transaction, ChannelHandler channelHandler)
 {
     new TransactionOutcomeListener(receiveContext, transaction, channelHandler);
 }
 public TransactionOutcomeListener(ReceiveContext receiveContext, Transaction transaction, ChannelHandler handler)
 {
     this.receiveContext = receiveContext;
     transaction.TransactionCompleted += new TransactionCompletedEventHandler(this.OnTransactionComplete);
     this.channelHandler = handler;
 }
Esempio n. 10
0
        internal MessageRpc(RequestContext requestContext, Message request, DispatchOperationRuntime operation,
            ServiceChannel channel, ServiceHostBase host, ChannelHandler channelHandler, bool cleanThread,
            OperationContext operationContext, InstanceContext instanceContext, EventTraceActivity eventTraceActivity)
        {
            Fx.Assert((operationContext != null), "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), operationContext == null");
            Fx.Assert(channelHandler != null, "System.ServiceModel.Dispatcher.MessageRpc.MessageRpc(), channelHandler == null");

            this.Activity = null;
            this.EventTraceActivity = eventTraceActivity;            
            this.AsyncResult = null;
            this.CanSendReply = true;
            this.Channel = channel;
            this.channelHandler = channelHandler;
            this.Correlation = EmptyArray.Allocate(operation.Parent.CorrelationCount);
            this.CorrelationCallback = null;
            this.DidDeserializeRequestBody = false;
            this.TransactionMessageProperty = null;
            this.TransactedBatchContext = null;
            this.Error = null;
            this.ErrorProcessor = null;
            this.FaultInfo = new ErrorHandlerFaultInfo(request.Version.Addressing.DefaultFaultAction);
            this.HasSecurityContext = false;
            this.Host = host;
            this.Instance = null;
            this.MessageRpcOwnsInstanceContextThrottle = false;
            this.NextProcessor = null;
            this.NotUnderstoodHeaders = null;
            this.Operation = operation;
            this.OperationContext = operationContext;
            this.paused = false;
            this.ParametersDisposed = false;
            this.ReceiveContext = null;
            this.Request = request;
            this.RequestContext = requestContext;
            this.RequestContextThrewOnReply = false;
            this.SuccessfullySendReply = false;
            this.RequestVersion = request.Version;
            this.Reply = null;
            this.ReplyTimeoutHelper = new TimeoutHelper();
            this.SecurityContext = null;
            this.InstanceContext = instanceContext;
            this.SuccessfullyBoundInstance = false;
            this.SuccessfullyIncrementedActivity = false;
            this.SuccessfullyLockedInstance = false;
            this.switchedThreads = !cleanThread;
            this.transaction = null;
            this.InputParameters = null;
            this.OutputParameters = null;
            this.ReturnParameter = null;
            this.isInstanceContextSingleton = InstanceContextProviderBase.IsProviderSingleton(this.Channel.DispatchRuntime.InstanceContextProvider);
            this.invokeContinueGate = null;

            if (!operation.IsOneWay && !operation.Parent.ManualAddressing)
            {
                this.RequestID = request.Headers.MessageId;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo(request);
            }
            else
            {
                this.RequestID = null;
                this.ReplyToInfo = new RequestReplyCorrelator.ReplyToInfo();
            }

            this.HostingProperty = AspNetEnvironment.Current.GetHostingProperty(request, true);

            if (DiagnosticUtility.ShouldUseActivity)
            {
                this.Activity = TraceUtility.ExtractActivity(this.Request);
            }

            if (DiagnosticUtility.ShouldUseActivity || TraceUtility.ShouldPropagateActivity)
            {
                this.ResponseActivityId = ActivityIdHeader.ExtractActivityId(this.Request);
            }
            else
            {
                this.ResponseActivityId = Guid.Empty;
            }

            this.InvokeNotification = new MessageRpcInvokeNotification(this.Activity, this.channelHandler);

            if (this.EventTraceActivity == null && FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                if (this.Request != null)
                {
                    this.EventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.Request, true);
                }
            }
        }
 internal static void Register(ChannelHandler handler)
 {
     handler.Register();
 }
        internal ChannelHandler(ChannelHandler handler, TransactedBatchContext context)
        {
            this.messageVersion = handler.messageVersion;
            this.isManualAddressing = handler.isManualAddressing;
            this.binder = handler.binder;
            this.listener = handler.listener;
            this.wasChannelThrottled = handler.wasChannelThrottled;

            this.host = handler.host;
            this.receiveSynchronously = true;
            this.receiveWithTransaction = true;
            this.duplexBinder = handler.duplexBinder;
            this.hasSession = handler.hasSession;
            this.isConcurrent = handler.isConcurrent;
            this.receiver = handler.receiver;

            this.sharedTransactedBatchContext = context.Shared;
            this.transactedBatchContext = context;
            this.requestInfo = new RequestInfo(this);

            this.sendAsynchronously = handler.sendAsynchronously;
            this.sessionOpenNotification = handler.sessionOpenNotification;
            this.needToCreateSessionOpenNotificationMessage = handler.needToCreateSessionOpenNotificationMessage;
            this.shouldRejectMessageWithOnOpenActionHeader = handler.shouldRejectMessageWithOnOpenActionHeader;
        }
 private bool PrivateAcquireDynamic(ChannelHandler channel)
 {
     if (this.dynamic != null)
     {
         return this.dynamic.Acquire(channel);
     }
     return true;
 }
 private bool PrivateAcquireCall(ChannelHandler channel)
 {
     if (this.calls != null)
     {
         return this.calls.Acquire(channel);
     }
     return true;
 }
 internal static void Register(ChannelHandler handler, RequestContext request)
 {
     (handler.Binder as BufferedReceiveBinder).InjectRequest(request);
     handler.Register();
 }
 bool PrivateAcquireDynamic(ChannelHandler channel)
 {
     return (this.dynamic == null) || this.dynamic.Acquire(channel);
 }
 bool PrivateAcquireInstanceContext(ChannelHandler channel)
 {
     if ((this.instanceContexts != null) && (channel.InstanceContext == null))
     {
         channel.InstanceContextServiceThrottle = this;
         return this.instanceContexts.Acquire(channel);
     }
     else
     {
         return true;
     }
 }
 internal void DispatchStarted()
 {
     lock (thisLock)
     {
         ++this.currentConcurrentDispatches;
         if (this.currentConcurrentDispatches == this.currentConcurrentBatches && this.currentConcurrentBatches < this.maxConcurrentBatches)
         {
             TransactedBatchContext context = new TransactedBatchContext(this);
             ++this.currentConcurrentBatches;
             ChannelHandler newHandler = new ChannelHandler(this.handler, context);
             ChannelHandler.Register(newHandler);
         }
     }
 }
            public bool ChannelHandlerOwnsInstanceContextThrottle; // if true, we are responsible for instance/dynamic throttle

            public RequestInfo(ChannelHandler channelHandler)
            {
                this.Endpoint = null;
                this.ExistingInstanceContext = null;
                this.Channel = null;
                this.EndpointLookupDone = false;
                this.DispatchRuntime = null;
                this.RequestContext = null;
                this.ChannelHandler = channelHandler;
                this.ChannelHandlerOwnsCallThrottle = false;
                this.ChannelHandlerOwnsInstanceContextThrottle = 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();
             }
         }
     }
 }
        internal static void Register(ChannelHandler handler, RequestContext request)
        {
            BufferedReceiveBinder bufferedBinder = handler.Binder as BufferedReceiveBinder;
            Fx.Assert(bufferedBinder != null, "ChannelHandler.Binder is not a BufferedReceiveBinder");

            bufferedBinder.InjectRequest(request);
            handler.Register();
        }
            public AcknowledgementCompleteAsyncResult(
                ReceiveContext receiveContext,
                TimeSpan timeout,
                ref MessageRpc rpc,
                Transaction transaction,
                AsyncCallback callback,
                object state) : base(callback, state)
            {
                this.receiveContext = receiveContext;
                this.currentTransaction = transaction;
                this.channelHandler = rpc.channelHandler;
                this.resumableRPC = rpc.Pause();

                bool completeThrew = true;
                try
                {
                    bool completed = this.Complete(timeout);
                    completeThrew = false;

                    if (completed)
                    {
                        this.resumableRPC = null;
                        rpc.UnPause();
                        this.Complete(true);
                    }
                }
                finally
                {
                    if (completeThrew)
                    {
                        rpc.UnPause();
                    }
                }
            }
Esempio n. 23
0
 public MessageRpcInvokeNotification(ServiceModelActivity activity, ChannelHandler handler)
 {
     this.activity = activity;
     this.handler = handler;
 }
Esempio n. 24
0
        private void Dispatch()
        {
            ListenerChannel channel = _channel;
            SessionIdleManager idleManager = _idleManager;
            _channel = null;
            _idleManager = null;

            try
            {
                if (channel != null)
                {
                    ChannelHandler handler = new ChannelHandler(_listenerBinder.MessageVersion, channel.Binder, this, idleManager);

                    if (!channel.Binder.HasSession)
                    {
                        _channelDispatcher.Channels.Add(channel.Binder.Channel);
                    }

                    if (channel.Binder is DuplexChannelBinder)
                    {
                        DuplexChannelBinder duplexChannelBinder = channel.Binder as DuplexChannelBinder;
                        duplexChannelBinder.ChannelHandler = handler;
                        duplexChannelBinder.DefaultCloseTimeout = this.DefaultCloseTimeout;

                        if (_timeouts == null)
                            duplexChannelBinder.DefaultSendTimeout = ServiceDefaults.SendTimeout;
                        else
                            duplexChannelBinder.DefaultSendTimeout = _timeouts.SendTimeout;
                    }

                    ChannelHandler.Register(handler);
                    channel = null;
                    idleManager = null;
                }
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                this.HandleError(e);
            }
            finally
            {
                if (channel != null)
                {
                    channel.Binder.Channel.Abort();
                    if (idleManager != null)
                    {
                        idleManager.CancelTimer();
                    }
                }
            }
        }