How to invoke a WorkflowGen API using .NET code

#1

Note: APIs are only available as of WorkflowGen version 5.1.

Before invoking a WorkflowGen API using .NET code, first verify that you have access to the APIs by doing the following:

  1. Open a new web browser (Internet Explorer or Firefox).
  2. Connect to your web service with your WorkflowGen URL: http://yourserver:port/wfgen/ws/ProcessesRuntime.asmx.
  3. Authenticate with your WorkflowGen account.
  4. The above URL will provide you with a list of available web service APIs.

Use the sample code below to invoke a web service API from within your code. This example demonstrates how to call the CompleteActivityInstance API, which is used to complete an open action.

Prior to implementing the code below, do the following:

  1. Open your existing web project (or create a new web project) for which you would like to implement the API web service call.
  2. Add a web reference to your website by performing the following steps:
    1. In Visual Studio, choose Website > Add Web Reference...
    2. Enter the web service URL (http://yourserver:port/wfgen/ws/ProcessesRuntime.asmx) and click Add Reference. You will likely be prompted by the server to authenticate your request. Enter the appropriate username, password, and domain (if necessary). Once submitted, you should see the same screen as when you verified your access to the APIs, with a list of available APIs.
    3. You will be prompted to give the web reference a name. The sample below uses the web reference name WFG_APIs.
    4. Click Add reference. You should now see the reference within your Solution Explorer.
  3. Add the following code, or incorporate the code into your existing code as required:

Language: C#

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WorkflowGen.My.Web.UI.WebForms;
using WorkflowGen.My.Data;
using System.Net;

 
public partial class _Default : WorkflowPage
{

   private WFG_APIs.RuntimeService wsAPI;

   protected void Page_Load(object sender, EventArgs e)
   {

   }

 
   protected void Button1_Click(object sender, EventArgs e)
   {

      string workflowContextXml; // string to get the xml context data

      // Create a new WorkflowGen object for context parameters
      WorkflowGen.My.Data.ContextParameters myWorkflowContextParameters = new WorkflowGen.My.Data.ContextParameters();

 
      // Get the xml context data into variable
      workflowContextXml = myWorkflowContextParameters.GetXml();

      // ID of the request to cancel
      string RequestID = "1374"

      //ID of the activity to cancel (Current Action ID) 
      string ActivityID = "4"

      wsAPI = new WFG_APIs.RuntimeService();

      wsAPI.Credentials = new NetworkCredential("USERNAME", "PASSWORD","");

      try
      {
            wsAPI.CompleteActivityInstance(Convert.ToInt16(RequestID), Convert.ToInt16(ActivityID), workflowContextXml.ToString());
            Response.Write("OK – Action Completed");
      }
      catch (Exception exN)
      {
             Response.Write("Error = " + exN.Message.ToString() + exN.StackTrace.ToString());
      }
      
   }

}
0 Likes

Web Services API
Having Trouble Integrating Web API Based on Sample Code