RemoteLaunch Development in .NET Framework

Overview

The RemoteLaunch SDK is used to launch a WorkflowGen process from the outside of the WorkflowGen environment. This section will explain how to develop a RemoteLaunch SDK application using WorkflowGen.My v3.3. You'll need to create a new website for each RemoteLaunch SDK application you need.

Creating the RemoteLaunch website

Suggested development tools

  • Visual Studio Standard or Professional 2013 or later

Website installation directory

We strongly suggest that you put all of your RemoteLaunch SDKs in the \wfgen\wfapps\sdk\MyRemoteLaunch folder.

Creating the application in IIS

The RemoteLaunch site 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

  1. 1.
    Open Internet Information Services (IIS) Manager.
  2. 2.
    Navigate to your web form location, which should be placed under the Default Web Site node, under \wfgen\wfapps\sdk\MyRemoteLaunch.
  3. 3.
    Right-click on MyRemoteLaunch and choose Convert to Application.
  4. 4.
    Select the application pool used by your site and another specific application pool.
  5. 5.
    Click OK.

Creating the project with Visual Studio

Creating the project

  1. 1.
    Open Visual Studio.
  2. 2.
    Select File > New Web Site.
  3. 3.
    Choose ASP.NET Empty Web Site.
  4. 4.
    Chose File system from the Location drop-down list.
  5. 5.
    Click Browse and choose the location of your ASP.NET website.
  6. 6.
    Click OK.

Obtaining detailed error messages

By default, you will have no web.config file in your web project if you are using C# as your development language in the Visual Studio IDE. In order to be able to see complete error messages when you want to debug, you have to have a web.config file.
In order to be able to see complete error messages, change the following properties in the web.config file:
  1. 1.
    Make sure this line is set to "true":
    1
    <compilation debug="true" />
    Copied!
  2. 2.
    Make sure this is not commented and that the mode="Off":
    1
    <customErrors mode="Off" defaultRedirect="GenericErrorPage.htm">
    2
    <error statusCode="403" redirect="NoAccess.htm" />
    3
    <error statusCode="404" redirect="FileNotFound.htm" />
    4
    </customErrors>
    Copied!

Basic implementation

Overview

In order to demonstrate how to implement a RemoteLaunch application, we'll make a simple RemoteLaunch example that sends a context containing two parameters to a WorkflowGen process: AMOUNT and NAME. This process will be launched with these two parameters.

Reference

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.
1
using WorkflowGen.My.Data;
Copied!

Defining the Page_Load event

We'll use the Page_Load event to immediately start the remote process. Here is the basic code structure we are going to use for the RemoteLaunch SDK application:
1
protected void Page_Load(object sender, EventArgs e)
2
{
3
// Call the main function
4
RemoteProcessLaunch();
5
}
6
7
/// <summary>
8
/// RemoteProcessLaunch
9
/// </summary>
10
private void RemoteProcessLaunch()
11
{
12
...
13
}
Copied!

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. The advantage to this is that if you modify the name of the process to launch, or the username of the launching user, or any other configurations, you will not have to change your code-behind files, only your web.config file, without recompiling the web application. Here are the web.config values that we'll use:
1
<appSettings>
2
<add key="WorkflowGenLaunchUrl" value="http://localhost/wfgen/show.aspx?QUERY=PROCESS_START_REMOTE"/>
3
<add key="WorkflowGenUsername" value="wfgen_admin"/>
4
<add key="WorkflowgenUserPassword" value="Advantys123"/>
5
<add key="WorkflowGenUserDomain" value=""/>
6
<add key="ProcessName" value="SDK_CS_REMOTE_LAUNCH"/>
7
<add key="Language" value="en-US"/>
8
<add key="RequesterUsername" value="wfgen_admin"/>
9
<add key="Test" value="Y"/>
10
</appSettings>
Copied!
The following code declares all the variables we need for the RemoteLaunch, then gets the web.config values to populate some of these variables.
1
// Variables Declaration
2
System.Net.HttpWebRequest httpWebReq = null; // Http web request object
3
System.Net.HttpWebResponse httpWebResp = null; // Http web response object
4
System.Net.NetworkCredential myCred = null; // To hold credential information
5
System.Net.CredentialCache myCache = null; // credential cache
6
System.Text.ASCIIEncoding encoding = null; // for encoding
7
System.IO.Stream myStream = null; // To get request data
8
System.IO.StreamReader myReader = null; // To read response stream
9
string respCode; // string used to get response status code
10
string workflowContextXml; // string to get the xml context data
11
string appUrl = string.Empty; // string used to Approval URL
12
string postData = null; // string used to put the data for request
13
string response = null; // string used to display response
14
byte[] buffer; // byte used to get the encoded data
15
16
// Get values into Configuration constants
17
// Get the Launch URL
18
workflowGenLaunchUrl = ConfigurationManager.AppSettings["WorkflowGenLaunchUrl"].ToString();
19
20
// Get the WorkflowGen user username
21
workflowGenUsername = ConfigurationManager.AppSettings["WorkflowGenUsername"].ToString();
22
23
// Get the WorkflowGen user password
24
workflowgenUserPassword = ConfigurationManager.AppSettings["WorkflowgenUserPassword"].ToString();
25
26
// Get the WorkflowGen user domain
27
workflowGenUserDomain = ConfigurationManager.AppSettings["WorkflowGenUserDomain"].ToString();
28
29
// Get the process name
30
processName = ConfigurationManager.AppSettings["ProcessName"].ToString();
31
32
// Get the culture information
33
language = ConfigurationManager.AppSettings["Language"].ToString();
34
35
// Get the requester name, default is wfgen_admin
36
requesterUsername = ConfigurationManager.AppSettings["RequesterUsername"].ToString();
37
38
// Get the launch test mode status
39
test = Convert.ToChar(ConfigurationManager.AppSettings["Test"].ToString());
Copied!

Building a context from scratch

We now need to build a new context to send to WorkflowGen, to start the new process that needs two parameters: AMOUNT and NAME, which are numeric and text parameters, respectively. Here is the necessary code to create a new context:
1
// Create a new WorkflowGen object for context parameters
2
WorkflowGen.My.Data.ContextParameters myWorkflowContextParameters = new
3
WorkflowGen.My.Data.ContextParameters();
4
5
// Create a new AMOUNT context parameter object
6
WorkflowGen.My.Data.ContextParameter contextParamAmount = new
7
WorkflowGen.My.Data.ContextParameter();
8
9
// Set the parameter name
10
contextParamAmount.Name = "AMOUNT";
11
12
// Set the direction for the parameter
13
contextParamAmount.Direction = WorkflowGen.My.Data.ContextParameter.Directions.In;
14
15
// Set parameter type as double
16
contextParamAmount.Type = typeof(double);
17
18
// Set parameter value
19
contextParamAmount.Value = Convert.ToDouble(10000);
20
21
// Adding the parameter to the context parameters
22
myWorkflowContextParameters.Add(contextParamAmount);
23
24
// Updating the context parameters
25
myWorkflowContextParameters.Update();
26
WorkflowGen.My.Data.ContextParameter contextParamName = new
27
WorkflowGen.My.Data.ContextParameter();
28
29
// Set the parameter name
30
contextParamName.Name = "NAME";
31
32
// Set the direction for the parameter
33
contextParamName.Direction = WorkflowGen.My.Data.ContextParameter.Directions.In;
34
35
// Set parameter type as string
36
contextParamName.Type = typeof(string);
37
38
// Set parameter value
39
contextParamName.Value = "SDK SAMPLE TEXT";
40
41
// Adding the parameter to the context parameters
42
myWorkflowContextParameters.Add(contextParamName);
43
44
// Updating the context parameters
45
myWorkflowContextParameters.Update();
46
47
// Get the xml context data into variable
48
workflowContextXml = myWorkflowContextParameters.GetXml();
Copied!

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:
1
// Call WorkflowGen to instantiate the process
2
// Prepare the URL
3
appUrl = workflowGenLaunchUrl + "&L=" + language + "&PROCESS=" + processName + "&REQUESTER_USERNAME=" + requesterUsername + "&TEST=" + test;
4
5
// Submit the parameters
6
myCred = new System.Net.NetworkCredential(workflowGenUsername,workflowgenUserPassword, workflowGenUserDomain);
7
myCache = new System.Net.CredentialCache();
8
myCache.Add(new Uri(workflowGenLaunchUrl), "Basic", myCred);
9
10
// Prepare a request
11
httpWebReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(appUrl);
12
httpWebReq.Method = "POST";
13
14
// Set authentication information
15
httpWebReq.Credentials = myCache;
16
17
// Set CONTEXT content
18
postData = "CONTEXT=" + HttpUtility.UrlEncode(workflowContextXml.ToString());
19
encoding = new System.Text.ASCIIEncoding();
20
buffer = encoding.GetBytes(postData);
21
22
// Set the content type of the data being posted.
23
httpWebReq.ContentType = "application/x-www-form-urlencoded";
24
25
// Set the content length of the string being posted.
26
httpWebReq.ContentLength = postData.Length;
27
28
// Send the CONTEXT
29
myStream = httpWebReq.GetRequestStream();
30
myStream.Write(buffer, 0, buffer.Length);
31
32
// Close the Stream object.
33
myStream.Close();
Copied!

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:
1
// Try block to handle exception
2
try
3
{
4
// Check the WorkflowGen response status
5
httpWebResp = (System.Net.HttpWebResponse)httpWebReq.GetResponse();
6
}
7
// Catch the exception
8
catch (WebException e)
9
{
10
// Display the error message
11
Response.Write(e.ToString());
12
return;
13
}
14
15
respCode = "OK"; // response code variable
16
17
// Check the response status code is OK
18
if (respCode != httpWebResp.StatusCode.ToString())
19
{
20
// Display the Error details
21
Response.Write("Error:" + httpWebResp.StatusCode);
22
}
23
else
24
{
25
// Gets the stream associated with the response
26
httpWebResp = (System.Net.HttpWebResponse)httpWebReq.GetResponse();
27
myReader = new System.IO.StreamReader(httpWebResp.GetResponseStream());
28
response = myReader.ReadToEnd();
29
httpWebResp.Close();
30
31
// Display response message
32
Response.Write(response);
33
}
Copied!
Last modified 10mo ago