protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (this.Fault == null) { throw new InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_PropertyNotSet", new object[] { FaultProperty.Name })); } WorkflowQueuingService service = executionContext.GetService <WorkflowQueuingService>(); base.RaiseEvent(SendingFaultEvent, this, EventArgs.Empty); WebServiceInputActivity activityByName = base.GetActivityByName(this.InputActivityName) as WebServiceInputActivity; IComparable queueName = new EventQueueName(activityByName.InterfaceType, activityByName.MethodName, activityByName.QualifiedName); IMethodResponseMessage message = null; WorkflowQueue workflowQueue = service.GetWorkflowQueue(queueName); if (workflowQueue.Count != 0) { message = workflowQueue.Dequeue() as IMethodResponseMessage; } message.SendException(this.Fault); return(ActivityExecutionStatus.Closed); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (this.Fault == null) { throw new InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, SR.Error_PropertyNotSet, FaultProperty.Name)); } WorkflowQueuingService queueService = executionContext.GetService <WorkflowQueuingService>(); // fire event this.RaiseEvent(WebServiceFaultActivity.SendingFaultEvent, this, EventArgs.Empty); WebServiceInputActivity webservicereceive = this.GetActivityByName(this.InputActivityName) as WebServiceInputActivity; IComparable queueId = new EventQueueName(webservicereceive.InterfaceType, webservicereceive.MethodName, webservicereceive.QualifiedName); Debug.Assert(queueService.Exists(queueId)); IMethodResponseMessage responseMessage = null; WorkflowQueue queue = queueService.GetWorkflowQueue(queueId); if (queue.Count != 0) { responseMessage = queue.Dequeue() as IMethodResponseMessage; } System.Diagnostics.Debug.Assert(responseMessage != null); // populate exception & reset the waiting thread responseMessage.SendException(this.Fault); return(ActivityExecutionStatus.Closed); }
protected Object[] Invoke(Type interfaceType, String methodName, bool isActivation, Object[] parameters) { Guid workflowInstanceId = GetWorkflowInstanceId(ref isActivation); WorkflowInstance wfInstance; EventQueueName key = new EventQueueName(interfaceType, methodName); MethodInfo mInfo = interfaceType.GetMethod(methodName); bool responseRequired = (mInfo.ReturnType != typeof(void)); if (!responseRequired) { foreach (ParameterInfo parameter in mInfo.GetParameters()) { if (parameter.ParameterType.IsByRef || parameter.IsOut) { responseRequired = true; break; } } } MethodMessage methodMessage = PrepareMessage(interfaceType, methodName, parameters, responseRequired); EventHandler <WorkflowTerminatedEventArgs> workflowTerminationHandler = null; EventHandler <WorkflowCompletedEventArgs> workflowCompletedHandler = null; try { if (isActivation) { wfInstance = WorkflowRuntime.CreateWorkflow(this.workflowType, null, workflowInstanceId); SafeEnqueueItem(wfInstance, key, methodMessage); wfInstance.Start(); } else { wfInstance = WorkflowRuntime.GetWorkflow(workflowInstanceId); SafeEnqueueItem(wfInstance, key, methodMessage); } bool workflowTerminated = false; //Handler for workflow termination in b/w outstanding req-response. workflowTerminationHandler = delegate(Object sender, WorkflowTerminatedEventArgs e) { if (e.WorkflowInstance.InstanceId.Equals(workflowInstanceId)) { methodMessage.SendException(e.Exception); workflowTerminated = true; } }; workflowCompletedHandler = delegate(Object sender, WorkflowCompletedEventArgs e) { if (e.WorkflowInstance.InstanceId.Equals(workflowInstanceId)) { methodMessage.SendException(new ApplicationException(SR.GetString(System.Globalization.CultureInfo.CurrentCulture, SR.Error_WorkflowCompleted))); } }; WorkflowRuntime.WorkflowTerminated += workflowTerminationHandler; WorkflowRuntime.WorkflowCompleted += workflowCompletedHandler; ManualWorkflowSchedulerService scheduler = WorkflowRuntime.GetService <ManualWorkflowSchedulerService>(); if (scheduler != null) { scheduler.RunWorkflow(wfInstance.InstanceId); } if (!responseRequired) { // no ret, out or ref return(new Object[] { }); } IMethodResponseMessage response = methodMessage.WaitForResponseMessage(); if (response.Exception != null) { if (!workflowTerminated) { throw response.Exception; } else { throw new ApplicationException(SR.GetString(System.Globalization.CultureInfo.CurrentCulture, SR.Error_WorkflowTerminated), response.Exception); } } if (response.OutArgs != null) { return(((ArrayList)response.OutArgs).ToArray()); } else { return new Object[] { } }; } finally { if (workflowTerminationHandler != null) { WorkflowRuntime.WorkflowTerminated -= workflowTerminationHandler; } if (workflowCompletedHandler != null) { WorkflowRuntime.WorkflowCompleted -= workflowCompletedHandler; } } }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } WorkflowQueuingService queueService = executionContext.GetService <WorkflowQueuingService>(); // fire event this.RaiseEvent(WebServiceOutputActivity.SendingOutputEvent, this, EventArgs.Empty); WebServiceInputActivity webservicereceive = this.GetActivityByName(this.InputActivityName) as WebServiceInputActivity; if (webservicereceive == null) { Activity parent = this.Parent; while (parent != null) { //typically if defined inside a custom activity string qualifiedName = parent.QualifiedName + "." + this.InputActivityName; webservicereceive = this.GetActivityByName(qualifiedName) as WebServiceInputActivity; if (webservicereceive != null) { break; } parent = this.Parent; } } if (webservicereceive == null) { throw new InvalidOperationException(SR.GetString(SR.Error_CannotResolveWebServiceInput, this.QualifiedName, this.InputActivityName)); } IComparable queueId = new EventQueueName(webservicereceive.InterfaceType, webservicereceive.MethodName, webservicereceive.QualifiedName); MethodInfo mInfo = webservicereceive.InterfaceType.GetMethod(webservicereceive.MethodName); if (!queueService.Exists(queueId)) { // determine if no response is required, // compiler did not catch it, do the runtime check and return if (mInfo.ReturnType == typeof(void)) { return(ActivityExecutionStatus.Closed); } bool isresponseRequired = false; foreach (ParameterInfo formalParameter in mInfo.GetParameters()) { if (formalParameter.ParameterType.IsByRef || (formalParameter.IsIn && formalParameter.IsOut)) { isresponseRequired = true; } } if (isresponseRequired) { return(ActivityExecutionStatus.Closed); } } if (!queueService.Exists(queueId)) { throw new InvalidOperationException(SR.GetString(SR.Error_WebServiceInputNotProcessed, webservicereceive.QualifiedName)); } IMethodResponseMessage responseMessage = null; WorkflowQueue queue = queueService.GetWorkflowQueue(queueId); if (queue.Count != 0) { responseMessage = queue.Dequeue() as IMethodResponseMessage; } IMethodMessage message = responseMessage as IMethodMessage; WorkflowParameterBindingCollection parameterBindings = this.ParameterBindings; ArrayList outArgs = new ArrayList(); // populate result if (this.ParameterBindings.Contains("(ReturnValue)")) { WorkflowParameterBinding retBind = this.ParameterBindings["(ReturnValue)"]; if (retBind != null) { outArgs.Add(retBind.Value); } } foreach (ParameterInfo formalParameter in mInfo.GetParameters()) { // update out and byref values if (formalParameter.ParameterType.IsByRef || (formalParameter.IsIn && formalParameter.IsOut)) { WorkflowParameterBinding binding = parameterBindings[formalParameter.Name]; outArgs.Add(binding.Value); } } // reset the waiting thread responseMessage.SendResponse(outArgs); return(ActivityExecutionStatus.Closed); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } WorkflowQueuingService service = executionContext.GetService <WorkflowQueuingService>(); base.RaiseEvent(SendingOutputEvent, this, EventArgs.Empty); WebServiceInputActivity activityByName = base.GetActivityByName(this.InputActivityName) as WebServiceInputActivity; if (activityByName == null) { for (Activity activity2 = base.Parent; activity2 != null; activity2 = base.Parent) { string activityQualifiedName = activity2.QualifiedName + "." + this.InputActivityName; activityByName = base.GetActivityByName(activityQualifiedName) as WebServiceInputActivity; if (activityByName != null) { break; } } } if (activityByName == null) { throw new InvalidOperationException(SR.GetString("Error_CannotResolveWebServiceInput", new object[] { base.QualifiedName, this.InputActivityName })); } IComparable queueName = new EventQueueName(activityByName.InterfaceType, activityByName.MethodName, activityByName.QualifiedName); MethodInfo method = activityByName.InterfaceType.GetMethod(activityByName.MethodName); if (!service.Exists(queueName)) { if (method.ReturnType == typeof(void)) { return(ActivityExecutionStatus.Closed); } bool flag = false; foreach (ParameterInfo info2 in method.GetParameters()) { if (info2.ParameterType.IsByRef || (info2.IsIn && info2.IsOut)) { flag = true; } } if (flag) { return(ActivityExecutionStatus.Closed); } } if (!service.Exists(queueName)) { throw new InvalidOperationException(SR.GetString("Error_WebServiceInputNotProcessed", new object[] { activityByName.QualifiedName })); } IMethodResponseMessage message = null; WorkflowQueue workflowQueue = service.GetWorkflowQueue(queueName); if (workflowQueue.Count != 0) { message = workflowQueue.Dequeue() as IMethodResponseMessage; } WorkflowParameterBindingCollection parameterBindings = this.ParameterBindings; ArrayList outArgs = new ArrayList(); if (this.ParameterBindings.Contains("(ReturnValue)")) { WorkflowParameterBinding binding = this.ParameterBindings["(ReturnValue)"]; if (binding != null) { outArgs.Add(binding.Value); } } foreach (ParameterInfo info3 in method.GetParameters()) { if (info3.ParameterType.IsByRef || (info3.IsIn && info3.IsOut)) { WorkflowParameterBinding binding2 = parameterBindings[info3.Name]; outArgs.Add(binding2.Value); } } message.SendResponse(outArgs); return(ActivityExecutionStatus.Closed); }
protected object[] Invoke(Type interfaceType, string methodName, bool isActivation, object[] parameters) { EventHandler <WorkflowCompletedEventArgs> handler3 = null; object[] objArray; Guid workflowInstanceId = GetWorkflowInstanceId(ref isActivation); EventQueueName key = new EventQueueName(interfaceType, methodName); MethodInfo method = interfaceType.GetMethod(methodName); bool responseRequired = method.ReturnType != typeof(void); if (!responseRequired) { foreach (ParameterInfo info2 in method.GetParameters()) { if (info2.ParameterType.IsByRef || info2.IsOut) { responseRequired = true; break; } } } MethodMessage methodMessage = PrepareMessage(interfaceType, methodName, parameters, responseRequired); EventHandler <WorkflowTerminatedEventArgs> handler = null; EventHandler <WorkflowCompletedEventArgs> handler2 = null; try { WorkflowInstance workflow; if (isActivation) { workflow = this.WorkflowRuntime.CreateWorkflow(this.workflowType, null, workflowInstanceId); SafeEnqueueItem(workflow, key, methodMessage); workflow.Start(); } else { workflow = this.WorkflowRuntime.GetWorkflow(workflowInstanceId); SafeEnqueueItem(workflow, key, methodMessage); } bool workflowTerminated = false; handler = delegate(object sender, WorkflowTerminatedEventArgs e) { if (e.WorkflowInstance.InstanceId.Equals(workflowInstanceId)) { methodMessage.SendException(e.Exception); workflowTerminated = true; } }; if (handler3 == null) { handler3 = delegate(object sender, WorkflowCompletedEventArgs e) { if (e.WorkflowInstance.InstanceId.Equals(workflowInstanceId)) { methodMessage.SendException(new ApplicationException(SR.GetString(CultureInfo.CurrentCulture, "Error_WorkflowCompleted"))); } }; } handler2 = handler3; this.WorkflowRuntime.WorkflowTerminated += handler; this.WorkflowRuntime.WorkflowCompleted += handler2; ManualWorkflowSchedulerService service = this.WorkflowRuntime.GetService <ManualWorkflowSchedulerService>(); if (service != null) { service.RunWorkflow(workflow.InstanceId); } if (!responseRequired) { return(new object[0]); } IMethodResponseMessage message = methodMessage.WaitForResponseMessage(); if (message.Exception != null) { if (!workflowTerminated) { throw message.Exception; } throw new ApplicationException(SR.GetString(CultureInfo.CurrentCulture, "Error_WorkflowTerminated"), message.Exception); } if (message.OutArgs != null) { return(((ArrayList)message.OutArgs).ToArray()); } objArray = new object[0]; } finally { if (handler != null) { this.WorkflowRuntime.WorkflowTerminated -= handler; } if (handler2 != null) { this.WorkflowRuntime.WorkflowCompleted -= handler2; } } return(objArray); }