I'm writing a workflow that uses pluggable workflow services to await an external event from an external program. My problem is that, no matter how I re-write it, the external event is raised twice, even though I'm calling the RaiseEvent method once. I'm at the end of my wits here - how do I solve this issue?
Here's the structure of my workflow. Both event handler activities are bound to the same method, HandleEvent1_Invoked:
Here's how I'm raising the events:
// 1: Raising the events: console program
using (var site = new SPSite(siteGuid))
{
using (var web = site.OpenWeb(webGuid))
{
SPWorkflowExternalDataExchangeService.RaiseEvent(web, site.SystemAccount.ID, workflowGuid, typeof(IWfExternalEvents),
"RandomEventType", new object[] { "alpha" }, SPWorkflowRunOptions.SynchronousAllowPostpone);
SPWorkflowExternalDataExchangeService.RaiseEvent(web, site.SystemAccount.ID, workflowGuid, typeof(IWfExternalEvents),
"RandomEventType", new object[] { "beta" }, SPWorkflowRunOptions.SynchronousAllowPostpone);
}
}
// 2: External data service
public override void CallEventHandler(Type eventType, string eventName, object[] eventData, SPWorkflow workflow,
string identity, System.Workflow.Runtime.IPendingWork workHandler, object workItem)
{
var args = new ExternalEventArgs(workflow.InstanceId)
{
EventData = (string)eventData[0]
};
if (Event != null)
{
Event(null, args);
}
}
// 3: Event handling method: workflow
private void HandleEvent1_Invoked(object sender, ExternalDataEventArgs e)
{
var args = (ExternalEventArgs)e;
workflowProperties.Workflow.CreateHistoryEvent(1, 1, workflowProperties.OriginatorUser, "Event received", args.EventData, null);
}
Here's what I'm getting in the workflow history log:
It looks like it delivers the first event ("alpha") twice, and when it tries to deliver the second one, the workflow is already complete, so it raises the exception.
Any help is appreciated.
System.Workflow.Activities.EventDeliveryFailedException: Event "Event" on interface type "EventTest.IWfExternalEvents" for instance id "50ebe158-99ef-4d1e-83d1-85ee9807cc94" cannot be delivered.
- also two times.