locked
How to get workflowinstance id? RRS feed

  • Question

  • I couple of questions about windows workflow

     

    1>How do i find the currently executing workflow instance id. There is a class WorkflowInstance which has the InstanceID property

    but how do i get to the current instance of the workflow?

     

    2>I'm using .xamlx to create workflow service. I want make the workflow service async.  Here are the steps

                    Caller calls the  WF service

                    Caller will immediately get back the respose from WF service with WorkflowInstanceID

                    Caller doesn’t have to wait for the remaining WF activities to complete.

     

                    So my workflow activities are in the following sequence

    1>     ReceiveRequest Activity

    2>     Assign Activity – “Assign WorkFlowInstance ID to Response contract's ID property”

    3>     SendResponse Activity

    4>     Custom Activity1

    5>     Custom Activity2

    6>     Custom Activity3

    7>     Custom Activity4

     

     

    Friday, January 20, 2012 5:17 PM

Answers

All replies

  • You can get the workflow instance Id from CodeActivityContext - see this thread

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/f6ebe346-4c6b-456a-9d6d-7d04b6a9e574

    Tim

    Friday, January 20, 2012 7:53 PM
  • Well the link provided above says "In this way you can see you don't need to know workflow ids any more - you can just use some piece of data that is natural to your problem domain." I dont want to use some piece of data as my unique workflow id. I found one way is by creating a custom activity, and then use the CodeActivityContext which is passed as a parameter has the WorkflowInstanceID

    But i wanted do to it in design without creating custom activity if possible. Isn't there any Current.Context available in WF?

    Im using xamlx to design work flow
    I have a variable "Response" which has a property call InstanceID
    I drag & dropped the Assign activity on workflow
    Now how do i get InstanceID here so that i can assign it to Response.InstanceID. I aready have the insatance of Respose


    • Edited by lax4u Friday, January 20, 2012 9:52 PM
    Friday, January 20, 2012 8:08 PM
  • Hi Lax,
    You can still use workflow instance IDs if you prefer to do so.
    Unfortunately there is no way that I know of to get the workflow instance ID without having a custom activity in your workflow. In particular there are no special variables available in the context of VB expressions called things like current or this.
    Tim

    Friday, January 20, 2012 10:06 PM
  • my other question is still there. If i already have WF service available, then how do i make that service async?

    Friday, January 20, 2012 11:14 PM
  • In part 2 your workflow is already async. As soon as the caller receives a response you sent using SendReply, the service call is finished, even if your callee workflow is still in progress.
    Tim
    Saturday, January 21, 2012 3:30 AM
  • Well its not working as i expected

    I have added proxy and made the async operations are created. The client is subscribed to completed event. The client code call the service using async operation. I put the breakpoint in all the custom activities and also in complete event handler. When i run the client code,  the break point in completed event handler does not hit until all the custom activities are executed.

    Do i need to someother activity inorder to send the response back to client immediately after SendResponse activity?

    What is the difference between Send and SendResponce activity? I'm using SendResponse currently.

    Sunday, January 22, 2012 1:42 AM
  • I found the solution for this issue. You have to add "Delay" activity after "SendReply"

    Here is my other post

    http://social.msdn.microsoft.com/Forums/en-US/wfprerelease/thread/23e91219-d6ed-4a5e-994e-9a4eab2e3208

     

    • Marked as answer by lax4u Wednesday, January 25, 2012 4:04 PM
    Monday, January 23, 2012 2:09 AM
  • Hi again lax,
    In this case the workflow really is executing asynchronously, but when you listen to a completed event, the completed event won't happen until the workflow hits an idle point. Adding delay activity created an idle point, which becomes a point of synchronizing with your workflow.

    A source of confusion here is that your original question talked about the 'caller' receiving a response, and I thought you meant the service caller who receives the Message response of the SendReply. That should be totally asynchronous from the rest of the workflow execution.
    Tim

    Tuesday, January 24, 2012 10:58 PM
  • Go here for GetWorkflowInstanceId class: http://msdn.microsoft.com/en-us/library/ee943758.aspx

    Then call the class like this:

    (New GetWorkflowInstanceId()).toString()

    Tuesday, November 20, 2012 10:28 PM