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

[8451 byte] By [ChintanJhaveri] at [2007-12-22]
# 1
Take a look this sample on my blog, it should answer your question.
TomLake at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...
# 2

HI,

Thanks for your response.

My problem has got resolved. But now I am facing another problem.

When I execute these two lines

WFInstance = workflowRuntime.CreateWorkflow(typeof(InterviewProcessWorkflow), null, workflowInstanceId);

WFInstance.Start();

In the first execution, I am getting 'Timeout exceptioin', and at the second time 'An item with the same key has already been added'.

I am using SQL Server 2005 with SQL Server authentication.

This same code works when I point my workflow SQL connection string to my local machine SQL Express.

Do you have any idea?

Chintan

ChintanJhaveri at 2007-8-30 > top of Msdn Tech,Software Development for Windows Vista,Windows Workflow Foundation...

Software Development for Windows Vista

Site Classified