1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Introduction to Windows Workflow Foundation

Discussion in 'ASP.NET' started by MinalS, Mar 6, 2015.

  1. MinalS

    MinalS New Member

    Joined:
    Jul 8, 2014
    Messages:
    138
    Likes Received:
    30
    Trophy Points:
    0
    Windows Workflow Foundation is a part of .NET 3.0 framework released by Microsoft. The business process code and the actual implementation need the Service Oriented Architecture. In WCF, the business logic is defined in the workflow. The implementation of the code is defined in C#, VB or any .NET language.

    Let’s explore the features of the Windows Workflow foundation.

    1. Activities

    The activity is the basic block of the Windows Workflow. It consists of steps, tasks in the workflow, and workflow definition. The activities can be added in hierarchical manner and the engine executes the instructions.

    The Activity is the base class for all the activities. The common operations for all the activities are defined. Common properties, events and activities are defined in the workflow.

    The different types of activities derived from the base class Activity are NativeActivity, CodeActivity, AsyncCodeActivity, etc. The activities have two behavior types as runtime and design time.

    The runtime specifies the action that execute upon execution. The design time is used for controlling the look of the activity and interaction displayed in the designer window.

    2. Custom Activities

    The functionality of the base activity can be extended using the custom activities for solving the problem in the domain. The custom activities derive from the Activity base class.

    The domain specific languages for creating the solutions are done using custom activities. The problem space can be simplified using the specific language.

    Windows WorkFlow and XAML

    The Workflow designer can create the Visual basic and C# for representing the workflow. The XAML files can be used for reading and writing data. The XAML files are XML files. The XAML generates the code for the workflow is as shown below:

    Code:
    
    <SequentialWorkFlowActivity xmlns=”http://schemas.micorosft.com/winfx/2006/xaml” 
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/workflow”
    x:Class=”NewTech.NewTechWorkflow”
    >
    <CodeActivity x:Name=”codeActivity1” x:Name=”codeActivity1” ExecuteCode=”codeActivity1_ExecuteCode1” />
    </SequentialWorkFlowActivity>
    
    
    Services

    The WorkFlowRuntime class provides the basic features for executing workflows. The runtime engine uses many services when the workflow instance is executed. The workflow provides default implementations at the runtime. The services provided by the runtime engine are scheduling services, transaction services, tracking services, and persistence services.

    The custom services are created to extend the Windows Workflow foundation by deriving the base services classes. The AddService method allows user to provide one or more services to the user at runtime. They can be custom services written for specific domain.

    Scheduling Services

    The scheduling service controls threads runtime need for the workflow execution. The DefualtWorkflowSchedulerService creates new thread for the workflow execution. The application threads are simultaneously executed without blocking other application threads.

    The ManualWorkflowSchedulerService is a scheduling service useful when the host application is ready to donate threads to the workflow runtime. The concept is useful in web application where server side applications access thread from pool and service client request.

    Transaction Services

    The transaction service allows runtime to save the internal state of the workflow consistent with the state in a durable store. The service is an instance of DefaultWorkflowTransactionService class. The activities and the services operating on the same instance share the similar content.

    The System.Transactions namespace is used for implementing transactions. The class contains light weighted, promotable transaction.

    Persistence Services

    The persistence services are useful for storing the state of workflow to durable store. The SqlWorkflowPersistenceService service saves the workflow state to workflow in a SQL Server database. The runtime reloads the workflow instance and the process is resumed.

    The runtime will automatically persist the workflow which is idle or suspended when the service is available. The service can be executed with different versions of SQL Server.

    Tracking Services

    The tracking service is useful for monitoring and recording information about the execution of workflow. The information is saved as the instance is executed. The SqlTrackingService uses the SQL database for storing the tracking information.

    The tracking profile helps user to configure the type and information the service needs to receive for the workflow instance. The tracking service request a tracking channel associated with the workflow.

    The three types of events the tracking service can track are user events, workflow instance events, activity events. The runtime does not start the tracking service by default. User can programmatically add the tacking service.

    Correlation

    The workflow service messages are related to each other using correlation. The messages can be reply to the request or an application instance state. The correlation can be protocol based or content based.

    The protocol based correlations use the data provided by the message delivery structure for mapping between messages. The messages correlated through protocol based correlation are related using object in memory. Content based correlation relates messages using the application specific data. The messages are correlated using the correlation through application defined data in the message.

    The CorrelationHandle is useful for combining the message activities together. The pattern is used is basic in both the protocols. The CorrelationScope activity is used to explicitly set the correlation handle on an activity. The scope activity provides user with the connection handle for a request reply correlation. The hosting of workflow services using WorkflowServiceHost have same default correlation management.

    Example to demonstrate the Simple Workflow
    1. Open the Visual Studio application.
    2. Select ‘File’, ‘New Project’, select ‘Workflow Console Application’ in the Workflow project type.
    3. Add the project name and click OK.
    4. Right click on the Project, add new item, select Activity.
    5. Save the activity with an appropriate name.

      [​IMG]
    6. The workflow designer window is opened.
    7. From the Toolbox, add the WriteLine Activity from the Primitives category in the designer workflow.

      [​IMG]
    8. Select the TextBox and add the following code.

      [​IMG]
    9. In the xaml application, from the toolbox add the Assign activity above the WriteLine activity.
    10. The sequence activity is automatically added in the application.
    11. Open the Variables tab from the bottom left side of the designer.
    12. Select the sequence activity in the designer. In the Variables tab, create variable and type name for the variable name.

      [​IMG]
    13. Add the variable name in the textbox. Type the following code in the Expression textbox.

      [​IMG]
    14. Add the WriteLine activity above the Assign activity.
    15. The final workflow is as shown below:

      [​IMG]
    16. Build the solution and execute the application.

      [​IMG]
     
    shabbir likes this.

Share This Page