locked
Getting WorkflowIdentity From Within Workflow RRS feed

  • Question

  • I would like to be able to get the type and name or WorkflowIdentity from within a custom activity that is running within the workflow. But I cannot seem to find any workflow-related class and or static method that will give me access to the workflow service that is hosting my custom activity. All ideas are welcome. Thanks.

    D. Ferguson

    Wednesday, June 26, 2013 11:42 PM

Answers

  • I don't think you have access to them inside an acitivty, at least not directly, since the ActivityExecutor (that could expose them) is a private member of the NativeActivityContext.

    If you do use persistence you can query the instance store for the identity by workflow id (ActivityContext.WorkflowInstanceId), and with the identity in hand locate the definition from your activity library.

    You can pass the identity and some handle as an InArgument, this unfortunately persists with the workflow.

    You can also pass an extension that holds a reference to the identity and the definition. This initialization should be done every time you start a workflow (or load and resume one from store).

    • Marked as answer by Pengzhen Song Thursday, July 4, 2013 10:16 AM
    Monday, July 1, 2013 2:57 PM

All replies

  • Hi,

    please refer here:

    http://msdn.microsoft.com/en-us/library/system.activities.workflowidentity.aspx

    Hope it can help you

    Friday, June 28, 2013 10:49 AM
  • Thanks for the reply Sven.

    I had already looked the WorkflowIdentity class. My problem is that if I'm in code within a custom activity (derived from CodeActivity or NativeCodeActivity), all I have is a form of ActivityContext (Code or Native) from which to interrogate my environment. And I don't see anything in that environment that tells me the WorkflowDefinition or WorkflowIdentity that is at the root of the activity tree. And I also haven't found any static methods on any of the workflow classes that might let me get at that information.


    D. Ferguson

    Friday, June 28, 2013 1:45 PM
  • I don't think you have access to them inside an acitivty, at least not directly, since the ActivityExecutor (that could expose them) is a private member of the NativeActivityContext.

    If you do use persistence you can query the instance store for the identity by workflow id (ActivityContext.WorkflowInstanceId), and with the identity in hand locate the definition from your activity library.

    You can pass the identity and some handle as an InArgument, this unfortunately persists with the workflow.

    You can also pass an extension that holds a reference to the identity and the definition. This initialization should be done every time you start a workflow (or load and resume one from store).

    • Marked as answer by Pengzhen Song Thursday, July 4, 2013 10:16 AM
    Monday, July 1, 2013 2:57 PM
  • Thanks for the reply Greg. Somewhat disappointing. I was hoping to get at this as part of a workflow registration process I'm working on. I guess the other alternative would be to look into the workflow load-up process by extending or tapping into startup logic in the WorkflowServiceHost. Is that a viable alternative?


    D. Ferguson

    Thursday, July 4, 2013 11:15 AM
  • The WorkflowServiceHost.WorkflowExtensions property seem to be the extensibility point you're looking for.

    I prefer WorkflowApplication which requires more complex and careful coding (including manually hooking up persistence and implementing custom activation), but is much more customizable. The WorkflowServiceHost is tied to WCF and is more or less designed to support a limited number of definitions, however if this meets your needs, it's pretty efficient and is there out-of-the-box.

    Thursday, July 4, 2013 8:44 PM