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.
This integration is not supported when using OpenID Connect authentication methods (Azure, AD FS, Auth0, Okta). Alternative solutions would be to use a GraphQL API request with a server-side script or to use webhooks.
See the following documentation for instructions on how to configure each method for server-side scripts:
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
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\sdk\MyRemoteLaunch.
Right-click on MyRemoteLaunch and choose Convert to Application.
Select the application pool used by your site and another specific application pool.
Click OK.
Creating the project with Visual Studio
Creating the project
Open Visual Studio.
Select File > New Web Site.
Choose ASP.NET Empty 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
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:
Make sure this line is set to "true":
<compilation debug="true" />
Make sure this is not commented and that the mode="Off":
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.
C#
usingWorkflowGen.My.Data;
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:
C#
protectedvoidPage_Load(object sender,EventArgs e){ // Call the main functionRemoteProcessLaunch();}/// <summary>/// RemoteProcessLaunch/// </summary>privatevoidRemoteProcessLaunch(){...}
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:
The following code declares all the variables we need for the RemoteLaunch, then gets the web.config values to populate some of these variables.
C#
// Variables DeclarationSystem.Net.HttpWebRequest httpWebReq =null; // Http web request objectSystem.Net.HttpWebResponse httpWebResp =null; // Http web response objectSystem.Net.NetworkCredential myCred =null; // To hold credential informationSystem.Net.CredentialCache myCache =null; // credential cacheSystem.Text.ASCIIEncoding encoding =null; // for encodingSystem.IO.Stream myStream =null; // To get request dataSystem.IO.StreamReader myReader =null; // To read response streamstring respCode; // string used to get response status codestring workflowContextXml; // string to get the xml context datastring appUrl =string.Empty; // string used to Approval URLstring postData =null; // string used to put the data for requeststring response =null; // string used to display responsebyte[] buffer; // byte used to get the encoded data// Get values into Configuration constants// Get the Launch URLworkflowGenLaunchUrl =ConfigurationManager.AppSettings["WorkflowGenLaunchUrl"].ToString();// Get the WorkflowGen user usernameworkflowGenUsername =ConfigurationManager.AppSettings["WorkflowGenUsername"].ToString();// Get the WorkflowGen user passwordworkflowgenUserPassword =ConfigurationManager.AppSettings["WorkflowgenUserPassword"].ToString();// Get the WorkflowGen user domainworkflowGenUserDomain =ConfigurationManager.AppSettings["WorkflowGenUserDomain"].ToString();// Get the process nameprocessName =ConfigurationManager.AppSettings["ProcessName"].ToString();// Get the culture informationlanguage =ConfigurationManager.AppSettings["Language"].ToString();// Get the requester name, default is wfgen_adminrequesterUsername =ConfigurationManager.AppSettings["RequesterUsername"].ToString();// Get the launch test mode statustest =Convert.ToChar(ConfigurationManager.AppSettings["Test"].ToString());
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:
C#
// Create a new WorkflowGen object for context parametersWorkflowGen.My.Data.ContextParameters myWorkflowContextParameters =newWorkflowGen.My.Data.ContextParameters();// Create a new AMOUNT context parameter objectWorkflowGen.My.Data.ContextParameter contextParamAmount = newWorkflowGen.My.Data.ContextParameter();// Set the parameter namecontextParamAmount.Name = "AMOUNT";// Set the direction for the parametercontextParamAmount.Direction = WorkflowGen.My.Data.ContextParameter.Directions.In;// Set parameter type as doublecontextParamAmount.Type = typeof(double);// Set parameter valuecontextParamAmount.Value = Convert.ToDouble(10000);// Adding the parameter to the context parametersmyWorkflowContextParameters.Add(contextParamAmount);// Updating the context parametersmyWorkflowContextParameters.Update();WorkflowGen.My.Data.ContextParameter contextParamName = newWorkflowGen.My.Data.ContextParameter();// Set the parameter namecontextParamName.Name = "NAME";// Set the direction for the parametercontextParamName.Direction = WorkflowGen.My.Data.ContextParameter.Directions.In;// Set parameter type as stringcontextParamName.Type = typeof(string);// Set parameter valuecontextParamName.Value = "SDK SAMPLE TEXT";// Adding the parameter to the context parametersmyWorkflowContextParameters.Add(contextParamName);// Updating the context parametersmyWorkflowContextParameters.Update();// Get the xml context data into variableworkflowContextXml = myWorkflowContextParameters.GetXml();
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#
// Call WorkflowGen to instantiate the process// Prepare the URLappUrl = workflowGenLaunchUrl + "&L=" + language + "&PROCESS=" + processName + "&REQUESTER_USERNAME=" + requesterUsername + "&TEST=" + test;
// Submit the parametersmyCred =newSystem.Net.NetworkCredential(workflowGenUsername,workflowgenUserPassword, workflowGenUserDomain);myCache =newSystem.Net.CredentialCache();myCache.Add(newUri(workflowGenLaunchUrl),"Basic", myCred);// Prepare a requesthttpWebReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(appUrl);httpWebReq.Method="POST";// Set authentication informationhttpWebReq.Credentials= myCache;// Set CONTEXT contentpostData ="CONTEXT="+HttpUtility.UrlEncode(workflowContextXml.ToString());encoding =newSystem.Text.ASCIIEncoding();buffer =encoding.GetBytes(postData);// Set the content type of the data being posted.httpWebReq.ContentType="application/x-www-form-urlencoded";// Set the content length of the string being posted.httpWebReq.ContentLength=postData.Length;// Send the CONTEXTmyStream =httpWebReq.GetRequestStream();myStream.Write(buffer,0,buffer.Length);// Close the Stream object.myStream.Close();
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#
// Try block to handle exceptiontry{ // Check the WorkflowGen response status httpWebResp = (System.Net.HttpWebResponse)httpWebReq.GetResponse();}// Catch the exceptioncatch (WebException e){ // Display the error messageResponse.Write(e.ToString());return;}respCode ="OK"; // response code variable// Check the response status code is OKif (respCode !=httpWebResp.StatusCode.ToString()){ // Display the Error detailsResponse.Write("Error:"+httpWebResp.StatusCode);}else{ // Gets the stream associated with the response httpWebResp = (System.Net.HttpWebResponse)httpWebReq.GetResponse(); myReader =newSystem.IO.StreamReader(httpWebResp.GetResponseStream()); response =myReader.ReadToEnd();httpWebResp.Close(); // Display response messageResponse.Write(response);}