Skip to main content

Create a Windows workflow application using Windows Workflow Foundation in IBM Database Add-ins for Visual Studio

Farzad Farahbod, Senior Software Engineer, IBM, Software Group
Farzad Farahbod photo
Farzad Farahbod is a senior software engineer working at the IBM Silicon Valley Lab, providing tools for seamless integration with IBM servers. He is also the Visual Studio .NET XML tooling lead.
Ajay Aggrwal, Advisory Software Engineer, IBM
Ajay Aggrwal
Ajay Aggrwal is an advisory software engineer with the IBM Database Add-ins for Visual Studio team.

Summary:  IBM®'s support for the Microsoft® .NET Framework 3.5 Windows® Workflow Foundation (WF) allows users to create Windows workflow applications that map directly to any IBM data server relational object. In this article, you'll see how easy it is to create a Windows workflow application to access DB2® or Informix® data, using the latest IBM Database Add-ins for Visual Studio. .

Date:  06 Nov 2008
Level:  Intermediate PDF:  A4 and Letter (667KB | 17 pages)Get Adobe® Reader®
Activity:  1326 views

Introduction

Windows WF is the programming model, engine, and toolset for quickly building workflow-enabled applications on Windows. It consists of .NET classes, an in-process workflow engine, and designers for Visual Studio. IBM Database Add-ins for Visual Studio workflow control allows users to easily create Windows workflow applications without knowledge of workflow or deep knowledge of IBM databases. In this article, you'll walk you through the process of creating your own workflow application to access relational data in an IBM database.

Prerequisites

In order to create WF applications using IBM's workflow component, you will need the following:

  • Visual Studio 2008 Professional Edition installed
  • IBM database Add-ins for Visual Studio Version 9.5 FP2 installed
  • IBM database Client 9.5 FP2 installed
  • Access to a DB2 or Informix database

You should have general familiarity with the IBM Database Add-ins for Visual Studio. To become more familiar with the general features of the IBM Database Add-ins for Visual Studio, read the "Overview of IBM Database Add-ins for Visual Studio 2005" and the Develop proof-of-concepts .NET applications tutorial series.

New users to Windows WF concepts and .NET Framework 3.0 can get acquainted to the this new technology by following these useful articles:

Use IBMDatabaseActivity component in a sequential workflow

Sequential workflow is a flow of events that run in a specific order. This means that each event occurs after another certain event has taken place. Now look at a simple example to illustrate a sequential workflow.

Assume that a customer places an order that needs to be shipped. This order can be processed after checking the inventory. This order receipt, verifying inventory to process the order and then shipping the order, is one of the simplest workflows. In real life, the workflow may include complex conditions as defined in if blocks. Events need to happen based on the outcome of the conditions defined in the if block. If the product in stock is less than the quantity ordered, the product needs to be reordered. Otherwise, the order can be processed and inventory updated.

The following steps illustrate a simple example for beginners and provide an introduction to the Windows workflow console application. You can create more complex applications after becoming familiar with this technology.

  1. Launch Visual Studio 2008 and create a connection to the database. Select Add Connection from the Server Explorer pop-up menu, which will launch the Add Connection dialog, as shown in Figure 1.

    Figure 1. Add Connection
    Add Connection dialog

  2. In the Data Source field, select IBM DB2, IDS and U2 Servers (IBM DB2, IDS, and U2 Data Provider for .NET Framework), and provide a server name, user ID, and password. Click Test Connection to verify whether the connection has been made successfully. Click OK.

    Figure 2. Add Connection
    Add Connection

  3. To create a workflow console application, from the main menu, select File > New Project. In the New Project window, expand the Visual C# node, then select Workflow. There are different workflow type applications. However, for this example create a state machine application by selecting the Sequential Workflow Console Application and naming it OrderWorkflow. Then click OK.


    Figure 3. Create the Sequential Workflow Console Application
    Create the Sequestial Workflow Console Application

    This creates a new Sequential Workflow Console Application project.



    Figure 4. New Sequential Workflow Console Application project
    New Sequestial Workflow Console Application project

  4. Drag and drop the IBMDatabase component from the Toolbox to the designer to start creating the workflow application.


    Figure 5. Adding the IBMDatabase component
    Adding the IBMDatabase component

    Note: If you can't see Workflow1.cs[Design] or IBMDatabase is not being shown with the steps here, check the prerequisites again. It is possible that some of the prerequisites are missing.

  5. Select ibmDatabase1 on the designer and rename it to IBMCheckInventory, using the property window.


    Figure 6. Setting properties for the IBMDatabase component
    Setting properties for the IBMDatabase component

  6. Add an IfElseActivity and two more IBMDatabase activities into each IfElse branch, rename these to IBMOrderStock and IBMProcessCustomerOrder. Finally, add one more IBMDatabase activity after IfElseActivity and name it IBMUpdateInventory.


    Figure 7. Adding conditions to the project


  7. To configure these activities (IBMCheckInventory, IBMOrderStock, IBMProcessCustomerOrder, and IBMUpdateInventory), select each activity, go to the Properties page, and set properties as illustrated here.

    For IBMCheckInventory, set CommandText to include the SQL (for example, select stockonhand from stocks), set CommandType to Text, ConnectString should include the connection information (this information is also available from the Advanced Properties dialog. Select the Modify Connection pop-up menu on the connection in Server Explorer, and click Advanced to launch the Advanced Properties dialog). Select the Source Table to get the data. Under Events properties, set the CommandExecuted property to include the method name.



    Figure 8. Setting properties for IBMCheckInventory
    Setting properties for IBMCheckInventory

  8. Click IBMOrderStock, IBMProcessCustomerOrder, and IBMUpdateInventory and update the properties as you did for IBMCheckInventory.


    Figure 9. Setting properties for IBMOrderStock
    Setting properties for IBMOrderStock



    Figure 10. Setting properties for IBMProcessCustomerOrder
    Setting properties for IBMProcessCustomerOrder



    Figure 11. Setting properties for IBMUpdateInventory
    Setting properties for IBMUpdateInventory

  9. In the Workflow1.cs class, add these private variables:
    private int _stockcounter;
    private int _ordercounter;
    



    Figure 12. Adding variables
    Adding variables

  10. In design view, click the IBMCheckInventory activity, and in the Properties window, type CheckInv in the CommandExecuted field:


    Figure 13. Set property name -- IBMCheckInventory
    Set property name -- IBMCheckInventory

  11. This will take you to the Code View window. There, add the code snippet below:
    private void CheckInv (object sender, EventArgs e)
    {
    Console.WriteLine("Cheking Inventory...");
    _stockcounter = (int)
     this.IBMCheckInventory.DataSet.Tables[0].Rows[0]["stockonhand"];
    Console.WriteLine("Stock on hand: " + _stockcounter.ToStrig());
    Console.ReadLine();
    }
    
    



    Figure 14. Adding code
    Adding code

  12. Go back to the Design View, and click ifElseBranchActivity1. In the Properties window, click the Condition row and select Declarative Rule Condition. Expand the row and set the condition name as LessThan. Click Expression, and in the Rule Condition Editor window, enter the following code:
    this._stockcounter < 1
    

  13. Do the same for the other branch and name it GreaterThan and give the expression:
    this._stockcounter >= 1
    

  14. In Design View, click IBMOrderStock, and in Properties window, type OrderStock in the CommandExecuted field:


    Figure 15. Set the property name -- IBMOrderStock
    Set property name -- IBMOrderStock

  15. This takes you to the Code View window. There, add the code snippet below:
    private void CheckInv (object sender, EventArgs e)
    {
         Console.WriteLine("Out of stock. Item reordered...");
    }
    
    

  16. In Design View, click IBMProcessCustomerOrder and in Properties window, type ProcessCustomerOrder in the CommandExecuted field:


    Figure 16. Set the property name -- IBMProcessCustomerOrder
    Set the property name -- IBMProcessCustomerOrder

  17. This takes you to the Code View window. There, add the code snippet below:
    private void ProcessCustomerOrder (object sender, EventArgs e)
    {
         Console.WriteLine("Order Processed...");
    }
    

  18. In Design View, click IBMUpdateInventory and in the Properties window, type UpdateInventory in the CommandExecuted field:


    Figure 17. Set the property name -- IBMUpdateInventory
    Set the property name -- IBMUpdateInventory

    This takes you to the Code View window. There, add the code snippet below:

    private void UpdateInventory (object sender, EventArgs e)
    {
         Console.WriteLine("Inventory updated...");
    }
    

Press F5, or click Run, in order to run the project. You will get different outputs. However, two possible outputs for value 1 and 0 are shown in Figures 18 and 19:


Figure 18. Displaying output
Displaying output

Figure 17. Displaying output 2
Displaying output 2

Conclusion

As illustrated in this article, it is fairly easy to create a sequential workflow application that executes a series of predefined steps to accomplish a certain task. You can define complex business rules using other available components. IBM Database Add-ins has included the IBMDatabase component to simplify the creation of a WF application with IBM database servers. Windows WF applications support dynamic business situations and complex requirements that are the need of the day and handling these requirements with ease of use can help users meet business challenges effectively.


Resources

Learn

Get products and technologies

  • Download IBM product evaluation versions and get your hands on application development tools and middleware products from IBM Information Management, Lotus®, Rational®, Tivoli®, and WebSphere®.

Discuss

About the authors

Farzad Farahbod photo

Farzad Farahbod is a senior software engineer working at the IBM Silicon Valley Lab, providing tools for seamless integration with IBM servers. He is also the Visual Studio .NET XML tooling lead.

Ajay Aggrwal

Ajay Aggrwal is an advisory software engineer with the IBM Database Add-ins for Visual Studio team.

Comments (Undergoing maintenance)



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Information Management
ArticleID=350043
ArticleTitle=Create a Windows workflow application using Windows Workflow Foundation in IBM Database Add-ins for Visual Studio
publish-date=11062008
author1-email=ffarahbo@us.ibm.com
author1-email-cc=
author2-email=aaggrwal@us.ibm.com
author2-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Special offers