index > Windows Workflow Foundation > Dynamic Update from Custom Activity

Dynamic Update from Custom Activity

How can I do Dynamic Update from Custom Activity? I could not access ApplyWorkflowChanges() from within the Custom Activity.

Any ideas to solve this are appeciated.

Thanks

KarimRadi

You can create a WorkflowRuntimeService that does the work:

in a hurry, I would write this :

step 1 class MyUpdateService : WorkflowRuntimeService {

public void MakeTheUpdateHere(Guid aGuid)

{

WorkflowInstance instance = this.Runtime.GetWorkflow(aGuid)

...

instance.ApplyWorkflowChanges(...)

}

}

step 2 Add the service in the workflowRuntime

step 3 In your custom activity :

class MyCustomClass {

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{

MyUpdateService myService = executionContext.GetService<MyUpdateService>();

myService.MakeTheUpdateHere(this.WorkflowInstanceId);
return ActivityExecutionStatus.Closed;
}

}




Serge Luca; Guidance Belgium; blog: www.redwood.be
Serge Luca

Thanks Serge,

I have tried your suggested solution in the past BUT when I ApplyWorkflowChanges() (when the Workflow Instance is not suspended/idle) I get this error "Instance operation is not valid on workflow runtime thread"! In the past I have also posted this problem in the forum but I got no answer (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=684011&SiteID=1).

Any further ideas are appreciated.

Thanks

KarimRadi

Hi Karim,

1?If you choose the "Service Way of working" (personally I prefer decoupling my workflow from this kind of stuff)

you can Suspend and Resume it in the service:

 

public void MakeTheUpdateHere(Guid aGuid)

{

WorkflowInstance instance = this.Runtime.GetWorkflow(aGuid)

insance...Suspend(...);

instance.ApplyWorkflowChanges(...)

instance.Resume();

}

 

2?If you choose Matt's idea:

Since ApplyWorkfllowChanges is protected, you can provide a public function at the WorkflowActivity level (ex: ApplyChanges) that will call the protected ApplyWorklowChanges

 

class MyWorkflow : SequentialWorkflowActivity {

public void ApplyChanges(....)

{

this.ApplyWorkflowChanges(...);

}

}

 

 

in your activity :

class MyCustomActivity : Activity {

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
         

   Activity rootActivity   ...get the root activity as you did

   ((MyWorkflow) rootWorkflow).ApplyChanges(...);
    return ActivityExecutionStatus.Closed;   
}

}

 

Hope this helps; let me know if that works (I haven't tested it)

Serge




Serge Luca; Guidance Belgium; blog: www.redwood.be
Serge Luca

Use the parent property recursively to move up to the workflow itself (parent is null) or composite activity and then use the ApplyWorkflowChanges method from the composite activity class.

Matt




See What You Can Learn -- http://www.pluralsight.com/courses/IntroducingWF.aspx
Matt Milner - Pluralsight

Thanks Matt,

BUT the composite activity class does not have ApplyWorkflowChanges method. I have tried this:

Activity parentActivity = executionContext.Activity.Parent;

while(parentActivity.Parent != null)

{

parentActivity = parentActivity.Parent;

};

((CompositeActivity)parentActivity).<<ApplyWorkflowChanges DOES NOT Exist>>

Could you please let me know what is the mistake I am doing? and how to access ApplyWorkflowChanges method from a Custom Activity?

Thanks

KarimRadi

Sorry, too quick on the keys, that method is protected.

If your custom activity derives from composite, you should be able to apply changes to your activity and children.

If you need to apply changes to the workflow itself, it might be best to create a custom worklow that derives from the base you wish to use (sequential or state machine) and then open up the ApplyworkflowChanges method.

Matt




See What You Can Learn -- http://www.pluralsight.com/courses/IntroducingWF.aspx
Matt Milner - Pluralsight
reply 7

You can use google to search for other answers

 

More Articles

• workflow s/w seggregation
• Web Service credentials
• Versioning in WorkflowCompiler
• Event Sink question
• Suggestion for the SQLTracking Service
• Default values of dependency properties
• Bind the CurrentItem property of the ForEach activty
• Nothing changed in Feb CTP?
• Problems with Rehosting work flow designer in ASP.NET example
• Is WF adequated to build an OLTP middleware tier?
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Pageflow Engine
• how to implement human workflow using St
• Hide compensation tab
• Xoml customization and compilation
• Beta 2: WorkflowMarkupSerializer (De)Ser
• Assign a different Item for each task in
• Where can I get guides about Workflow Fo
• Issue loading & resuming an unloaded
• Jon, quick question on Workflow Designer
• Event cannot be delivered
• xoml vs. code
• InvokeWebservice vs. code
• Binding workflow parameters with activit
• XOML and Parameters
• WF version packaged with WinFX Beta 2

Hot Articles

• multi choice pattern
• Custom/Preconfigured StateActivity
• Output path property settings
• WebServiceInput Activity Error: Paramete
• Can you get the current state of a State
• How to reference to System.Workflow.Runt
• Workflow arrows not showing up - what's
• The workflow hosting environment does no
• Access Workflowruntime
• Installation Issue
• EventSink Roles terminates workflow
• deserialization of a List<string>
• Binding to an item within an array.
• DesignerSerializationManager seems to no
• Missing Condition Error

Recommend Articles

• How to determine if WorkflowInstance is
• workflow conference dvd
• install infoPath workflow application on
• About "Presenting Windows Workflow
• InvokeWorkflow In the same context...
• InnerException {"Event \"HighR
• WF Designer: Glyph provider is not being
• Can I show the graphically workflow on t
• Data Activites missing - UpdateDate Sele
• Questions on MSDN WF rules engine article
• Persistence services
• Beta2 - CallExternalMethod vs InvokeMeth
• How to implement custom rules using Rule
• Help regarding windows service which wil
• Workflow Runtime Engine for every applic