public void GotReply(Message reply)
            {
                bool flag;
                ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? TraceUtility.ExtractActivity(reply) : null;

                using (ServiceModelActivity.BoundOperation(activity))
                {
                    lock (this.parent.ThisLock)
                    {
                        bool isDone = this.IsDone;
                        this.reply    = reply;
                        this.gotReply = true;
                        flag          = !isDone && this.IsDone;
                    }
                    if ((activity != null) && DiagnosticUtility.ShouldUseActivity)
                    {
                        TraceUtility.SetActivity(reply, this.activity);
                        if ((DiagnosticUtility.ShouldUseActivity && (this.activity != null)) && (FxTrace.Trace != null))
                        {
                            FxTrace.Trace.TraceTransfer(this.activity.Id);
                        }
                    }
                }
                if (DiagnosticUtility.ShouldUseActivity && (activity != null))
                {
                    activity.Stop();
                }
                if (flag)
                {
                    this.Done(false);
                }
            }
Exemplo n.º 2
0
 internal void Close()
 {
     using (ServiceModelActivity.BoundOperation(this.Activity))
     {
         this.poisonHandler.Dispose();
         this.queue.Dispose();
     }
     ServiceModelActivity.Stop(this.activity);
 }
Exemplo n.º 3
0
 internal Message ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
 {
     if (reply != null)
     {
         if (DiagnosticUtility.ShouldUseActivity)
         {
             ServiceModelActivity activity = TraceUtility.ExtractActivity(reply);
             if (((activity != null) && (correlationState != null)) && ((correlationState.Activity != null) && (activity.Id != correlationState.Activity.Id)))
             {
                 using (ServiceModelActivity.BoundOperation(activity))
                 {
                     if (FxTrace.Trace != null)
                     {
                         FxTrace.Trace.TraceTransfer(correlationState.Activity.Id);
                     }
                     activity.Stop();
                 }
             }
         }
         ServiceModelActivity activity2 = (correlationState == null) ? null : correlationState.Activity;
         using (ServiceModelActivity.BoundOperation(activity2))
         {
             if (DiagnosticUtility.ShouldUseActivity)
             {
                 TraceUtility.SetActivity(reply, activity2);
             }
             Message   faultMessage   = reply;
             Exception faultException = null;
             try
             {
                 base.SecurityProtocol.VerifyIncomingMessage(ref reply, timeout, new SecurityProtocolCorrelationState[] { correlationState });
             }
             catch (MessageSecurityException)
             {
                 base.TryGetSecurityFaultException(faultMessage, out faultException);
                 if (faultException == null)
                 {
                     throw;
                 }
             }
             if (faultException != null)
             {
                 base.Fault(faultException);
                 throw DiagnosticUtility.ExceptionUtility.ThrowHelperWarning(faultException);
             }
         }
     }
     return(reply);
 }
        public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result)
        {
            object returnVal;

            if (instance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoServiceObject)));
            }

            outputs = EmptyArray.Allocate(this.OutputParameterCount);
            bool callFailed  = true;
            bool callFaulted = false;
            ServiceModelActivity activity = null;

            try
            {
                Activity boundOperation = null;
                GetActivityInfo(ref activity, ref boundOperation);
                using (boundOperation)
                {
                    returnVal  = this.InvokeEndDelegate(instance, outputs, result);
                    callFailed = false;
                }
            }
            catch (SecurityException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException());
            }
            catch (FaultException)
            {
                callFaulted = true;
                callFailed  = false;
                throw;
            }
            finally
            {
                ServiceModelActivity.Stop(activity);
                StopOperationInvokeTrace(callFailed, callFaulted, this.endMethod.Name);
                StopOperationInvokePerformanceCounters(callFailed, callFaulted, this.endMethod.Name.Substring(ServiceReflector.EndMethodNamePrefix.Length));
            }

            return(returnVal);
        }
        public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
        {
            if (instance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoServiceObject)));
            }
            if (inputs == null)
            {
                if (this.InputParameterCount > 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInputParametersToServiceNull, this.InputParameterCount)));
                }
            }
            else if (inputs.Length != this.InputParameterCount)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInputParametersToServiceInvalid, this.InputParameterCount, inputs.Length)));
            }

            StartOperationInvokePerformanceCounters(this.beginMethod.Name.Substring(ServiceReflector.BeginMethodNamePrefix.Length));

            IAsyncResult         returnValue;
            bool                 callFailed  = true;
            bool                 callFaulted = false;
            ServiceModelActivity activity    = null;

            try
            {
                Activity boundActivity = null;
                CreateActivityInfo(ref activity, ref boundActivity);

                StartOperationInvokeTrace(this.beginMethod.Name);

                using (boundActivity)
                {
                    if (DiagnosticUtility.ShouldUseActivity)
                    {
                        string activityName = null;

                        if (this.endMethod == null)
                        {
                            activityName = SR.GetString(SR.ActivityExecuteMethod,
                                                        this.beginMethod.DeclaringType.FullName, this.beginMethod.Name);
                        }
                        else
                        {
                            activityName = SR.GetString(SR.ActivityExecuteAsyncMethod,
                                                        this.beginMethod.DeclaringType.FullName, this.beginMethod.Name,
                                                        this.endMethod.DeclaringType.FullName, this.endMethod.Name);
                        }

                        ServiceModelActivity.Start(activity, activityName, ActivityType.ExecuteUserCode);
                    }

                    returnValue = this.InvokeBeginDelegate(instance, inputs, callback, state);
                    callFailed  = false;
                }
            }
            catch (System.Security.SecurityException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException());
            }
            catch (Exception e)
            {
                TraceUtility.TraceUserCodeException(e, this.beginMethod);
                if (e is FaultException)
                {
                    callFaulted = true;
                    callFailed  = false;
                }

                throw;
            }
            finally
            {
                ServiceModelActivity.Stop(activity);

                // An exception during the InvokeBegin will not call InvokeEnd,
                // so we complete the trace and performance counters here.
                if (callFailed || callFaulted)
                {
                    StopOperationInvokeTrace(callFailed, callFaulted, this.EndMethod.Name);
                    StopOperationInvokePerformanceCounters(callFailed, callFaulted, endMethod.Name.Substring(ServiceReflector.EndMethodNamePrefix.Length));
                }
            }
            return(returnValue);
        }
Exemplo n.º 6
0
        public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
        {
            if (instance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoServiceObject)));
            }

            if (inputs == null)
            {
                if (this.InputParameterCount > 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInputParametersToServiceNull, this.InputParameterCount)));
                }
            }
            else if (inputs.Length != this.InputParameterCount)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInputParametersToServiceInvalid, this.InputParameterCount, inputs.Length)));
            }

            this.outputs = EmptyArray.Allocate(this.OutputParameterCount);

            AsyncMethodInvoker.StartOperationInvokePerformanceCounters(this.taskMethod.Name);

            IAsyncResult         returnValue;
            bool                 callFailed  = true;
            bool                 callFaulted = false;
            ServiceModelActivity activity    = null;

            try
            {
                Activity boundActivity = null;
                AsyncMethodInvoker.CreateActivityInfo(ref activity, ref boundActivity);

                AsyncMethodInvoker.StartOperationInvokeTrace(this.taskMethod.Name);

                using (boundActivity)
                {
                    if (DiagnosticUtility.ShouldUseActivity)
                    {
                        string activityName = SR.GetString(SR.ActivityExecuteMethod, this.taskMethod.DeclaringType.FullName, this.taskMethod.Name);
                        ServiceModelActivity.Start(activity, activityName, ActivityType.ExecuteUserCode);
                    }

                    object taskReturnValue = this.InvokeDelegate(instance, inputs, this.outputs);

                    if (taskReturnValue == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("task");
                    }
                    else if (this.isGenericTask)
                    {
                        returnValue = (IAsyncResult)this.toAsyncMethodInfo.Invoke(null, new object[] { taskReturnValue, callback, state });
                    }
                    else
                    {
                        returnValue = ((Task)taskReturnValue).AsAsyncResult(callback, state);
                    }

                    callFailed = false;
                }
            }
            catch (System.Security.SecurityException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException());
            }
            catch (Exception e)
            {
                TraceUtility.TraceUserCodeException(e, this.taskMethod);
                if (e is FaultException)
                {
                    callFaulted = true;
                    callFailed  = false;
                }

                throw;
            }
            finally
            {
                ServiceModelActivity.Stop(activity);

                // Any exception above means InvokeEnd will not be called, so complete it here.
                if (callFailed || callFaulted)
                {
                    AsyncMethodInvoker.StopOperationInvokeTrace(callFailed, callFaulted, this.TaskMethod.Name);
                    AsyncMethodInvoker.StopOperationInvokePerformanceCounters(callFailed, callFaulted, this.TaskMethod.Name);
                }
            }

            return(returnValue);
        }
Exemplo n.º 7
0
        public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result)
        {
            object returnVal;
            bool   callFailed             = true;
            bool   callFaulted            = false;
            ServiceModelActivity activity = null;

            if (instance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoServiceObject)));
            }

            try
            {
                Activity boundOperation = null;
                AsyncMethodInvoker.GetActivityInfo(ref activity, ref boundOperation);

                using (boundOperation)
                {
                    Task task = result as Task;

                    Fx.Assert(task != null, "InvokeEnd needs to be called with the result returned from InvokeBegin.");
                    if (task.IsFaulted)
                    {
                        Fx.Assert(task.Exception != null, "Task.IsFaulted guarantees non-null exception.");

                        // If FaultException is thrown, we will get 'callFaulted' behavior below.
                        // Any other exception will retain 'callFailed' behavior.
                        throw FxTrace.Exception.AsError <FaultException>(task.Exception);
                    }

                    // Task cancellation without an exception indicates failure but we have no
                    // additional information to provide.  Accessing Task.Result will throw a
                    // TaskCanceledException.   For consistency between void Tasks and Task<T>,
                    // we detect and throw here.
                    if (task.IsCanceled)
                    {
                        throw FxTrace.Exception.AsError(new TaskCanceledException(task));
                    }

                    outputs = this.outputs;
                    if (this.isGenericTask)
                    {
                        returnVal = this.taskTResultGetMethod.Invoke(result, Type.EmptyTypes);
                    }
                    else
                    {
                        returnVal = null;
                    }

                    callFailed = false;
                }
            }
            catch (SecurityException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException());
            }
            catch (FaultException)
            {
                callFaulted = true;
                callFailed  = false;
                throw;
            }
            finally
            {
                ServiceModelActivity.Stop(activity);
                AsyncMethodInvoker.StopOperationInvokeTrace(callFailed, callFaulted, this.TaskMethod.Name);
                AsyncMethodInvoker.StopOperationInvokePerformanceCounters(callFailed, callFaulted, this.TaskMethod.Name);
            }

            return(returnVal);
        }
Exemplo n.º 8
0
        public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result)
        {
            object obj2;

            if (instance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxNoServiceObject")));
            }
            outputs = EmptyArray.Allocate(this.OutputParameterCount);
            bool flag  = true;
            bool flag2 = false;

            try
            {
                ServiceModelActivity activity       = null;
                Activity             boundOperation = null;
                this.GetActivityInfo(ref activity, ref boundOperation);
                using (boundOperation)
                {
                    obj2 = this.InvokeEndDelegate(instance, outputs, result);
                    flag = false;
                }
                ServiceModelActivity.Stop(activity);
            }
            catch (SecurityException exception)
            {
                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException());
            }
            catch (FaultException)
            {
                flag2 = true;
                flag  = false;
                throw;
            }
            finally
            {
                if (flag)
                {
                    if (TD.OperationFailedIsEnabled())
                    {
                        TD.OperationFailed(this.EndMethod.Name, TraceUtility.GetUtcBasedDurationForTrace(TraceUtility.ExtractAsyncOperationStartTime()));
                    }
                }
                else if (flag2)
                {
                    if (TD.OperationFaultedIsEnabled())
                    {
                        TD.OperationFaulted(this.EndMethod.Name, TraceUtility.GetUtcBasedDurationForTrace(TraceUtility.ExtractAsyncOperationStartTime()));
                    }
                }
                else if (TD.OperationCompletedIsEnabled())
                {
                    TD.OperationCompleted(this.EndMethod.Name, TraceUtility.GetUtcBasedDurationForTrace(TraceUtility.ExtractAsyncOperationStartTime()));
                }
                if (PerformanceCounters.PerformanceCountersEnabled)
                {
                    if (flag)
                    {
                        PerformanceCounters.MethodReturnedError(this.endMethod.Name.Substring("End".Length));
                    }
                    else if (flag2)
                    {
                        PerformanceCounters.MethodReturnedFault(this.endMethod.Name.Substring("End".Length));
                    }
                    else
                    {
                        PerformanceCounters.MethodReturnedSuccess(this.endMethod.Name.Substring("End".Length));
                    }
                }
            }
            return(obj2);
        }
Exemplo n.º 9
0
        public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state)
        {
            IAsyncResult result;

            if (instance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxNoServiceObject")));
            }
            if (inputs == null)
            {
                if (this.InputParameterCount > 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInputParametersToServiceNull", new object[] { this.InputParameterCount })));
                }
            }
            else if (inputs.Length != this.InputParameterCount)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxInputParametersToServiceInvalid", new object[] { this.InputParameterCount, inputs.Length })));
            }
            if (PerformanceCounters.PerformanceCountersEnabled)
            {
                PerformanceCounters.MethodCalled(this.beginMethod.Name.Substring("Begin".Length));
            }
            try
            {
                ServiceModelActivity activity      = null;
                Activity             boundActivity = null;
                this.CreateActivityInfo(ref activity, ref boundActivity);
                if (TD.OperationInvokedIsEnabled())
                {
                    TD.OperationInvoked(this.beginMethod.Name.Substring("Begin".Length), TraceUtility.GetCallerInfo(OperationContext.Current));
                }
                if ((TD.OperationCompletedIsEnabled() || TD.OperationFaultedIsEnabled()) || TD.OperationFailedIsEnabled())
                {
                    TraceUtility.UpdateAsyncOperationContextWithStartTime(DateTime.UtcNow.Ticks);
                }
                using (boundActivity)
                {
                    if (DiagnosticUtility.ShouldUseActivity)
                    {
                        string activityName = null;
                        if (this.endMethod == null)
                        {
                            activityName = System.ServiceModel.SR.GetString("ActivityExecuteMethod", new object[] { this.beginMethod.DeclaringType.FullName, this.beginMethod.Name });
                        }
                        else
                        {
                            activityName = System.ServiceModel.SR.GetString("ActivityExecuteAsyncMethod", new object[] { this.beginMethod.DeclaringType.FullName, this.beginMethod.Name, this.endMethod.DeclaringType.FullName, this.endMethod.Name });
                        }
                        ServiceModelActivity.Start(activity, activityName, ActivityType.ExecuteUserCode);
                    }
                    result = this.InvokeBeginDelegate(instance, inputs, callback, state);
                }
                ServiceModelActivity.Stop(activity);
            }
            catch (SecurityException exception)
            {
                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException());
            }
            catch (Exception exception2)
            {
                TraceUtility.TraceUserCodeException(exception2, this.beginMethod);
                throw;
            }
            return(result);
        }
Exemplo n.º 10
0
        public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result)
        {
            if (instance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoServiceObject)));
            }

            object returnVal                    = null;
            bool   callFailed                   = true;
            bool   callFaulted                  = false;
            ServiceModelActivity activity       = null;
            Activity             boundOperation = null;

            try
            {
                AsyncMethodInvoker.GetActivityInfo(ref activity, ref boundOperation);

                Task <Tuple <object, object[]> > invokeTask = result as Task <Tuple <object, object[]> >;

                if (invokeTask == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.SFxInvalidCallbackIAsyncResult));
                }

                AggregateException       ae    = null;
                Tuple <object, object[]> tuple = null;
                Task task = null;

                if (invokeTask.IsFaulted)
                {
                    Fx.Assert(invokeTask.Exception != null, "Task.IsFaulted guarantees non-null exception.");
                    ae = invokeTask.Exception;
                }
                else
                {
                    Fx.Assert(invokeTask.IsCompleted, "Task.Result is expected to be completed");

                    tuple = invokeTask.Result;
                    task  = tuple.Item1 as Task;

                    if (task == null)
                    {
                        outputs = tuple.Item2;
                        return(null);
                    }

                    if (task.IsFaulted)
                    {
                        Fx.Assert(task.Exception != null, "Task.IsFaulted guarantees non-null exception.");
                        ae = task.Exception;
                    }
                }

                if (ae != null && ae.InnerException != null)
                {
                    if (ae.InnerException is FaultException)
                    {
                        // If invokeTask.IsFaulted we produce the 'callFaulted' behavior below.
                        // Any other exception will retain 'callFailed' behavior.
                        callFaulted = true;
                        callFailed  = false;
                    }

                    if (ae.InnerException is SecurityException)
                    {
                        DiagnosticUtility.TraceHandledException(ae.InnerException, TraceEventType.Warning);
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException());
                    }

                    invokeTask.GetAwaiter().GetResult();
                }

                // Task cancellation without an exception indicates failure but we have no
                // additional information to provide.  Accessing Task.Result will throw a
                // TaskCanceledException.   For consistency between void Tasks and Task<T>,
                // we detect and throw here.
                if (task.IsCanceled)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new TaskCanceledException(task));
                }

                outputs = tuple.Item2;

                returnVal  = this.isGenericTask ? this.taskTResultGetMethod.Invoke(task, Type.EmptyTypes) : null;
                callFailed = false;

                return(returnVal);
            }
            finally
            {
                if (boundOperation != null)
                {
                    ((IDisposable)boundOperation).Dispose();
                }

                ServiceModelActivity.Stop(activity);
                AsyncMethodInvoker.StopOperationInvokeTrace(callFailed, callFaulted, this.TaskMethod.Name);
                AsyncMethodInvoker.StopOperationInvokePerformanceCounters(callFailed, callFaulted, this.TaskMethod.Name);
            }
        }
Exemplo n.º 11
0
        private async Task <Tuple <object, object[]> > InvokeAsync(object instance, object[] inputs)
        {
            EnsureIsInitialized();

            if (instance == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxNoServiceObject)));
            }

            if (inputs == null)
            {
                if (this.inputParameterCount > 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInputParametersToServiceNull, this.inputParameterCount)));
                }
            }
            else if (inputs.Length != this.inputParameterCount)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.SFxInputParametersToServiceInvalid, this.inputParameterCount, inputs.Length)));
            }

            object[] outputs = EmptyArray.Allocate(this.outputParameterCount);

            AsyncMethodInvoker.StartOperationInvokePerformanceCounters(this.taskMethod.Name);

            object returnValue;
            ServiceModelActivity activity      = null;
            Activity             boundActivity = null;

            try
            {
                AsyncMethodInvoker.CreateActivityInfo(ref activity, ref boundActivity);
                AsyncMethodInvoker.StartOperationInvokeTrace(this.taskMethod.Name);

                if (DiagnosticUtility.ShouldUseActivity)
                {
                    string activityName = SR.GetString(SR.ActivityExecuteMethod, this.taskMethod.DeclaringType.FullName, this.taskMethod.Name);
                    ServiceModelActivity.Start(activity, activityName, ActivityType.ExecuteUserCode);
                }

                OperationContext.EnableAsyncFlow();

                returnValue = this.invokeDelegate(instance, inputs, outputs);

                if (returnValue == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("task");
                }

                var returnValueTask = returnValue as Task;

                if (returnValueTask != null)
                {
                    // Only return once the task has completed
                    await returnValueTask;
                }

                return(Tuple.Create(returnValue, outputs));
            }
            catch (SecurityException e)
            {
                DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException());
            }
            catch (Exception e)
            {
                TraceUtility.TraceUserCodeException(e, this.taskMethod);
                throw;
            }
            finally
            {
                OperationContext.DisableAsyncFlow();

                if (boundActivity != null)
                {
                    ((IDisposable)boundActivity).Dispose();
                }

                ServiceModelActivity.Stop(activity);
            }
        }