Wednesday, June 27, 2007
Before Using Windows Workflow Foundation
1. Create a database called SqlPersistenceService in the SQL Server 2005.
2. Go to: %WINDIR%\Microsoft.NET\Framework\v3.0\Windows Workflow Foundation\SQL\EN
3. Execute the SqlPersistenceService_Schema.sql on the newly created database.
4. Also, execute the SqlPersistenceService_Logic.sql
This will be needed if you want to develop workflows and run them from e.g. a desktop application in Visual Studio 2005.
In the same directory, there will be 2 more SQL files for Tracking services. If tracking services are to be used, these two queries should also be executed (first the schema, then the logic query).
The workflow hosting environment does not have a persistence service as required by an operation on the workflow instance
When you run a Workflow which does not have a persistence service, you may encounter the following error : The workflow hosting environment does not have a persistence service as required by an operation on the workflow instance. This blog explains the cause, and tells you how to fix it.
--------------------------------------------------------------------------------
When you run a Workflow which does not have a persistence service, you may encounter the following error : The workflow hosting environment does not have a persistence service as required by an operation on the workflow instance "d0d830f6-afd5-42c5-8e16-10437417caf6".
Let's have a look at this sample:
Create a workflow with a CompensatableTransactionScope, and a CodeActivity within the CompensatableTransactionScope, which outputs a message to the Console e.g. Console.WriteLine("Hello Workflow");
If you run the application, you will obtain the error above. This is because Persistence is built into the CompensatableTransactionScope, and a "persistence point" will occur automatically whenever the Transaction completes.
A "Persistence Point" occurs in the following scenarios:
- When workflow becomes idle AND the unloadOnIdle flag for the persistence service is true. E.g. Delay Activity
- Host application calls WorkflowInstance.Unload or WorkflowInstance.RequestPersist
If any of the following objects complete their work. e.g.:
- a Workflow terminates or finishes.
- a custom Activity using PersistOnClose attribute finishes
- a CompensatableSequenceActivity is completed
- an Atomic transaction completes : TransactionScopeActivity / CompensatableTransactionScopeActivity
The way to solve our dilemma is to add a persistence service to the WorkflowRuntime, as follows:
SqlWorkflowPersistenceService sqlPersistenceService = new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI");
workflowRuntime.AddService(sqlPersistenceService);
Now run the application, and your persistence problem is solved.
--------------------------------------------------------------------------------
When you run a Workflow which does not have a persistence service, you may encounter the following error : The workflow hosting environment does not have a persistence service as required by an operation on the workflow instance "d0d830f6-afd5-42c5-8e16-10437417caf6".
Let's have a look at this sample:
Create a workflow with a CompensatableTransactionScope, and a CodeActivity within the CompensatableTransactionScope, which outputs a message to the Console e.g. Console.WriteLine("Hello Workflow");
If you run the application, you will obtain the error above. This is because Persistence is built into the CompensatableTransactionScope, and a "persistence point" will occur automatically whenever the Transaction completes.
A "Persistence Point" occurs in the following scenarios:
- When workflow becomes idle AND the unloadOnIdle flag for the persistence service is true. E.g. Delay Activity
- Host application calls WorkflowInstance.Unload or WorkflowInstance.RequestPersist
If any of the following objects complete their work. e.g.:
- a Workflow terminates or finishes.
- a custom Activity using PersistOnClose attribute finishes
- a CompensatableSequenceActivity is completed
- an Atomic transaction completes : TransactionScopeActivity / CompensatableTransactionScopeActivity
The way to solve our dilemma is to add a persistence service to the WorkflowRuntime, as follows:
SqlWorkflowPersistenceService sqlPersistenceService = new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI");
workflowRuntime.AddService(sqlPersistenceService);
Now run the application, and your persistence problem is solved.
Tuesday, March 13, 2007
Enumerations in C#
The [Flags] attribute is optional and informs the runtime that the values in the enum can be bit-combined and should be decoded accordingly in the debugger or when outputting text to console. For example:
[Flags]
internal enum Colours { Red = 1, Green = 2, Blue = 4, White = 8 };
private void Test()
{
string [] items = System.Enum.GetNames(typeof(Colours));
// this outputs: Red Green Blue White
foreach (string item in items)
textBox1.Text += item + " ";
textBox1.Text += "\r\n";
Colours c = Colours.Red Colours.Blue;
// this outputs: Red, Blue
textBox1.Text += c + "\r\n";
// this outputs: 5
textBox1.Text += (int)n + "\r\n";
}
Sunday, March 11, 2007
Wednesday, January 10, 2007
Subscribe to:
Posts (Atom)
