MaYunsong

Hi, Guys, afternoon.

i'm struggling a problem which is as follows.

1) i made a Windows application and unloaded a executing workflow through clicking a button which calls the workflowinstance.Unload() method.

2) then i made another Windows application and want to click a button to load the persisted workflow mentioned above. the loading code is as follows:

private void button1_Click(object sender, EventArgs e)
{
foreach (SqlPersistenceWorkflowInstanceDescription sqlwid in sqlPersistence.GetAllWorkflows())
{
Guid wfGuid = sqlwid.WorkflowInstanceId;
WorkflowInstance wfInstance = wfRuntime.GetWorkflow(wfGuid);
wfInstance.Load();
}
}

Problem is: i can get the wfGuid of the persisted workflow from SqlServer but i can't get the wfInstance. i don't know if this is because the 2 WorkflowRuntime object or the 2 processes are different or not.

Look forward to everyone's advice. Thank you sincerely!!!




Re: Windows Workflow Foundation Help for persistence£¡£¡£¡

Khalid Aggag - MSFT

When you say cant get the WorkflowInstance you mean you are hitting an exception when you call GetWorkflow If so can you provide the exception. You will hit an exception if the workflow is currently loaded or owned by owner workflow runtime.




Re: Windows Workflow Foundation Help for persistence£¡£¡£¡

MaYunsong

Aggag, thank you so so much about your reply!!! I'm so happy that i just worked it out.

And you know, i'm a Chinese serving as an intern in Japan, so my VS2005 is in Japanese which is reall really horrible for me.(I wish my boss wouldn't see this thread...) So it's a little difficult for me to translate and paste the exception hint.

OK, back to the point. What the exception hint means is kinda like I haven't refered to some workflow file and I failed to connect to the DB.

So

1) I try adding the workflow project which I defined in the first solution whose function is to persist the workflow instance.

2) Then in the button_click event handler, I create the workflowRuntime instance, add SQLWorkflowPersistService into it and start it.

After doing these things, it worked out. And the button_click event handler is following.

private void button1_Click(object sender, EventArgs e)
{
wfRuntime = new WorkflowRuntime();
sqlPersistence = new SqlWorkflowPersistenceService(conn);
wfRuntime.AddService(sqlPersistence);
wfRuntime.StartRuntime();
foreach (SqlPersistenceWorkflowInstanceDescription sqlwid in sqlPersistence.GetAllWorkflows())
{
Guid wfGuid = sqlwid.WorkflowInstanceId;
WorkflowInstance wfInstance = wfRuntime.GetWorkflow(wfGuid);
wfInstance.Load();
}
}






Re: Windows Workflow Foundation Help for persistence£¡£¡£¡

Khalid Aggag - MSFT

I think the problem that the workflow definition (type) was needed in both your projects for them to be able to load and execute your worfklow. When you added the project that contained the workflow definition things worked.




Re: Windows Workflow Foundation Help for persistence£¡£¡£¡

MaYunsong

That's correct.

Such a little bit childish mistakeSmile