You are viewing limited content. For full access, please sign in.

Question

Question

Unable to start workflows using the Workflow Web Service

asked on November 24, 2015 Show version history

I'm developing a simple web console that a user can use to start workflows. I have a simple web server that listens for incoming requests and starts the workflow.

This WFSO code works:

using System.Collections.Generic;
using System.Web.Mvc;
using Laserfiche.Workflow;
using Laserfiche.Workflow.Objects;

namespace WFWeb.Controllers
{
    public class WorkflowController : Controller
    {
        //
        // GET: /Workflow/RunWF/5
        public void RunWF(int id)
        {
            string workflowServer = "localhost";
            string workflowApplication = "My App";
            using (WorkflowConnection connection = WorkflowConnection.CreateConnection(workflowServer, workflowApplication))
            {
                string workflowName = "Test WF";
                Database database = connection.Database;
                PublishedWorkflow workflow = database.GetPublishedWorkflow(workflowName);
                string ruleName = "My Rule";
                StartingEntry entry = null;
                Initiator initiator = null;
                WorkflowCreationOptions options = null;
                Dictionary<string, string> parameters = new Dictionary<string, string>
                {
                    { "workflowID", id.ToString() }
                };
                workflow.StartWorkflow(ruleName, entry, initiator, options, parameters);
            }
        }
    }
}

This WorkflowRestAPI code doesn't:

using System.Web.Mvc;
using WFWeb.WorkflowRestAPI;

namespace WFWeb.Controllers
{
    public class WorkflowController : Controller
    {
        //
        // GET: /Workflow/RunWF/5
        public void RunWF(int id)
        {
            using (WorkflowAPIBaseClient WorkflowService = new WorkflowAPIBaseClient())
            {
                InstanceCreationData creationData = new InstanceCreationData();
                creationData.StartingEntry = new InstanceEntryData();
                creationData.Initiator = new InstanceUserData();
                creationData.Initiator.InitiatorName = "Admin";

                InstanceParameterData firstName = new InstanceParameterData();
                creationData.ParameterCollection = new InstanceParameterCollection();
                creationData.ParameterCollection.Add(firstName);
                creationData.RuleName = "My Rule";
                string workflowName = "Test WF";

                InstanceCreationResultData results = WorkflowService.CreateWorkflowInstance(workflowName, creationData);
                string instanceID = results.instanceId;
                string fault = results.fault != null ? results.fault.Detail : string.Empty;

            }
        }
    }
}

Nothing happens and there are no errors reported anywhere.

I also tried to send a POST request directly to http://localhost:81/Workflow/api/instances/{WORKFLOWNAME} with a JSON body containing the example data located at /Workflow/api/help/operations/CreateWorkflowInstance, but kept getting "Bad Request" and gave up. That would be my ideal approach, since Workflow already has a web service and all I need is to start a workflow, so if anyone has thoughts I'm all ears. smiley

1 0

Answer

SELECTED ANSWER
replied on November 25, 2015

This seems to be working now... the only change I made was to give the firstName InstanceParameterData object a name and a value. I hope this helps someone. smiley

2 0

Replies

replied on July 8, 2020

I would have appreciated a response to this question. It seems like a valid question

0 1
You are not allowed to follow up in this post.

Sign in to reply to this post.