views:

571

answers:

2

In workflowRuntime_WorkflowUnloaded and Loaded etc.. the only thing I can get which is pretty useless is the workflowinstanceId. I want to be able to access some DPs that are on the root activity, whenever I do a GetWorkFlowDefintion() and cast to root activity, all the property that I've passed in are all null..

+1  A: 

You have to use the TrackingServices to get more than just the basic info. See http://msdn.microsoft.com/en-us/library/ms735887(VS.85).aspx

We use the default sqlTrackingService, host the workflow in a windows service, it is exposed using wcf and it is a state machine workflow.

Here is how we used it in one case:

SqlTrackingWorkflowInstance instance = null;
//wfServiceHost is an instance of WorkflowServiceHost
WorkflowRuntimeBehavior workflowRuntimeBehaviour = wfServiceHost.Description.Behaviors.Find<WorkflowRuntimeBehavior>();
WorkflowRuntime wfRuntime = workflowRuntimeBehaviour.WorkflowRuntime;

if (wfRuntime != null)
{
        SqlTrackingService trackingService = (SqlTrackingService)wfRuntime.GetService(typeof(SqlTrackingService));
        SqlTrackingQuery sqlTrackingQuery = new SqlTrackingQuery(trackingService.ConnectionString);

         sqlTrackingQuery.TryGetWorkflow(instanceId, out instance);
}
Dan
A: 

OK, I have managed to use the above to retrieve business-data (i.e. an ID) which lives inside the workflow, but I had to add a

this.TrackData("name", myObject)

into my initial activity inside the workflow.

At that point, I was able to get the ID from myObject (Job) by the following code. Yippee!

          foreach (UserTrackingRecord userTrackingRecord in
              sqlTrackingWorkflowInstance.UserEvents)
          {
              Console.WriteLine("Key : {0}  Data : {1}",
                  userTrackingRecord.UserDataKey,
                  userTrackingRecord.UserData.ToString());
              if (userTrackingRecord.UserDataKey == "Job")
              {
                  OrderRequest request = userTrackingRecord.UserData as OrderRequest;
                  if (request != null)
                  {
                      Console.WriteLine("\nJob ID: {0}", request.JobID);
                  }
              }
          }
Phil Penn