Workflow Application: Assembly: Use a .NET Class method as a Workflow Application

The Assembly workflow application allows you to declare a .NET class method as a workflow application. It’s the fastest solution to develop custom workflow applications (compared to web services).

The execution performance is also best because WorkflowGen instantiates the assembly directly, without network communication and without web service authentication.

Simple example

This example shows how to create a simple class library with methods used as workflow applications. Each supported datatype (Text, Numeric, DateTime, File) has a corresponding method.

The supported .NET datatypes for each WorkflowGen process data datatype are:

  • Text: String, Char, Byte, SByte, Boolean

  • Numeric: Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Decimal, Double

  • DateTime: DateTime

  • File: XmlDocument, XmlNode, XmlElement, WorkflowFile

  1. In Visual Studio, create a new Class library Solution called WorkflowAppSample.

  2. Add a reference to WorkflowGen.My.dll v2.3.4 or above (only required when you need to exchange files). This library is found in \wfgen\bin and will be included in the \bin folder of the WorkflowAppWCFSample website/app.

    Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using WorkflowGen.My.Data;
    
    namespace WorkflowApp
    {
    
        public class Test
        {
    
            public string GetString(string message)
            {
                return message + "!";
            }
    
            public DateTime GetDateTime(DateTime message)
            {
                return message.AddHours(1) ;
            }
    
            public Double GetDouble(Double message)
            {
                return message * 10;
            }
    
            public XmlDocument GetXml(XmlDocument message)
            {
                return message;
            }
    
            public XmlDocument GetFile(XmlDocument message)
            {
                if (WorkflowFile.IsWorkflowFile(message))
                {
                    WorkflowFile file = new WorkflowFile(message);
                    return file.GetXmlDoc();
                }
                else
                {
                    return message;
                }
           }
    
            public WorkflowFile GetWorkflowFile(WorkflowFile message)
            {
                message.Save("c:\\temp");
                return message;
            }  
    
      }
    
    }
    
  3. Compile the solution.

  4. Copy the generated WorkflowAppSample.dll assembly into the \wfgen\bin folder.

    Note: If you use Remote Approval, the Web Services API, or the WorkflowGen Engine service to complete workflow actions, you must also copy the DLL into the \wfgen\ws\bin and DRIVE:\Program Files\Advantys\WorkflowGen\Services\bin folders. (For more information, see Workflow Application: Assembly: The assembly system action started but did not complete successfully.)

  5. On the Applications page in the Administration Module, click New Application.

    Name: SAMPLE_GET_STRING
    Description: Returns a string with a !
    Type: Assembly
    Assembly full name or path: WorkflowAppSample

  6. Click Save.

    • Class full name: Select WorkflowApp.Test

    • Method: Select GetString

These parameters are automatically generated:

  • IN message (Text)

  • OUT RETURN_VALUE (Text)

You can now use this workflow application in your processes.

You can repeat the application creation for each class method to test the other datatypes.

Note: WorkflowGen does not yet support method overload (two methods with the same name but different parameters). This will be supported in a future release.

About File parameters

You can send or receive the content of a File to or from your .NET class method. There are two ways to do this:

  • If your method uses a WorkflowGen.My.Data.WorkflowFile object:

    public WorkflowFile GetWorkflowFile(WorkflowFile message)
    {
                message.Save("c:\\temp");
                return message;
    }
    
  • If your method uses an XmlDocument object, when WorkflowGen calls your methods, it converts the WorkflowFile object into an XmlDocument.

You can use the WorkflowFile.IsWorkflowFile() static method to check if the XmlDocument is a WorkflowFile.

If your method returns an Xml Document, WorkflowGen converts the Xml Document into a WorkflowFile if needed.

public XmlDocument GetFile(XmlDocument message)
{
            if (WorkflowFile.IsWorkflowFile(message))
            {
                WorkflowFile file = new WorkflowFile(message);
                return file.GetXmlDoc();
            }
            else
            {
                return message;
            }
}

Note: Because the file content is stored in memory, you have to avoid using these solutions for very large files.