WF Custom SQL Tracking Service Stopped Working for Older Workflows?

I have a custom tracking service that has been running for a while, now that more than 1,500 live workflows are ticking, I am now working on a version of the workflows so that I can release some change requests.

Unfortunately, the system was not initially deployed using strongly typed assemblies, so I am sorting this mess.

I need to use a custom SerializationBinder mix to translate PublicKeyToken = null into my new PublicKeyToken and AppDomain_AssemblyResolve delegate to help point the node to now strongly typed assemblies - Link here .

I also had to replace the contents of the related rows in the [Type] table that comes with the default SqlTrackingService in order to reference the new PublicKeyToken, so:

some.namespace.foobar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 

replaced by:

 some.namespace.foobar, Version=1.0.0.0, Culture=neutral, PublicKeyToken=123456789acb 

I seemed to get good results, however, when I go to the State Machine workflow, the Custom Tracking service that I added as a service no longer starts for workflows version 1.0.0.0, but works for the newly created version 2.0.0.0 work processes.

Note. The standard SqlTrackingService still works fine in both versions of the workflow, it's just a problem with the custom tracking service on existing persistent workflows.

A custom tracking service is always added via app.config as follows:

 <Services> ...other services here... <add type="some.namespace.ActiveStateTrackingService, some.namespace.extensions" assembly="uk.gov.gsi.cma.extensions" /> </Services> 

Any ideas on what else I need to change to get this to work for existing workflows?

As requested, this is a custom tracking service, although the problem is that the host โ€œbindsโ€ the custom tracking service, not the tracking service - I know this because in the case where the custom tracking service isnโ€™t, none of methods, including the constructor, are not called.

  public class ActiveStateTrackingService : TrackingService { protected override TrackingProfile GetProfile(Guid workflowInstanceId) { return GetDefaultProfile(); } protected override TrackingProfile GetProfile(Type workflowType, Version profileVersionId) { return GetDefaultProfile(); } protected override TrackingChannel GetTrackingChannel(TrackingParameters parameters) { return new ActiveStateTrackingChannel(parameters); } protected override bool TryGetProfile(Type workflowType, out TrackingProfile profile) { profile = GetDefaultProfile(); return true; } protected override bool TryReloadProfile(Type workflowType, Guid workflowInstanceId, out TrackingProfile profile) { profile = null; return false; } private TrackingProfile GetDefaultProfile() { TrackingProfile profile = new TrackingProfile(); profile.Version = new Version(1, 0); // Add tracking point for state activity executing ActivityTrackPoint statePoint = new ActivityTrackPoint(); ActivityTrackingLocation location = new ActivityTrackingLocation(typeof(StateActivity), new ActivityExecutionStatus[] { ActivityExecutionStatus.Executing }); statePoint.MatchingLocations.Add(location); profile.ActivityTrackPoints.Add(statePoint); return profile; } } public class ActiveStateTrackingChannel : TrackingChannel { private TrackingParameters param; public ActiveStateTrackingChannel(TrackingParameters parameters) { param = parameters; } protected override void InstanceCompletedOrTerminated() { return; } protected override void Send(TrackingRecord record) { // get the tracking record and write out the name of the state. var r = record as ActivityTrackingRecord; if (r != null) if (!string.IsNullOrEmpty(r.QualifiedName)) { using (ICaseService caseService = new CaseService()) { SomeServiceLayer.UpdateCurrentStateOutsideOfTheWorkflow(param.ContextGuid, r.ParentContextGuid, r.QualifiedName); Console.WriteLine("*** Current State: {0} ***", r.QualifiedName); } } } } 
+6
source share
1 answer

It turns out the last step is simple. The problem is due to a bug in WF and Microsoft described the answer here .

Basically, you should decorate your own tracking service class with an attribute that allows you to resolve old tracking service links, for example:

 [System.Workflow.Runtime.Tracking.PreviousTrackingService("myNamespace.Workflow.StateMachineTrackingService, myNamespace.Workflow.StateMachineTracking, Version=1.2.0.1, Culture=neutral, PublicKeyToken=gr4b2191f58h9e0d")] public class StateMachineTrackingService : TrackingService { //Body of your custom tracking service here } 

Low level, and my previously saved workflows now allow a new version of the tracking service.

0
source

Source: https://habr.com/ru/post/900879/


All Articles