Workflow Applications
Application types
The following application types are covered in this section:
Web procedures
Asynchronous web procedures
The following application types are not covered in this section:
Incoming webhooks
Non-interactive clients
SOAP web services
WCF services
Web applications
How it works
When an action using a workflow application is launched, WorkflowGen sends the parameters in a JSON or XML file (depending on the context format previously chosen during the creation of the application) to the application using the HTTP protocol. The application uses the JSON or XML file to get the parameters and executes its operations. Once the application is done, a JSON or XML file with the OUT parameters is sent back to WorkflowGen. JSON is supported by Webproc and Webproc Async applications. For web services, the SOAP protocol is used to communicate with the application. Web services that don’t use the SOAP protocol to communicate with WorkflowGen application will be referred as WebProc applications.
Note: The JSON context is supported as of WorkflowGen version 7.0.0.
Requirements for .NET development
.NET Framework version
The WorkflowGen.My assembly requires .NET Framework 4.
WorkflowGen.My assembly
In order to implement a custom workflow application using the .NET Framework, you must have the latest version of WorkflowGen.My 3.x referenced in your project. To directly reference an assembly in your web project, do the following:
Create a \bin directory under your project root folder (e.g. \wfgen\wfapps\sdk\MyProject\bin).
Copy the "WorkflowGen.My.dll" file to this folder.
Right-click on your project name and choose Add reference...
Click Browse.
Navigate to the \bin directory you created and choose the "WorkflowGen.My.dll" file, then click OK. WorkflowGen.My is now referenced in your project.
You can also put this assembly in your GAC (Global Assembly Cache) in order to have only one centralized reference, instead of referring to a copy of the assembly in each project. To install the assembly in your GAC, do the following:
Copy "WorkflowGen.My.dll" to DRIVE:\Windows\system32.
Open a command prompt and browse to DRIVE:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\v3.5\Bin.
Enter the command
gacutil /i c:\windows\system32\WorkflowGen.My.dll
, then pressENTER
. WorkflowGen.My is now in your GAC.
If you want to use an assembly from the GAC, you should drop your assemblies into a local folder, and then add a reference to the assembly from this folder. You may want to set the Copy Local
property to False
for that assembly if you don't want the assembly to be copied locally to your project folders. At runtime, the application will automatically use the assembly from the GAC.
Important: WorkflowGen.My.dll 3.4.0 and later requires Newtonsoft.Json.dll in the same BIN or GAC.
Configuration settings (app.config
or web.config
)
app.config
or web.config
)The WorkflowGen.My assembly does not require any particular configuration settings.
Deploying a custom assembly
There are some considerations when deploying a custom assembly SDK workflow application in WorkflowGen, namely the assembly location, the reference to WorkflowGen.My, and references to other software libraries.
Assembly location
There are two ways of deploying an assembly file in WorkflowGen.
Method 1: Reference by assembly’s full name
The assembly file must be copied to the three bin folders containing the WorkflowGen executable files: \wfgen\bin
, \wfgen\ws\bin
, and DRIVE:\Program Files\Advantys\WorkflowGen\Services\bin
.
Method 2: Reference by assembly’s path (full physical path with file name)
The assembly file can be copied to a custom folder such as DRIVE:\MyWorkflowApps\Assembly.dll
, and then use that specific path in the workflow application’s definition.
Important: If your custom assembly has dependencies, they must be located in the same folder as the assembly.
Reference to WorkflowGen.My
WorkflowGen.My v3.1.0 and earlier
WorkflowGen.My versions 3.1.0 and earlier are strong-named, which means your assembly must be built with and use the same version as your target WorkflowGen. This requires recompiling your assembly whenever you upgrade WorkflowGen to a newer version.
You can use one of the following workarounds to overcome this requirement:
Install the required WorkflowGen.My version in the system's global assembly cache (GAC). For instructions on how to do this, see the How to: Install an assembly into the global assembly cache Microsoft article. OR
Add a delegate to handle the assembly resolve event in order to load the current WorkflowGen.My version. For instructions on how to do this, see the How to add an assembly resolve event delegate to overcome WorkflowGen.My dependency issue when deploying custom assembly SDK workflow application article on the WorkflowGen Forum & Knowledge Base. OR
Add a web configuration setting to redirect the required version to the current version of WorkflowGen.My. For more information, see the <assemblyBinding> Element for <runtime> Microsoft article.
Note: If your assembly is built with WorkflowGen.My v3.1.0 or earlier, it can be used in WorkflowGen version 6.2.0 and later if one of the above workarounds has been implemented.
WorkflowGen.My v3.2.0 and later
As of version 3.2.0, WorkflowGen.My is no longer strong-named in order to allow non-specific version dependency when referenced by your assembly. You can simply deploy your assembly file using one of the two methods in the Assembly location section above in WorkflowGen 6.2.0 and later.
Note: If your assembly is built with WorkflowGen.My v3.2.0 or later, it can be used in WorkflowGen versions prior to 6.2.0 if you have implemented either workaround 2 or 3 above.
References to other software libraries
If your assembly uses third-party libraries, then these must also be deployed into the three WorkflowGen executable \bin
folders. Alternatively, they can be installed into the system’s global assembly cache (GAC) if they are strong-named assemblies.
WorkflowContext
WorkflowContext is a JSON or XML data structure used to exchange parameters with WorkflowGen. The context format is used by both web procedures and asynchronous web procedures.
For an example of an XML ADO.NET dataset context, see WorkflowContext in the Web services API section.
As of WorkflowGen 7.0.0, the application can build ContextParameters
instances from JSON strings. The JSON should respect the following structure:
JSON example:
WorkflowContext creation with WorkflowGen.My
Loading the WorkflowGen context
In order to manipulate a WorkflowGen context, it is necessary to load it into a ContextParameters
object instance. Usually, you will receive the context in a string variable. Follow these steps to load the WorkflowGen context into a new ContextParameters
object instance.
To load the context, you only have to build a new ContextParameters
instance. The following sample code loads the context from a workflowGenContext
string:
C#
Reading a data parameter from the context
You can access any data parameter in the WorkflowGen context by using the contextHandler
(ContextParameters
instance) that you created in the previous section.
When you access a single parameter, you store it in a ContextParameter
object to manipulate it.
Get a particular parameter from the context
To access a particular parameter from the context, use the ContextParameters
indexer. The following example accesses a DATE_EXAMPLE
parameter in the previously loaded context:
C#
Get the ContextParameter value
To access the value of the context parameter, use the Value
property of the ContextParameter
instance that you retrieved in the previous section.
C#
The dateValue
variable now contains the DATE_EXAMPLE
parameter value.
Filtering the ContextParameters collection
Suppose that you would like to iterate over all the "IN" parameters of the ContextParameters
instance. You could do this by using a filter, and then by using the collection enumerator. Don't forget to remove the filter afterward, or else you won't be able to access the other parameters.
C#
Modifying a parameter value in the context
After you have stored your data parameter in a ContextParameter, you can modify its value.
C#
Note: If you try to modify a parameter with the wrong data type, you will only receive an exception when you try to serialize the context back to a JSON or XML string.
Adding a parameter to the context
In order to add a parameter to the context, you need to build a new ContextParameter
instance, define its name and direction, and then add it to the ContextParameters
instance you already have.
C#
Working with file parameters
File parameters need to be put into a ContextFileReference
instance. The following is an example that extracts a file parameter value into a ContextFileReference
, then modifies the file parameter so that it points to another sample file.
C#
Web procedure development using an ASP.NET XML web service
Overview
The most widely-used type of WorkflowGen integration is the web procedure. Web procedures are used to receive a WorkflowGen context as a parameter, manipulate it, and then return the modified context to WorkflowGen.
Note: As of WorkflowGen 7.0.0, the term "web services" is only used to refer to web services using the SOAP protocol; all others are referred to as web procedures.
Creating the web procedure
Suggested development tools
Visual Studio Standard or Professional 2013 or later
Web procedure installation directory
We strongly suggest that you put all of your web services in the \wfgen\wfapps\WebServices\MyWebProc folder.
Be aware that if you modify your WorkflowGen process and you need to modify the associated MyWebProc
because of those changes, you should duplicate MyWebProc
beforehand and create another IIS application, otherwise the two versions of the process will use the same modified MyWebProc
.
Creating the application in IIS
The web service directory must be declared as an application in IIS in order to be recognized as a .NET web service application. To declare your web service directory as an IIS application, do the following:
For IIS 7 and later
Open Internet Information Services (IIS) Manager.
Navigate to your web form location, which should be under the Default Web Site node, under \wfgen\wfapps\webservices\MyWebProc.
Right-click on MyWebProc and choose Convert to Application.
Select the application pool used by your site and another specific application pool.
Click OK.
Creating a web procedure workflow application using an ASP.NET XML web service
You can create a web procedure using an ASP.NET web service, but this Visual Studio template is only available for .NET versions 2.0 to 3.5.
Open Visual Studio.
Select File > New Web Site.
Choose ASP.NET Web Service (available for .NET Framework versions 2.0 to 3.5).
Choose File system from the Location drop-down list.
Click Browse and choose the location of your ASP.NET website.
Click OK.
Obtaining detailed error messages
In order to be able to see complete error messages, change the following properties in the "web.config" file:
Make sure this line is set to true
:
Make sure this is not commented and that the mode="Off"
:
Authorize GET and POST protocols
In order to use a web service with WorkflowGen, the GET and POST protocols must be enabled in the "web.config" file of the web service. The following are the necessary nodes to insert in your "web.config", in the system.web
node:
Configure the IIS rendering framework version in the "web.config" file
You will need to revert to the behavior of having only .aspx pages trigger request validation by adding the following code to your "web.config" file:
Basic implementation
Overview
In order to demonstrate how to implement a web procedure that process a context from WorkflowGen, we'll build a simple web service that converts an amount in Euros to an amount in U.S. dollars.
Reference
You must add a reference to WorkflowGen.My.dll in your web project, and then add a "using" statement (for the WorkflowGen.My.Data namespace of the WorkflowGen.My assembly. For example:
C#
Specifying your class signature
If you want to receive a JSON formatted context, you should add the following signature, located in the "App_Code\Service.cs" file, to your web procedure's Service
class (note that ScriptService signatures aren't required for other context formats). Your service class should look like this:
Specifying your web method signature
Only the methods that have the WebMethod
attribute can be remotely executed. The default web method signature which is created with your web service should look like this:
C#
We'll modify this signature name and add a parameter, which will be the WorkflowGen context. Any web procedure you create will only need this one context parameter for each web method you create.
C#
If you web procedure response returns the context with JSON format, you can add the [ScriptMethod]
signature to your web methods. In this case, the context will be returned by the method using the JSON format (enclosed by { }
).
C#
Otherwise, you don’t add the [ScriptMethod]
signature and convert your returned context directly to JSON in your code. You can use a library such as Newtonsoft.Json to serialize your context.
Note: The parameter name should always be WFGEN_CONTEXT
, which is case sensitive.
Variable and constant declarations
Now, we'll declare the variables we need and retrieve the exchange rate from the "web.config" file. This is the necessary code in the "web.config" file to add the ExchangeRate
key:
C#
Loading the WorkflowGen context
The next thing to do is create a ContextParameters instance that will be used to work with the WorkflowGen context we are receiving as a parameter.
C#
Managing errors
Our web procedure needs to receive two parameters: AMOUNT_DOLLARS
(OUT) and AMOUNT_EURO
(IN). If one of these parameters is missing, we have to inform the end-user that they forgot to pass these parameters to the web service. The only way to stop the web procedure execution and to send an error message back to WorkflowGen is to throw a new SoapException
. We'll now verify if the user provided the AMOUNT_EURO
parameter before getting the value from it. If the user did not provide it, we send a new SoapException
to WorkflowGen with a clear message.
C#
Retrieving the AMOUNT_EURO parameter from the context
We'll now get the AMOUNT_EURO
value into our amountEuro
double variable, and at the same time, we will verify that the value is not null, if so, we will send another exception.
C#
Modifying the AMOUNT_DOLLARS parameter with the new value
We will now modify the AMOUNT_DOLLARS
parameter with the AMOUNT_EURO
value modified using the exchangeRate
variable.
C#
Returning the modified context to WorkflowGen
Now that we have processed the context, we need to return the context back to WorkflowGen. Here is the necessary code to return the context depending on the context format you choose when creating or editing your WorkflowGen application:
C#
OR
Asynchronous web procedure development in .NET Framework
Overview
The asynchronous procedures allow a WorkflowGen system action to be run asynchronously, meaning that the action is initiated at some point in time during the workflow and can be completed at a later instance by an external application.
This type of asynchronous processing can be used in cases where a system action, like a Web service, can time out or cause the UI to hang while processing a large volume of information.
This section will explain how to develop an asynchronous web procedure application by using WorkflowGen.My v3.3. The development will have two different parts: a web procedure that receives and processes the context, and a listener to complete and close the open action (a console application in this example).
Creating the asynchronous website
Suggested development tools
Visual Studio Standard or Professional 2013 or later
Website installation directory
We strongly suggest that you put all your asynchronous web procedure SDK in the \wfgen\wfapps\WebServices\sdk\MyWebProcAsync folder.
Creating the application in IIS
The website directory must be declared as an IIS application in order to be recognized as a .NET website application. Follow these instructions to declare your website directory as an IIS application:
For IIS 7 and later
Open Internet Information Services (IIS) Manager.
Navigate to your web form location, which should be placed under the Default Web Site node, under wfgen/wfapps/WebServices/sdk/MyWebProcAsync.
Right-click on MyWebProcAsync and choose Convert to Application.
Select the application pool used by your site and another specific application pool.
Click OK.
Create the project with Visual Studio
Creating the project
Open Visual Studio.
Select File > New Web Site.
Choose ASP.NET Web Site.
Chose File system from the Location drop-down list.
Click Browse and choose the location of your ASP.NET website.
Click OK.
Obtaining detailed error messages
In order to be able to see complete error messages, change the following properties in the "web.config" file:
Make sure this line is set to
"true"
:```
```
Make sure this is not commented and that the
mode="Off"
.
Basic implementation
Overview
In order to demonstrate how we can implement an asynchronous web procedure application, we have developed a simple ASP.NET website example that receives a context containing three IN parameters: ACTION_ID
, REQUEST_ID
, and AMOUNT_EURO
, and the OUT parameter AMOUNT_DOLLARS
. The web application processes the incoming parameters, in order to convert the AMOUNT_EURO
value into dollars.
You must add a reference to "WorkflowGen.My.dll" in your web project, then add a using
statement for the WorkflowGen.My.Data
namespace of the WorkflowGen.My assembly.
C#
We'll use the Page_Load
event in code-behind to immediately start the asynchronous web procedure. Inside the Page_Load
event, you should get the application string context and make the needed conversion to get a JSON or XML string. Be aware that WorkflowGen will send the context to your external application formatted in dependence of your chosen context format and context type when creating or editing your application in WorkflowGen application form.
For example, if you choose JSON context with application/json
content type, your incoming payload will have the following structure:
In this case, you can read the HTTP Request body content, and convert it to a valid JSON string (in this example we use the Newtonsoft.Json library to serialize/deserialize JSON files). Afterwards, we pass the correctly formatted context into a method named StartAsynchronousAction
that will process the context parameters.
C#
In the case of ADO.NET DataSet WorkflowGen Context, the context is obtained directly from the HTTP Request and passed to the StartAsynchronousAction
method.
C#
Using the "web.config" to store your configurations
It is suggested to use the "web.config" file to store all the configurations, instead of hard coding them directly in your website's code-behind. In this case, you should add the ExchangeRate
key and its value in the "web.config" file to use it in the application currency conversion:
If you will be storing your application context in a database, you will need to add the connectionString
node to the "web.config" file:
This is the code that declares all the variables needed for the asynchronous web procedure, and then gets the "web.config" values to populate some of these variables.
C#
In this example, some variables takes their values from the database.
Building a context
We now need to build a new context to send to WorkflowGen to complete the asynchronous action. Here is the necessary code to create a new context:
C#
You can get the IN parameter values from the ContextParameters
instance:
C#
Then, the application processes the currency exchange and saves the final value into the AMOUNT_DOLLARS
OUT parameter.
C#
If the asynchronous web procedure chosen context format is JSON (the default context format), the application result will use this file format:
If the context format is XML ADO.NET DataSet, the returned value will be formatted as XML.
In this example, the variables needed to complete the application will be saved in a database, to be used by the Asynchronous Web Procedure listener.
Building the asynchronous web procedure listener
After having created the website used to launch the asynchronous web procedure, we need to develop a listener that will complete the web request, sending the context back to WorkflowGen. In this case, we have developed a console application for this purpose.
The application uses the same database as the web procedure previously developed, and gets the database parameters from there.
C#
The application sets the status to CLOSE
for the asynchronous web procedure in the database.
The console application then sends the context back to WorkflowGen.
Note that the POST method content would have the following structure:
and the context has to be formatted according to the asynchronous web procedure content type. In the case of JSON, the JSON string has to respect the JSON parameter structure explained earlier.
Starting the process and sending the context
After having created the context, we need to make a web request to WorkflowGen to start the remote process, and we also need to post the context to the new process instance. Here is the necessary code:
C#
Managing errors
After starting the process, you might receive errors from WorkflowGen if something is not working as expected. Here is the necessary code to display the WorkflowGen error so that you can debug your RemoteLaunch application:
C#
Managing errors
It is advised to prepare your code to get errors in case they occur; especially when the context is sent, it is useful to know all details in case of error.
C#
Last updated