public void SendFault(Exception exception, IDictionary <string, string> outgoingContextProperties)
        {
            if (exception == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("exception");
            }

            if (!(exception is FaultException)) //Wrap the exception if it is not FaultException.
            {
                exception = WorkflowOperationErrorHandler.CreateUnhandledException(exception);
            }

            WorkflowOperationAsyncResult asyncResult = this.GetAsyncResult();

            asyncResult.SendFault(exception, outgoingContextProperties);
            this.SetOperationCompleted();

            if (DiagnosticUtility.ShouldTraceInformation)
            {
                string traceText = SR.GetString(SR.TraceCodeWorkflowRequestContextFaultSent, asyncResult.InstanceId);
                TraceUtility.TraceEvent(TraceEventType.Information,
                                        TraceCode.WorkflowRequestContextFaultSent, traceText,
                                        new StringTraceRecord("Details", traceText),
                                        this,
                                        exception);
            }
        }
Beispiel #2
0
        void OnWorkflowActivationCompleted(object state)
        {
            WorkflowActivationCompletedCallbackState callbackState = (WorkflowActivationCompletedCallbackState)state;

            lock (callbackState.InstanceContext.ThisLock)
            {
                if (base.Cache.Contains(callbackState.InstanceId, callbackState.InstanceContext))
                {
                    WorkflowDurableInstance durableInstance = callbackState.InstanceContext.Extensions.Find <WorkflowDurableInstance>();
                    if (durableInstance != null &&
                        durableInstance.CurrentOperationInvocation != null &&
                        durableInstance.CurrentOperationInvocation.HasWorkflowRequestContextBeenSerialized &&
                        !durableInstance.CurrentOperationInvocation.IsCompleted)
                    {
                        // If we are here, it means the workflow instance completed, terminated, or otherwise unloaded without
                        // completing the current operation invocation. In such case, we want to make the best effort to let
                        // service model to consider this operation invocation failed.
                        try
                        {
                            durableInstance.CurrentOperationInvocation.SendFault(
                                WorkflowOperationErrorHandler.CreateUnhandledException(
                                    new InvalidOperationException(SR2.GetString(SR2.WorkflowServiceUnloadedWithoutSendingResponse))),
                                null);
                        }
                        catch (Exception e)
                        {
                            if (Fx.IsFatal(e))
                            {
                                throw;
                            }
                        }
                    }

                    IChannel[] incomingChannels = new IChannel[callbackState.InstanceContext.IncomingChannels.Count];
                    callbackState.InstanceContext.IncomingChannels.CopyTo(incomingChannels, 0);

                    if (callbackState.InstanceContext.IncomingChannels.Count != 0)
                    {
                        foreach (IChannel channel in incomingChannels)
                        {
                            callbackState.InstanceContext.IncomingChannels.Remove(channel);
                        }
                    }
                    else
                    {
                        //Call notify only when IncomingChannels Collection is empty.
                        if (callbackState.InstanceContextIdleCallback != null)
                        {
                            callbackState.InstanceContextIdleCallback(callbackState.InstanceContext);
                        }
                    }
                }
            }
        }