internal TransactedBatchContext CreateTransactedBatchContext()
 {
     lock (thisLock)
     {
         TransactedBatchContext context = new TransactedBatchContext(this);
         ++this.currentConcurrentBatches;
         return(context);
     }
 }
 internal TransactedBatchContext CreateTransactedBatchContext()
 {
     lock (this.thisLock)
     {
         TransactedBatchContext context = new TransactedBatchContext(this);
         this.currentConcurrentBatches++;
         return context;
     }
 }
 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 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);
         }
     }
 }
Example #5
0
 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 void Complete(Exception error)
 {
     if (!object.ReferenceEquals(this.Current, null))
     {
         TransactedBatchContext batchContext = this.rpc.TransactedBatchContext;
         if (null != batchContext)
         {
             if (null == error)
             {
                 batchContext.Complete();
             }
             else
             {
                 batchContext.ForceRollback();
             }
             batchContext.InDispatch = false;
         }
         else
         {
             if (this.transactionSetComplete)
             {
                 // Commit the transaction when TransactionSetComplete() is called and
                 // even when an exception(non transactional) happens after this call.
                 rpc.InstanceContext.Transaction.CompletePendingTransaction(this.Current, null);
                 if (DiagnosticUtility.ShouldTraceInformation)
                 {
                     TraceUtility.TraceEvent(TraceEventType.Information,
                                             TraceCode.TxCompletionStatusCompletedForSetComplete,
                                             SR.GetString(SR.TraceCodeTxCompletionStatusCompletedForSetComplete,
                                                          this.Current.TransactionInformation.LocalIdentifier,
                                                          this.rpc.Operation.Name)
                                             );
                 }
             }
             else if (this.IsCompleted || (error != null))
             {
                 rpc.InstanceContext.Transaction.CompletePendingTransaction(this.Current, error);
             }
         }
         if (this.rpc.Operation.IsInsideTransactedReceiveScope)
         {
             //We are done with the message processing associated with this TransactionRpcFacet so a commit that may have
             //been started by a TransactedReceiveScope can move forward.
             this.CompleteDependentClone();
         }
         this.Current = null;
     }
 }
 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);
 }
 internal void Complete(Exception error)
 {
     if (!object.ReferenceEquals(this.Current, null))
     {
         TransactedBatchContext transactedBatchContext = this.rpc.TransactedBatchContext;
         if (transactedBatchContext != null)
         {
             if (error == null)
             {
                 transactedBatchContext.Complete();
             }
             else
             {
                 transactedBatchContext.ForceRollback();
             }
             transactedBatchContext.InDispatch = false;
         }
         else if (this.transactionSetComplete)
         {
             this.rpc.InstanceContext.Transaction.CompletePendingTransaction(this.Current, null);
             if (DiagnosticUtility.ShouldTraceInformation)
             {
                 TraceUtility.TraceEvent(TraceEventType.Information, 0xe0007, System.ServiceModel.SR.GetString("TraceCodeTxCompletionStatusCompletedForSetComplete", new object[] { this.Current.TransactionInformation.LocalIdentifier, this.rpc.Operation.Name }));
             }
         }
         else if (this.IsCompleted || (error != null))
         {
             this.rpc.InstanceContext.Transaction.CompletePendingTransaction(this.Current, error);
         }
         if (this.rpc.Operation.IsInsideTransactedReceiveScope)
         {
             this.CompleteDependentClone();
         }
         this.Current = null;
     }
 }
        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 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;
        }
        bool TransactedBatchLoop()
        {
            if (null != this.transactedBatchContext)
            {
                if (this.transactedBatchContext.InDispatch)
                {
                    this.transactedBatchContext.ForceRollback();
                    this.transactedBatchContext.InDispatch = false;
                }
                if (!this.transactedBatchContext.IsActive)
                {
                    if (!this.isMainTransactedBatchHandler)
                    {
                        return false;
                    }
                    this.transactedBatchContext = null;
                }
            }

            if (null == this.transactedBatchContext)
            {
                try
                {
                    this.receiver.WaitForMessage();
                }
                catch (Exception ex)
                {
                    if (Fx.IsFatal(ex))
                    {
                        throw;
                    }

                    if (!this.HandleError(ex))
                    {
                        throw;
                    }
                }
                this.transactedBatchContext = this.sharedTransactedBatchContext.CreateTransactedBatchContext();
            }

            OperationContext existingOperationContext = OperationContext.Current;

            try
            {
                OperationContext currentOperationContext = new OperationContext(this.host);
                OperationContext.Current = currentOperationContext;

                RequestContext request;

                while (this.transactedBatchContext.IsActive)
                {
                    this.requestInfo.Cleanup();

                    bool valid = TryTransactionalReceive(this.transactedBatchContext.Transaction, out request);

                    if (!valid)
                    {
                        if (this.IsOpen)
                        {
                            this.transactedBatchContext.ForceCommit();
                            return true;
                        }
                        else
                        {
                            this.transactedBatchContext.ForceRollback();
                            return false;
                        }
                    }

                    if (null == request)
                    {
                        this.transactedBatchContext.ForceRollback();
                        return false;
                    }

                    TransactionMessageProperty.Set(this.transactedBatchContext.Transaction, request.RequestMessage);

                    this.transactedBatchContext.InDispatch = true;
                    if (!HandleRequest(request, currentOperationContext))
                    {
                        return false;
                    }

                    if (this.transactedBatchContext.InDispatch)
                    {
                        this.transactedBatchContext.ForceRollback();
                        this.transactedBatchContext.InDispatch = false;
                        return true;
                    }

                    if (!TryAcquirePump())
                    {
                        Fx.Assert("System.ServiceModel.Dispatcher.ChannelHandler.TransactedBatchLoop(): (TryAcquiredPump returned false)");
                        return false;
                    }

                    currentOperationContext.Recycle();
                }
            }
            finally
            {
                OperationContext.Current = existingOperationContext;
            }
            return true;
        }
Example #12
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 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);
         }
     }
 }
 private bool TransactedBatchLoop()
 {
     if (this.transactedBatchContext != null)
     {
         if (this.transactedBatchContext.InDispatch)
         {
             this.transactedBatchContext.ForceRollback();
             this.transactedBatchContext.InDispatch = false;
         }
         if (!this.transactedBatchContext.IsActive)
         {
             if (!this.isMainTransactedBatchHandler)
             {
                 return false;
             }
             this.transactedBatchContext = null;
         }
     }
     if (this.transactedBatchContext == null)
     {
         try
         {
             this.receiver.WaitForMessage();
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             if (!this.HandleError(exception))
             {
                 throw;
             }
         }
         this.transactedBatchContext = this.sharedTransactedBatchContext.CreateTransactedBatchContext();
     }
     OperationContext current = OperationContext.Current;
     try
     {
         OperationContext currentOperationContext = new OperationContext(this.host);
         OperationContext.Current = currentOperationContext;
         while (this.transactedBatchContext.IsActive)
         {
             RequestContext context3;
             this.requestInfo.Cleanup();
             if (!this.TryTransactionalReceive(this.transactedBatchContext.Transaction, out context3))
             {
                 if (this.IsOpen)
                 {
                     this.transactedBatchContext.ForceCommit();
                     return true;
                 }
                 this.transactedBatchContext.ForceRollback();
                 return false;
             }
             if (context3 == null)
             {
                 this.transactedBatchContext.ForceRollback();
                 return false;
             }
             TransactionMessageProperty.Set(this.transactedBatchContext.Transaction, context3.RequestMessage);
             this.transactedBatchContext.InDispatch = true;
             if (!this.HandleRequest(context3, currentOperationContext))
             {
                 return false;
             }
             if (this.transactedBatchContext.InDispatch)
             {
                 this.transactedBatchContext.ForceRollback();
                 this.transactedBatchContext.InDispatch = false;
                 return true;
             }
             if (!this.TryAcquirePump())
             {
                 return false;
             }
             currentOperationContext.Recycle();
         }
     }
     finally
     {
         OperationContext.Current = current;
     }
     return true;
 }