Workflow asmx Web Service Samples

This content applies to legacy components (such as K2 Studio and K2 for Visual Studio), legacy assemblies, legacy services or legacy functionality. If you have upgraded from K2 blackpearl 4.7 to K2 Five, these items may still be available in your environment. These legacy items may not be available in new installations of K2 Five. These legacy items may also not be available, supported, or behave as described, in future updates or versions of K2. Please see the legacy component support policy for more information about support for these components.

This topic contains some sample code showing how to interact with the workflow .asmx Web Service.

These samples assume that you have added a project reference called
WorkflowRuntimeAsmxService
to your project, which points to the URL of the workflow .asmx web service, something similar to http://[K2ServerName]/K2Services/ws.asmx

Starting a new workflow

WorkflowRuntimeAsmxService.WSSoapClient client = new WSSoapClient();

//NOTE: you have to set up credentials for the service call.
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;

//instantiate a process instance
ProcessInstance K2ProcInst = new ProcessInstance();

//Set the workflow to start by setting the process name value
K2ProcInst.FullName = @ "[ProjectName]\[WorkflowName]";

//set up the process instances values (Folio and Data fields)
K2ProcInst.Folio = "some folio value";
//get the defined datafields for the workflow
DataField[] K2Datafields = K2ProcInst.DataField;
//set up the data fields. In this case we will set each field value to the same value
foreach(DataField K2DataField in K2Datafields) {
 K2DataField.Value = "some field value";
}

//after setting up the workflow, start the new workflow instance
client.StartNewProcessInstance(ref K2ProcInst, false);

Retrieving the worklist

WorkflowRuntimeAsmxService.WSSoapClient client = new WSSoapClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;

//retrieve the worklist for the connected user
WorklistItem[] K2worklist = client.OpenWorklist(false);

//iterate over each worklist item
foreach(WorklistItem K2WLItem in K2worklist) {
 //do something with each worklist item, e.g. read the Folio
 string Folio = K2WLItem.ProcessInstance.Folio;
}

Opening and completing worklist item

WorkflowRuntimeAsmxService.WSSoapClient client = new WSSoapClient();

//NOTE: you have to set up credentials for the service call.
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;

//open a worklist item with a specific serial number
WorklistItem K2WorklistItem = client.OpenWorklistItem("[serialNumber]", false);

//update some properties of the worklist item/workflow
K2WorklistItem.ProcessInstance.Folio = "[updated Folio value]";

//get the defined datafields for the workflow
DataField[] K2Datafields = K2WorklistItem.ProcessInstance.DataField;

//set up the data fields. IN this case we will set each field"s value to the same value
foreach(DataField K2DataField in K2Datafields) {
 K2DataField.Value = "[some updated field value]";
}

//complete the worklist item with the specified Action
client.ExecuteActionByWorklistItem(K2WorklistItem, "[ActionName]", false);

//you can also complete the worklist item without setting data with the ExecuteActionBySerial method call
client.ExecuteActionBySerial("serialNumber", "[ActionName]", false);