Export (0) Print
Expand All

Get WorkflowInstanceId

This topic applies to Windows Workflow Foundation 4 (WF4).

This sample demonstrates how to use the custom activity, GetWorkflowInstanceId to return the workflow instance ID.

Demonstrates

Custom activity development, how to access the workflow instance.

Discussion

Getting the instance ID of a running workflow requires writing code. If you want to write a fully-declarative workflow, then you need an activity that can return the workflow instance ID so that the activity can be referenced in the workflow to provide a fully-declarative workflow authoring experience. Many scenarios require access to the instance ID: a few examples are for logging or auditing purposes or for doing application-level correlation by providing the instance ID back to a client for future association (for example, by using this activity inside a SendReply activity).

GetWorkflowInstanceId is implemented as a CodeActivity because it must return a value of type Guid, and it must have access to the CodeActivityContext for getting the workflow’s instance ID. Its implementation is fairly basic.

public sealed class GetWorkflowInstanceId : CodeActivity<Guid>
{
protected override Guid Execute(CodeActivityContext context)
        {
            return context.WorkflowInstanceId;
        }
}

Ee943758.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.

<InstallDrive>:\WF_WCF_Samples

If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.

<InstallDrive>:\WF_WCF_Samples\WF\Scenario\ActivityLibrary\GetWorkflowInstanceId

Community Additions

ADD
Show:
© 2014 Microsoft