Windows workflow in ASP.Net
Hi,
I am using a workflow created by me in my ASP .net application. When I create a WorkflowRuntime object, sometime I was getting an error "Can not create more then one WorkflowRuntime object in same AppDomain". So I put the WorkflowRuntime object in Application State and before creating the new object, I am checking the Application State.
Here is the code.
WFRuntime = (WorkflowRuntime)System.Web.HttpContext.Current.Application[Constants.WPRuntimeId];
if (WFRuntime ==null)
{
WFRuntime =newWorkflowRuntime();
WFRuntime.AddService(newSqlTrackingService(connectionString));
WFRuntime.AddService(newSqlWorkflowPersistenceService(connectionString,true,newTimeSpan(0, 0, 0, 10, 0),newTimeSpan(0, 0, 0, 10, 0)));
//WFRuntime.AddService(new SharedConnectionWorkflowTransactionService(connectionString));
System.Web.HttpContext.Current.Application.Add(Constants.WPRuntimeId, WFRuntime);
}
ExternalDataExchangeService dataService =newExternalDataExchangeService();
WFRuntime.AddService(dataService);
IPService =newInterviewProcessService();
dataService.AddService(IPService);
WFRuntime.StartRuntime();
When I run this code for the first time, it works fine. But when this code is executed second time, it gives an error.
An instance of ExternalDataExchangeService of type RecruitmentTracker.InterviewProcessWFService.IInterviewProcessService already exists in the runtime container.
When I write the code like this
WorkflowRuntime WFRuntime;
WFRuntime = (WorkflowRuntime)System.Web.HttpContext.Current.Application[Constants.WPRuntimeId];
if (WFRuntime ==null)
{
WFRuntime =newWorkflowRuntime();
WFRuntime.AddService(newSqlTrackingService(connectionString));
WFRuntime.AddService(newSqlWorkflowPersistenceService(connectionString,true,newTimeSpan(0, 0, 0, 10, 0),newTimeSpan(0, 0, 0, 10, 0)));
//WFRuntime.AddService(new SharedConnectionWorkflowTransactionService(connectionString));
System.Web.HttpContext.Current.Application.Add(Constants.WPRuntimeId, WFRuntime);
ExternalDataExchangeService dataService =newExternalDataExchangeService();
WFRuntime.AddService(dataService);
IPService =newInterviewProcessService();
dataService.AddService(IPService);
WFRuntime.StartRuntime();
}
This also works fine in the first execution, but in the second secution, when I am not able to fire any event of my service class, as variable IPService is null (As its instantiated in If condition). When I instantiate this variable to new instance before firing the event, I find all my events are null so can not fire the events.
I am using June 2006 CTP.
Please advise me.
Thanks Chintan

