コード例 #1
0
            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();
                    }
                }
            }
コード例 #2
0
        private void BeginReply(ref MessageRpc rpc)
        {
            bool success = false;

            try
            {
                IResumeMessageRpc resume = rpc.Pause();

                rpc.AsyncResult = rpc.RequestContext.BeginReply(rpc.Reply, rpc.ReplyTimeoutHelper.RemainingTime(),
                                                                s_onReplyCompleted, resume);
                success = true;

                if (rpc.AsyncResult.CompletedSynchronously)
                {
                    rpc.UnPause();
                }
            }
            catch (CommunicationException e)
            {
                _error.HandleError(e);
            }
            catch (TimeoutException e)
            {
                _error.HandleError(e);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                if (!_error.HandleError(e))
                {
                    rpc.RequestContextThrewOnReply = true;
                    rpc.CanSendReply = false;
                }
            }
            finally
            {
                if (!success)
                {
                    rpc.UnPause();
                }
            }
        }
コード例 #3
0
        internal void InvokeBegin(ref MessageRpc rpc)
        {
            if (rpc.Error == null)
            {
                object target = rpc.Instance;
                this.DeserializeInputs(ref rpc);
                this.InspectInputs(ref rpc);

                ValidateMustUnderstand(ref rpc);

                IAsyncResult result;
                bool         isBeginSuccessful = false;

                IResumeMessageRpc resumeRpc = rpc.Pause();
                try
                {
                    result            = Invoker.InvokeBegin(target, rpc.InputParameters, invokeCallback, resumeRpc);
                    isBeginSuccessful = true;
                }
                finally
                {
                    if (!isBeginSuccessful)
                    {
                        rpc.UnPause();
                    }
                }

                if (result == null)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException("IOperationInvoker.BeginDispatch"),
                                                        rpc.Request);
                }

                if (result.CompletedSynchronously)
                {
                    // if the async call completed synchronously, then the responsibility to call
                    // ProcessMessage{6,7,Cleanup} still remains on this thread
                    rpc.UnPause();
                    rpc.AsyncResult = result;
                }
            }
        }
コード例 #4
0
        private void ProcessMessage5(ref MessageRpc rpc)
        {
            rpc.NextProcessor = _processMessage6;

            bool success = false;

            try
            {
                // If async call completes in sync, it tells us through the gate below
                rpc.PrepareInvokeContinueGate();

                SetActivityIdOnThread(ref rpc);

                rpc.Operation.InvokeBegin(ref rpc);
                success = true;
            }
            finally
            {
                try
                {
                    if (rpc.IsPaused)
                    {
                        // Check if the callback produced the async result and set it back on the RPC on this stack
                        // and proceed only if the gate was signaled by the callback and completed synchronously
                        if (rpc.UnlockInvokeContinueGate(out rpc.AsyncResult))
                        {
                            rpc.UnPause();
                        }
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    if (success && !rpc.IsPaused)
                    {
                        throw;
                    }

                    _error.HandleError(e);
                }
            }

            // Proceed if rpc is unpaused and invoke begin was successful.
            if (!rpc.IsPaused)
            {
                this.ProcessMessage6(ref rpc);
            }
        }
コード例 #5
0
            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();
                    }
                }
            }
コード例 #6
0
        internal void InvokeBegin(ref MessageRpc rpc)
        {
            if (rpc.Error == null)
            {
                try
                {
                    this.InitializeCallContext(ref rpc);
                    object target = rpc.Instance;
                    this.DeserializeInputs(ref rpc);
                    this.InspectInputs(ref rpc);

                    ValidateMustUnderstand(ref rpc);

                    IAsyncResult result = null;
                    IDisposable impersonationContext = null;
                    IPrincipal originalPrincipal = null;
                    bool isThreadPrincipalSet = false;
                    bool isConcurrent = this.Parent.IsConcurrent(ref rpc);

                    try
                    {
                        if (this.parent.RequireClaimsPrincipalOnOperationContext)
                        {
                            SetClaimsPrincipalToOperationContext(rpc);
                        }
                       
                        if (this.parent.SecurityImpersonation != null)
                        {
                            this.parent.SecurityImpersonation.StartImpersonation(ref rpc, out impersonationContext, out originalPrincipal, out isThreadPrincipalSet);
                        }
                        IManualConcurrencyOperationInvoker manualInvoker = this.Invoker as IManualConcurrencyOperationInvoker;

                        if (this.isSynchronous)
                        {
                            if (manualInvoker != null && isConcurrent)
                            {
                                if (this.bufferedReceiveEnabled)
                                {
                                    rpc.OperationContext.IncomingMessageProperties.Add(
                                        BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc));
                                }
                                rpc.ReturnParameter = manualInvoker.Invoke(target, rpc.InputParameters, rpc.InvokeNotification, out rpc.OutputParameters);
                            }
                            else
                            {
                                rpc.ReturnParameter = this.Invoker.Invoke(target, rpc.InputParameters, out rpc.OutputParameters);
                            }
                        }
                        else
                        {
                            bool isBeginSuccessful = false;

                            if (manualInvoker != null && isConcurrent && this.bufferedReceiveEnabled)
                            {
                                // This will modify the rpc, it has to be done before rpc.Pause
                                // since IResumeMessageRpc implementation keeps reference of rpc.
                                // This is to ensure consistent rpc whether or not InvokeBegin completed
                                // synchronously or asynchronously.
                                rpc.OperationContext.IncomingMessageProperties.Add(
                                    BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc));
                            }

                            IResumeMessageRpc resumeRpc = rpc.Pause();
                            try
                            {
                                if (manualInvoker != null && isConcurrent)
                                {
                                    result = manualInvoker.InvokeBegin(target, rpc.InputParameters, rpc.InvokeNotification, invokeCallback, resumeRpc);
                                }
                                else
                                {
                                    result = this.Invoker.InvokeBegin(target, rpc.InputParameters, invokeCallback, resumeRpc);
                                }

                                isBeginSuccessful = true;
                                // if the call above actually went async, then responsibility to call 
                                // ProcessMessage{6,7,Cleanup} has been transferred to InvokeCallback
                            }
                            finally
                            {
                                if (!isBeginSuccessful)
                                {
                                    rpc.UnPause();
                                }
                            }
                        }
                    }
                    finally
                    {
                        try
                        {
                            if (this.parent.SecurityImpersonation != null)
                            {
                                this.parent.SecurityImpersonation.StopImpersonation(ref rpc, impersonationContext, originalPrincipal, isThreadPrincipalSet);
                            }
                        }
#pragma warning suppress 56500 // covered by FxCOP
                        catch
                        {
                            string message = null;
                            try
                            {
                                message = SR.GetString(SR.SFxRevertImpersonationFailed0);
                            }
                            finally
                            {
                                DiagnosticUtility.FailFast(message);
                            }
                        }
                    }

                    if (this.isSynchronous)
                    {
                        this.InspectOutputs(ref rpc);

                        this.SerializeOutputs(ref rpc);
                    }
                    else
                    {
                        if (result == null)
                        {
                            throw TraceUtility.ThrowHelperError(new ArgumentNullException("IOperationInvoker.BeginDispatch"), rpc.Request);
                        }

                        if (result.CompletedSynchronously)
                        {
                            // if the async call completed synchronously, then the responsibility to call
                            // ProcessMessage{6,7,Cleanup} still remains on this thread
                            rpc.UnPause();
                            rpc.AsyncResult = result;
                        }
                    }
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch { throw; } // Make sure user Exception filters are not impersonated.
                finally
                {
                    this.UninitializeCallContext(ref rpc);
                }
            }
        }
コード例 #7
0
        private void ProcessMessage5(ref MessageRpc rpc)
        {
            rpc.NextProcessor = _processMessage6;

            bool success = false;
            try
            {
                // If async call completes in sync, it tells us through the gate below
                rpc.PrepareInvokeContinueGate();

                SetActivityIdOnThread(ref rpc);

                rpc.Operation.InvokeBegin(ref rpc);
                success = true;
            }
            finally
            {
                try
                {
                    if (rpc.IsPaused)
                    {
                        // Check if the callback produced the async result and set it back on the RPC on this stack 
                        // and proceed only if the gate was signaled by the callback and completed synchronously
                        if (rpc.UnlockInvokeContinueGate(out rpc.AsyncResult))
                        {
                            rpc.UnPause();
                        }
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    if (success && !rpc.IsPaused)
                    {
                        throw;
                    }

                    _error.HandleError(e);
                }
            }

            // Proceed if rpc is unpaused and invoke begin was successful.
            if (!rpc.IsPaused)
            {
                this.ProcessMessage6(ref rpc);
            }
        }
 private void BeginFinalizeCorrelation(ref MessageRpc rpc)
 {
     CorrelationCallbackMessageProperty property;
     Message reply = rpc.Reply;
     if ((((reply != null) && (rpc.Error == null)) && (((rpc.transaction == null) || (rpc.transaction.Current == null)) || (rpc.transaction.Current.TransactionInformation.Status == TransactionStatus.Active))) && CorrelationCallbackMessageProperty.TryGet(reply, out property))
     {
         if (property.IsFullyDefined)
         {
             bool flag = false;
             try
             {
                 try
                 {
                     rpc.RequestContextThrewOnReply = true;
                     rpc.CorrelationCallback = property;
                     IResumeMessageRpc state = rpc.Pause();
                     rpc.AsyncResult = rpc.CorrelationCallback.BeginFinalizeCorrelation(reply, rpc.ReplyTimeoutHelper.RemainingTime(), onFinalizeCorrelationCompleted, state);
                     flag = true;
                     if (rpc.AsyncResult.CompletedSynchronously)
                     {
                         rpc.UnPause();
                     }
                 }
                 catch (Exception exception)
                 {
                     if (Fx.IsFatal(exception))
                     {
                         throw;
                     }
                     if (!this.error.HandleError(exception))
                     {
                         rpc.CorrelationCallback = null;
                         rpc.CanSendReply = false;
                     }
                 }
                 return;
             }
             finally
             {
                 if (!flag)
                 {
                     rpc.UnPause();
                 }
             }
         }
         rpc.CorrelationCallback = new RpcCorrelationCallbackMessageProperty(property, this, ref rpc);
         reply.Properties[CorrelationCallbackMessageProperty.Name] = rpc.CorrelationCallback;
     }
 }
コード例 #9
0
        void BeginFinalizeCorrelation(ref MessageRpc rpc)
        {
            Message reply = rpc.Reply;

            if (reply != null && rpc.Error == null)
            {
                if (rpc.transaction != null && rpc.transaction.Current != null &&
                    rpc.transaction.Current.TransactionInformation.Status != TransactionStatus.Active)
                {
                    return;
                }

                CorrelationCallbackMessageProperty callback;

                if (CorrelationCallbackMessageProperty.TryGet(reply, out callback))
                {
                    if (callback.IsFullyDefined)
                    {
                        bool success = false;

                        try
                        {
                            rpc.RequestContextThrewOnReply = true;
                            rpc.CorrelationCallback = callback;

                            IResumeMessageRpc resume = rpc.Pause();
                            rpc.AsyncResult = rpc.CorrelationCallback.BeginFinalizeCorrelation(reply,
                                rpc.ReplyTimeoutHelper.RemainingTime(), onFinalizeCorrelationCompleted, resume);
                            success = true;

                            if (rpc.AsyncResult.CompletedSynchronously)
                            {
                                rpc.UnPause();
                            }
                        }
                        catch (Exception e)
                        {
                            if (Fx.IsFatal(e))
                            {
                                throw;
                            }

                            if (!this.error.HandleError(e))
                            {
                                rpc.CorrelationCallback = null;
                                rpc.CanSendReply = false;
                            }
                        }
                        finally
                        {
                            if (!success)
                            {
                                rpc.UnPause();
                            }
                        }
                    }
                    else
                    {
                        rpc.CorrelationCallback = new RpcCorrelationCallbackMessageProperty(callback, this, ref rpc);
                        reply.Properties[CorrelationCallbackMessageProperty.Name] = rpc.CorrelationCallback;
                    }
                }
            }
        }
コード例 #10
0
 internal void InvokeBegin(ref MessageRpc rpc)
 {
     if (rpc.Error == null)
     {
         try
         {
             this.InitializeCallContext(ref rpc);
             object instance = rpc.Instance;
             this.DeserializeInputs(ref rpc);
             this.InspectInputs(ref rpc);
             this.ValidateMustUnderstand(ref rpc);
             IAsyncResult result = null;
             IDisposable  impersonationContext = null;
             IPrincipal   originalPrincipal    = null;
             bool         isThreadPrincipalSet = false;
             bool         flag2 = this.Parent.IsConcurrent(ref rpc);
             try
             {
                 if (this.parent.SecurityImpersonation != null)
                 {
                     this.parent.SecurityImpersonation.StartImpersonation(ref rpc, out impersonationContext, out originalPrincipal, out isThreadPrincipalSet);
                 }
                 IManualConcurrencyOperationInvoker invoker = this.Invoker as IManualConcurrencyOperationInvoker;
                 if (this.isSynchronous)
                 {
                     if ((invoker != null) && flag2)
                     {
                         if (this.bufferedReceiveEnabled)
                         {
                             rpc.OperationContext.IncomingMessageProperties.Add(BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc));
                         }
                         rpc.ReturnParameter = invoker.Invoke(instance, rpc.InputParameters, rpc.InvokeNotification, out rpc.OutputParameters);
                     }
                     else
                     {
                         rpc.ReturnParameter = this.Invoker.Invoke(instance, rpc.InputParameters, out rpc.OutputParameters);
                     }
                 }
                 else
                 {
                     bool flag3 = false;
                     if (((invoker != null) && flag2) && this.bufferedReceiveEnabled)
                     {
                         rpc.OperationContext.IncomingMessageProperties.Add(BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc));
                     }
                     IResumeMessageRpc state = rpc.Pause();
                     try
                     {
                         if ((invoker != null) && flag2)
                         {
                             result = invoker.InvokeBegin(instance, rpc.InputParameters, rpc.InvokeNotification, invokeCallback, state);
                         }
                         else
                         {
                             result = this.Invoker.InvokeBegin(instance, rpc.InputParameters, invokeCallback, state);
                         }
                         flag3 = true;
                     }
                     finally
                     {
                         if (!flag3)
                         {
                             rpc.UnPause();
                         }
                     }
                 }
             }
             finally
             {
                 try
                 {
                     if (this.parent.SecurityImpersonation != null)
                     {
                         this.parent.SecurityImpersonation.StopImpersonation(ref rpc, impersonationContext, originalPrincipal, isThreadPrincipalSet);
                     }
                 }
                 catch
                 {
                     string message = null;
                     try
                     {
                         message = System.ServiceModel.SR.GetString("SFxRevertImpersonationFailed0");
                     }
                     finally
                     {
                         DiagnosticUtility.FailFast(message);
                     }
                 }
             }
             if (this.isSynchronous)
             {
                 this.InspectOutputs(ref rpc);
                 this.SerializeOutputs(ref rpc);
             }
             else
             {
                 if (result == null)
                 {
                     throw TraceUtility.ThrowHelperError(new ArgumentNullException("IOperationInvoker.BeginDispatch"), rpc.Request);
                 }
                 if (result.CompletedSynchronously)
                 {
                     rpc.UnPause();
                     rpc.AsyncResult = result;
                 }
             }
         }
         catch
         {
             throw;
         }
         finally
         {
             this.UninitializeCallContext(ref rpc);
         }
     }
 }
 internal void InvokeBegin(ref MessageRpc rpc)
 {
     if (rpc.Error == null)
     {
         try
         {
             this.InitializeCallContext(ref rpc);
             object instance = rpc.Instance;
             this.DeserializeInputs(ref rpc);
             this.InspectInputs(ref rpc);
             this.ValidateMustUnderstand(ref rpc);
             IAsyncResult result = null;
             IDisposable impersonationContext = null;
             IPrincipal originalPrincipal = null;
             bool isThreadPrincipalSet = false;
             bool flag2 = this.Parent.IsConcurrent(ref rpc);
             try
             {
                 if (this.parent.SecurityImpersonation != null)
                 {
                     this.parent.SecurityImpersonation.StartImpersonation(ref rpc, out impersonationContext, out originalPrincipal, out isThreadPrincipalSet);
                 }
                 IManualConcurrencyOperationInvoker invoker = this.Invoker as IManualConcurrencyOperationInvoker;
                 if (this.isSynchronous)
                 {
                     if ((invoker != null) && flag2)
                     {
                         if (this.bufferedReceiveEnabled)
                         {
                             rpc.OperationContext.IncomingMessageProperties.Add(BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc));
                         }
                         rpc.ReturnParameter = invoker.Invoke(instance, rpc.InputParameters, rpc.InvokeNotification, out rpc.OutputParameters);
                     }
                     else
                     {
                         rpc.ReturnParameter = this.Invoker.Invoke(instance, rpc.InputParameters, out rpc.OutputParameters);
                     }
                 }
                 else
                 {
                     bool flag3 = false;
                     if (((invoker != null) && flag2) && this.bufferedReceiveEnabled)
                     {
                         rpc.OperationContext.IncomingMessageProperties.Add(BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc));
                     }
                     IResumeMessageRpc state = rpc.Pause();
                     try
                     {
                         if ((invoker != null) && flag2)
                         {
                             result = invoker.InvokeBegin(instance, rpc.InputParameters, rpc.InvokeNotification, invokeCallback, state);
                         }
                         else
                         {
                             result = this.Invoker.InvokeBegin(instance, rpc.InputParameters, invokeCallback, state);
                         }
                         flag3 = true;
                     }
                     finally
                     {
                         if (!flag3)
                         {
                             rpc.UnPause();
                         }
                     }
                 }
             }
             finally
             {
                 try
                 {
                     if (this.parent.SecurityImpersonation != null)
                     {
                         this.parent.SecurityImpersonation.StopImpersonation(ref rpc, impersonationContext, originalPrincipal, isThreadPrincipalSet);
                     }
                 }
                 catch
                 {
                     string message = null;
                     try
                     {
                         message = System.ServiceModel.SR.GetString("SFxRevertImpersonationFailed0");
                     }
                     finally
                     {
                         DiagnosticUtility.FailFast(message);
                     }
                 }
             }
             if (this.isSynchronous)
             {
                 this.InspectOutputs(ref rpc);
                 this.SerializeOutputs(ref rpc);
             }
             else
             {
                 if (result == null)
                 {
                     throw TraceUtility.ThrowHelperError(new ArgumentNullException("IOperationInvoker.BeginDispatch"), rpc.Request);
                 }
                 if (result.CompletedSynchronously)
                 {
                     rpc.UnPause();
                     rpc.AsyncResult = result;
                 }
             }
         }
         catch
         {
             throw;
         }
         finally
         {
             this.UninitializeCallContext(ref rpc);
         }
     }
 }
コード例 #12
0
        internal void InvokeBegin(ref MessageRpc rpc)
        {
            if (rpc.Error == null)
            {
                try
                {
                    this.InitializeCallContext(ref rpc);
                    object target = rpc.Instance;
                    this.DeserializeInputs(ref rpc);
                    this.InspectInputs(ref rpc);

                    ValidateMustUnderstand(ref rpc);

                    IAsyncResult result = null;
                    IDisposable  impersonationContext = null;
                    IPrincipal   originalPrincipal    = null;
                    bool         isThreadPrincipalSet = false;
                    bool         isConcurrent         = this.Parent.IsConcurrent(ref rpc);

                    try
                    {
                        if (this.parent.RequireClaimsPrincipalOnOperationContext)
                        {
                            SetClaimsPrincipalToOperationContext(rpc);
                        }

                        if (this.parent.SecurityImpersonation != null)
                        {
                            this.parent.SecurityImpersonation.StartImpersonation(ref rpc, out impersonationContext, out originalPrincipal, out isThreadPrincipalSet);
                        }
                        IManualConcurrencyOperationInvoker manualInvoker = this.Invoker as IManualConcurrencyOperationInvoker;

                        if (DS.OperationInvokerIsEnabled())
                        {
                            DS.InvokeOperationStart(this.Invoker.GetType(), Stopwatch.GetTimestamp());
                        }

                        if (this.isSynchronous)
                        {
                            if (manualInvoker != null && isConcurrent)
                            {
                                if (this.bufferedReceiveEnabled)
                                {
                                    rpc.OperationContext.IncomingMessageProperties.Add(
                                        BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc));
                                }
                                rpc.ReturnParameter = manualInvoker.Invoke(target, rpc.InputParameters, rpc.InvokeNotification, out rpc.OutputParameters);
                            }
                            else
                            {
                                rpc.ReturnParameter = this.Invoker.Invoke(target, rpc.InputParameters, out rpc.OutputParameters);
                            }
                        }
                        else
                        {
                            bool isBeginSuccessful = false;

                            if (manualInvoker != null && isConcurrent && this.bufferedReceiveEnabled)
                            {
                                // This will modify the rpc, it has to be done before rpc.Pause
                                // since IResumeMessageRpc implementation keeps reference of rpc.
                                // This is to ensure consistent rpc whether or not InvokeBegin completed
                                // synchronously or asynchronously.
                                rpc.OperationContext.IncomingMessageProperties.Add(
                                    BufferedReceiveMessageProperty.Name, new BufferedReceiveMessageProperty(ref rpc));
                            }

                            IResumeMessageRpc resumeRpc = rpc.Pause();
                            try
                            {
                                if (manualInvoker != null && isConcurrent)
                                {
                                    result = manualInvoker.InvokeBegin(target, rpc.InputParameters, rpc.InvokeNotification, invokeCallback, resumeRpc);
                                }
                                else
                                {
                                    result = this.Invoker.InvokeBegin(target, rpc.InputParameters, invokeCallback, resumeRpc);
                                }

                                isBeginSuccessful = true;
                                // if the call above actually went async, then responsibility to call
                                // ProcessMessage{6,7,Cleanup} has been transferred to InvokeCallback
                            }
                            finally
                            {
                                if (!isBeginSuccessful)
                                {
                                    rpc.UnPause();
                                }
                            }
                        }
                    }
                    finally
                    {
                        try
                        {
                            if (this.parent.SecurityImpersonation != null)
                            {
                                this.parent.SecurityImpersonation.StopImpersonation(ref rpc, impersonationContext, originalPrincipal, isThreadPrincipalSet);
                            }
                        }
#pragma warning suppress 56500 // covered by FxCOP
                        catch
                        {
                            string message = null;
                            try
                            {
                                message = SR.GetString(SR.SFxRevertImpersonationFailed0);
                            }
                            finally
                            {
                                DiagnosticUtility.FailFast(message);
                            }
                        }

                        if (this.isSynchronous && DS.OperationInvokerIsEnabled())
                        {
                            DS.InvokeOperationStop(Stopwatch.GetTimestamp());
                        }
                    }

                    if (this.isSynchronous)
                    {
                        this.InspectOutputs(ref rpc);

                        this.SerializeOutputs(ref rpc);
                    }
                    else
                    {
                        if (result == null)
                        {
                            throw TraceUtility.ThrowHelperError(new ArgumentNullException("IOperationInvoker.BeginDispatch"), rpc.Request);
                        }

                        if (result.CompletedSynchronously)
                        {
                            // if the async call completed synchronously, then the responsibility to call
                            // ProcessMessage{6,7,Cleanup} still remains on this thread
                            rpc.UnPause();
                            rpc.AsyncResult = result;
                        }
                    }
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch { throw; } // Make sure user Exception filters are not impersonated.
                finally
                {
                    this.UninitializeCallContext(ref rpc);
                }
            }
        }
 private void ProcessMessage5(ref MessageRpc rpc)
 {
     rpc.NextProcessor = this.processMessage6;
     try
     {
         bool flag = false;
         try
         {
             if (!rpc.Operation.IsSynchronous)
             {
                 rpc.PrepareInvokeContinueGate();
             }
             if (this.transaction != null)
             {
                 this.transaction.InitializeCallContext(ref rpc);
             }
             rpc.Operation.InvokeBegin(ref rpc);
             flag = true;
         }
         finally
         {
             try
             {
                 try
                 {
                     if (this.transaction != null)
                     {
                         this.transaction.ClearCallContext(ref rpc);
                     }
                 }
                 finally
                 {
                     if ((!rpc.Operation.IsSynchronous && rpc.IsPaused) && rpc.UnlockInvokeContinueGate(out rpc.AsyncResult))
                     {
                         rpc.UnPause();
                     }
                 }
             }
             catch (Exception exception)
             {
                 if (Fx.IsFatal(exception))
                 {
                     throw;
                 }
                 if (flag && (rpc.Operation.IsSynchronous || !rpc.IsPaused))
                 {
                     throw;
                 }
                 this.error.HandleError(exception);
             }
         }
     }
     catch
     {
         throw;
     }
     if (!rpc.IsPaused)
     {
         if (rpc.Operation.IsSynchronous)
         {
             this.ProcessMessage8(ref rpc);
         }
         else
         {
             this.ProcessMessage6(ref rpc);
         }
     }
 }
 private void BeginReply(ref MessageRpc rpc)
 {
     bool flag = false;
     try
     {
         IResumeMessageRpc state = rpc.Pause();
         rpc.AsyncResult = rpc.RequestContext.BeginReply(rpc.Reply, rpc.ReplyTimeoutHelper.RemainingTime(), onReplyCompleted, state);
         flag = true;
         if (rpc.AsyncResult.CompletedSynchronously)
         {
             rpc.UnPause();
         }
     }
     catch (CommunicationException exception)
     {
         this.error.HandleError(exception);
     }
     catch (TimeoutException exception2)
     {
         this.error.HandleError(exception2);
     }
     catch (Exception exception3)
     {
         if (Fx.IsFatal(exception3))
         {
             throw;
         }
         if (DiagnosticUtility.ShouldTraceError)
         {
             TraceUtility.TraceEvent(TraceEventType.Error, 0x80034, System.ServiceModel.SR.GetString("TraceCodeServiceOperationExceptionOnReply"), this, exception3);
         }
         if (!this.error.HandleError(exception3))
         {
             rpc.RequestContextThrewOnReply = true;
             rpc.CanSendReply = false;
         }
     }
     finally
     {
         if (!flag)
         {
             rpc.UnPause();
         }
     }
 }
コード例 #15
0
        void ProcessMessage5(ref MessageRpc rpc)
        {
            rpc.NextProcessor = this.processMessage6;

            try
            {
                bool success = false;
                try
                {
                    if (!rpc.Operation.IsSynchronous)
                    {
                        // If async call completes in [....], it tells us through the gate below
                        rpc.PrepareInvokeContinueGate();
                    }

                    if (this.transaction != null)
                    {
                        this.transaction.InitializeCallContext(ref rpc);
                    }

                    SetActivityIdOnThread(ref rpc);

                    rpc.Operation.InvokeBegin(ref rpc);
                    success = true;
                }
                finally
                {
                    try
                    {
                        try
                        {
                            if (this.transaction != null)
                            {
                                this.transaction.ClearCallContext(ref rpc);
                            }
                        }
                        finally
                        {
                            if (!rpc.Operation.IsSynchronous && rpc.IsPaused)
                            {
                                // Check if the callback produced the async result and set it back on the RPC on this stack 
                                // and proceed only if the gate was signaled by the callback and completed synchronously
                                if (rpc.UnlockInvokeContinueGate(out rpc.AsyncResult))
                                {
                                    rpc.UnPause();
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }

                        if (success && (rpc.Operation.IsSynchronous || !rpc.IsPaused))
                        {
                            throw;
                        }

                        this.error.HandleError(e);
                    }
                }
            }
            catch
            {
                // This catch clause forces ClearCallContext to run prior to stackwalks exiting this frame.
                throw;
            }

            // Proceed if rpc is unpaused and invoke begin was successful.
            if (!rpc.IsPaused)
            {
                this.ProcessMessage6(ref rpc);
            }
        }
コード例 #16
0
        internal void InvokeBegin(ref MessageRpc rpc)
        {
            if (rpc.Error == null)
            {
                object target = rpc.Instance;
                this.DeserializeInputs(ref rpc);
                this.InspectInputs(ref rpc);

                ValidateMustUnderstand(ref rpc);

                IAsyncResult result;
                bool isBeginSuccessful = false;

                IResumeMessageRpc resumeRpc = rpc.Pause();
                try
                {
                    result = Invoker.InvokeBegin(target, rpc.InputParameters, invokeCallback, resumeRpc);
                    isBeginSuccessful = true;
                }
                finally
                {
                    if (!isBeginSuccessful)
                    {
                        rpc.UnPause();
                    }
                }

                if (result == null)
                {
                    throw TraceUtility.ThrowHelperError(new ArgumentNullException("IOperationInvoker.BeginDispatch"),
                        rpc.Request);
                }

                if (result.CompletedSynchronously)
                {
                    // if the async call completed synchronously, then the responsibility to call
                    // ProcessMessage{6,7,Cleanup} still remains on this thread
                    rpc.UnPause();
                    rpc.AsyncResult = result;
                }
            }
        }
コード例 #17
0
        bool AcquireDynamicInstanceContextCore(ref MessageRpc rpc)
        {
            bool success = rpc.InstanceContext.QuotaThrottle.Acquire(rpc.Pause());

            if (success)
            {
                rpc.UnPause();
            }

            return success;
        }
コード例 #18
0
        private void BeginReply(ref MessageRpc rpc)
        {
            bool success = false;

            try
            {
                IResumeMessageRpc resume = rpc.Pause();

                rpc.AsyncResult = rpc.RequestContext.BeginReply(rpc.Reply, rpc.ReplyTimeoutHelper.RemainingTime(),
                    s_onReplyCompleted, resume);
                success = true;

                if (rpc.AsyncResult.CompletedSynchronously)
                {
                    rpc.UnPause();
                }
            }
            catch (CommunicationException e)
            {
                _error.HandleError(e);
            }
            catch (TimeoutException e)
            {
                _error.HandleError(e);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                if (!_error.HandleError(e))
                {
                    rpc.RequestContextThrewOnReply = true;
                    rpc.CanSendReply = false;
                }
            }
            finally
            {
                if (!success)
                {
                    rpc.UnPause();
                }
            }
        }
コード例 #19
0
        void BeginReply(ref MessageRpc rpc)
        {
            bool success = false;

            try
            {
                IResumeMessageRpc resume = rpc.Pause();

                rpc.AsyncResult = rpc.RequestContext.BeginReply(rpc.Reply, rpc.ReplyTimeoutHelper.RemainingTime(),
                    onReplyCompleted, resume);
                success = true;

                if (rpc.AsyncResult.CompletedSynchronously)
                {
                    rpc.UnPause();
                }
            }
            catch (CommunicationException e)
            {
                this.error.HandleError(e);
            }
            catch (TimeoutException e)
            {
                this.error.HandleError(e);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                if (DiagnosticUtility.ShouldTraceError)
                {
                    TraceUtility.TraceEvent(System.Diagnostics.TraceEventType.Error,
                        TraceCode.ServiceOperationExceptionOnReply,
                        SR.GetString(SR.TraceCodeServiceOperationExceptionOnReply),
                        this, e);
                }

                if (!this.error.HandleError(e))
                {
                    rpc.RequestContextThrewOnReply = true;
                    rpc.CanSendReply = false;
                }
            }
            finally
            {
                if (!success)
                {
                    rpc.UnPause();
                }
            }
        }
 private bool AcquireDynamicInstanceContextCore(ref MessageRpc rpc)
 {
     bool flag = rpc.InstanceContext.QuotaThrottle.Acquire(rpc.Pause());
     if (flag)
     {
         rpc.UnPause();
     }
     return flag;
 }