Workflow 4.0 hosting extensions

Source: Internet
Author: User

dear readers,
to those of you who found this post interesting, but still a little too vague on how exactly you can use extensions for Workflow-host communications, how this ties in with bookmarking, or what might be involved in implementing your own custom send/receive semantics in a workflow activity, you may enjoy the sequel post 'workflow 4.0 hosting extensions Redux ']

Here's some really useful information for workflow 4.0.SoUseful, in fact, that it is covered by numerous other sources already (such as other people's blogs and the wf4 samples)-! It still seems that this information is hard to find and in particle I have a hard time finding them! So it seems fair to post it just in case.

 

a problem you might often see while designing actim activities is that the obvious ways of passing data to/from a workflow or activity only work when the workflow isn' t really alive.

example: imagine that I wrote a send e-mail and wait-for-reply activity. it has inputs (E-mail address), outputs (reply), and can maybe throw an exception (E-mail address rejected ). additionally, it will go idle and persist for a long time. during this time it leaves a bookmark open for the workflow's host to resume the workflow when a response email is wrongly ed. however, in order for the host to know which bookmark to resume, your e-mail activity will probably need to pass some extra information to the host, describing the event for which the bookmark shocould be resumed. neither inargument nor outargument nor variable is highly suitable for this job.

OK.

So, the question is basically "How can I get extra information back from the workflow to the outside world (the host )?"

 

A second problem you might also see is the same problem but in the opposite direction: "How can I get extra information from outside world (in particle, the workflow host) into my activity, mid-execution of the activity?

 

The answer is using hosting extensions, aka workflow extensions, aka just extensions. (I mentioned once a long time ago that you canAccessOrDeclareExtensions in a nativeactivity-now for some details.) There are a couple flavors in how you can set up an extension, but pretty much only one flavor of how to actuallyUseAn extension. You can do it in a codeactivity or in a nativeactivity, And it looks something like this:

 

Public sealed class codeactivity1: codeactivity
{< br> protected override void execute (codeactivitycontext context)
{< br> myextension extension = context. getextension ();
string result = extension. dosomething ("information");
}< BR >}

so what does context. getextension () actually return? This getextension () function is a stronugly typed version of The iserviceprovider pattern: It just returns your custom extension object, which you registered earlier, whatever you registered. your extension can literally implement any functionality that you want it to, but there will exist only one such extension object Per workflow instance, Per T (at last in the usual case this is what you want) which is returned every time any activity in the workflow instance CILS getextension ().

So, how did you set up myextension in the first place?

Well, there are two options.

1-Go through the class system. activities. hosting. workflowinstanceextensionmanager directly. an instance of this type is available through workflowapplication. extensions. this option can make sense if you are implementing (or customizing) the workflow host, and you want the host to set up the extensions before it starts running workflows.

2-your activity can register its own extension during cachemetadata () by calling activitymetadata. adddefaultextensionprovider (). This option makes sense if you are writing a custom activity class that shocould automatically set up its own extension no matter how it is being hosted. (This is useful if you don't own the host, or if you have has extensions, hosts, and it wocould be too much work registering the right extensions on every host .) an example of an activity in the framework which registers its own extnesion in this way is the delay activity, which registers a type called timerextension.

 

Hungry for more? Well, let's finally dig up the links to those related WF samples... (Relative paths)

Basic \ Services \ absolutedelay (a useful variant of Framework's delay activity)

Basic \ Services \ channelcache (using an extension to cache and reuse WCF channel objects, by the sound of it)

Basic \ execution \ controllingworkflowapplications (ReadlineWorkflow hostScenario)

Basic \ persistence \ persistenceparticipants (the persistance participant ipants system seems to be based on the hosting extensions)

Enjoy!

Update: for a way to use extensions in Service hosted XAML (xamlx) see Maurice's answer here: ' using workflow extensions (context. getextension) in IIS-hosted workflows '(ForUM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.