internal static void SetWorkflowOperationBehavior(ContractDescription contractDescription, ServiceDescriptionContext context) { if (contractDescription == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("contractDescription"); } if (context == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context"); } foreach (OperationDescription opDescription in contractDescription.Operations) { WorkflowOperationBehavior behavior = null; KeyValuePair <Type, string> operationKey = new KeyValuePair <Type, string>(opDescription.DeclaringContract.ContractType, opDescription.Name); if (!context.WorkflowOperationBehaviors.TryGetValue(operationKey, out behavior)) { behavior = new WorkflowOperationBehavior(); context.WorkflowOperationBehaviors.Add(operationKey, behavior); behavior.CanCreateInstance = false; } if (opDescription.Behaviors.Find <WorkflowOperationBehavior>() != behavior) { opDescription.Behaviors.Remove(typeof(WorkflowOperationBehavior)); opDescription.Behaviors.Add(behavior); } } }
public static IAsyncResult BeginProcessRequest(WorkflowServiceInstance workflowInstance, OperationContext operationContext, string operationName, object[] inputs, bool performanceCountersEnabled, bool propagateActivity, Transaction currentTransaction, IInvokeReceivedNotification notification, WorkflowOperationBehavior behavior, ServiceEndpoint endpoint, TimeSpan timeout, AsyncCallback callback, object state) { Fx.Assert(inputs != null, "Null inputs"); return(new WorkflowOperationContext(inputs, operationContext, operationName, performanceCountersEnabled, propagateActivity, currentTransaction, workflowInstance, notification, behavior, endpoint, timeout, callback, state)); }
static void AddWorkflowOperationBehaviors(OperationDescription operation, string bookmarkName, bool canCreateInstance) { KeyedByTypeCollection <IOperationBehavior> behaviors = operation.Behaviors; WorkflowOperationBehavior workflowOperationBehavior = behaviors.Find <WorkflowOperationBehavior>(); if (workflowOperationBehavior == null) { behaviors.Add(new WorkflowOperationBehavior(new Bookmark(bookmarkName), canCreateInstance)); } else { workflowOperationBehavior.CanCreateInstance = workflowOperationBehavior.CanCreateInstance || canCreateInstance; } }
public WorkflowOperationInvoker(OperationDescription operationDescription, WorkflowOperationBehavior workflowOperationBehavior, WorkflowRuntime workflowRuntime, DispatchRuntime dispatchRuntime) { if (operationDescription == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operationDescription"); } if (workflowRuntime == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowRuntime"); } if (workflowOperationBehavior == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowOperationBehavior"); } this.isOneWay = operationDescription.IsOneWay; if (operationDescription.BeginMethod != null) { this.syncMethod = operationDescription.BeginMethod; inParameterCount = GetFlowedInParameterCount(operationDescription.BeginMethod.GetParameters()) - 2; } else { this.syncMethod = operationDescription.SyncMethod; inParameterCount = GetFlowedInParameterCount(operationDescription.SyncMethod.GetParameters()); } this.operationDescription = operationDescription; this.workflowRuntime = workflowRuntime; this.canCreateInstance = workflowOperationBehavior.CanCreateInstance; this.serviceAuthorizationManager = workflowOperationBehavior.ServiceAuthorizationManager; this.dispatchRuntime = dispatchRuntime; staticQueueName = QueueNameHelper.Create(this.syncMethod.DeclaringType, operationDescription.Name); }
WorkflowOperationContext(object[] inputs, OperationContext operationContext, string operationName, bool performanceCountersEnabled, bool propagateActivity, Transaction currentTransaction, WorkflowServiceInstance workflowInstance, IInvokeReceivedNotification notification, WorkflowOperationBehavior behavior, ServiceEndpoint endpoint, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.inputs = inputs; this.operationName = operationName; this.OperationContext = operationContext; this.ServiceEndpoint = endpoint; this.CurrentTransaction = currentTransaction; this.performanceCountersEnabled = performanceCountersEnabled; this.propagateActivity = propagateActivity; this.timeoutHelper = new TimeoutHelper(timeout); this.workflowInstance = workflowInstance; this.thisLock = new object(); this.notification = notification; this.OnCompleting = onCompleting; // Resolve bookmark Fx.Assert(behavior != null, "behavior must not be null!"); this.bookmark = behavior.OnResolveBookmark(this, out this.bookmarkScope, out this.bookmarkValue); Fx.Assert(this.bookmark != null, "bookmark must not be null!"); bool completeSelf = false; try { // set activity ID on the executing thread ( if (TraceUtility.MessageFlowTracingOnly) { this.e2eActivityId = TraceUtility.GetReceivedActivityId(this.OperationContext); DiagnosticTraceBase.ActivityId = this.e2eActivityId; } if (Fx.Trace.IsEtwProviderEnabled) { this.eventTraceActivity = EventTraceActivityHelper.TryExtractActivity(this.OperationContext.IncomingMessage); } // Take ownership of the ReceiveContext when buffering is enabled by removing the property if (this.workflowInstance.BufferedReceiveManager != null) { if (!ReceiveContext.TryGet(this.OperationContext.IncomingMessageProperties, out this.receiveContext)) { Fx.Assert("ReceiveContext expected when BufferedReceives are enabled"); } this.OperationContext.IncomingMessageProperties.Remove(ReceiveContext.Name); } completeSelf = ProcessRequest(); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } // Failing synchronously is one case where AsyncResult won't handle calling OnCompleting OnCompleting(this, e); throw; } if (completeSelf) { base.Complete(true); } }
public static IAsyncResult BeginProcessRequest(WorkflowServiceInstance workflowInstance, OperationContext operationContext, string operationName, object[] inputs, bool performanceCountersEnabled, bool propagateActivity, Transaction currentTransaction, IInvokeReceivedNotification notification, WorkflowOperationBehavior behavior, ServiceEndpoint endpoint, TimeSpan timeout, AsyncCallback callback, object state) { Fx.Assert(inputs != null, "Null inputs"); return new WorkflowOperationContext(inputs, operationContext, operationName, performanceCountersEnabled, propagateActivity, currentTransaction, workflowInstance, notification, behavior, endpoint, timeout, callback, state); }
private WorkflowOperationContext(object[] inputs, System.ServiceModel.OperationContext operationContext, string operationName, bool performanceCountersEnabled, bool propagateActivity, Transaction currentTransaction, WorkflowServiceInstance workflowInstance, IInvokeReceivedNotification notification, WorkflowOperationBehavior behavior, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state) { this.inputs = inputs; this.operationName = operationName; this.OperationContext = operationContext; this.CurrentTransaction = currentTransaction; this.performanceCountersEnabled = performanceCountersEnabled; this.propagateActivity = propagateActivity; this.timeoutHelper = new TimeoutHelper(timeout); this.workflowInstance = workflowInstance; this.thisLock = new object(); this.notification = notification; base.OnCompleting = onCompleting; this.bookmark = behavior.OnResolveBookmark(this, out this.bookmarkScope, out this.bookmarkValue); bool flag = false; try { if (TraceUtility.MessageFlowTracingOnly) { this.e2eActivityId = TraceUtility.GetReceivedActivityId(this.OperationContext); DiagnosticTrace.ActivityId = this.e2eActivityId; } if (this.workflowInstance.BufferedReceiveManager != null) { ReceiveContext.TryGet(this.OperationContext.IncomingMessageProperties, out this.receiveContext); this.OperationContext.IncomingMessageProperties.Remove(ReceiveContext.Name); } flag = this.ProcessRequest(); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } base.OnCompleting(this, exception); throw; } if (flag) { base.Complete(true); } }
public WorkflowOperationInvoker(OperationDescription operationDescription, ServiceEndpoint endpoint, CorrelationKeyCalculator keyCalculator, WorkflowOperationBehavior behavior, ServiceHostBase host, IOperationInvoker innerInvoker) : base(operationDescription, endpoint, keyCalculator, host) { Fx.Assert(operationDescription != null, "Null OperationDescription"); Fx.Assert(behavior != null, "Null WorkflowOperationBehavior"); this.StaticBookmarkName = behavior.bookmark == null ? null : behavior.bookmark.Name; this.behavior = behavior; this.CanCreateInstance = behavior.CanCreateInstance; this.performanceCountersEnabled = PerformanceCounters.PerformanceCountersEnabled; this.propagateActivity = TraceUtility.ShouldPropagateActivity; this.isHostingEndpoint = endpoint is WorkflowHostingEndpoint; this.innerInvoker = innerInvoker; this.isFirstReceiveOfTransactedReceiveScopeTree = operationDescription.IsFirstReceiveOfTransactedReceiveScopeTree; }