TechBubbles Microsoft Technology BLOG

Creating Custom Activities in Windows Workflow Foundation

Introduction

Activities are basic units in workflow execution. Activities are two types basic activities and composite activities. Basic activities are steps in the workflow and composite activities  can contain other activities.

Base activities are comes with Workflow Foundation and these can be used by dragging it from visual studio toolbox. We can also create custom activities that appear in the visual studio toolbox.

Activities are like classes and we can define properties, methods and events.

We can build an activity or multiple activities into .NET assembly and deploy them as re-usable assemblies.

 

In this post we will learn how to create custom activities and properties in workflow foundation.

Create a workflow project

1. Create a workflow project by selecting the File->New->Project menu command and it displays a dialogue box select the Sequential Workflow Console Application template and click ok.

activity  

2. Rename the Workflow1.cs workflow to SendMailWorkflow.cs.

Create an Activity Project

1. Add new project to the existing solution by selecting the Add new project option. select the Workflow Activity Library template from the dialogue box.

sendmail

2. Enter the SendMailActivityLibrary in the name field and visual studio creates a active library project.

3. Rename the single activity named ativity1 to SendMailActivity.

4. Click on the SendMailActivity in the workarea  to view the properties window.

clip_image002

5. Select the Base Class property from the properties window which displays the following dialogue box

clip_image001

 

6.In the type tab, Select the System.Workflow.ComponentModel.

7.The list box in the right side displays the available base classes activity and composite activity.

8. Select  activity and click Ok.

9. In the code beside file for the send mail activity write the following code

clip_image002

10. In the same way we can write the properties for From, Subject and Body.

11. Build the Workflow solution notice that sendmailactivity is now present in the Tollbox window.

clip_image002[9]

12. Drag the SendMailActivity from the Toolbox window and drop it on the workflow designer area and change the name property of the activity to sendMail.

13. You can see the custom properties that we have created in the previous steps.

clip_image002[11]

14. Add an Executor Component to the SendMailActivity.cs file

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

Console.WriteLine(To);

return ActivityExecutionStatus.Closed;}

Conclusion

We have learned how to create a custom activity and property in workflow foundation and using the defined property in the customactivity.

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

6 Comments

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud