Workflow asmx Web Service Samples
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();
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
ProcessInstance K2ProcInst = new ProcessInstance();
K2ProcInst.FullName = @ "[ProjectName]\[WorkflowName]";
K2ProcInst.Folio = "some folio value";
DataField[] K2Datafields = K2ProcInst.DataField;
foreach(DataField K2DataField in K2Datafields) {
K2DataField.Value = "some field value";
}
client.StartNewProcessInstance(ref K2ProcInst, false);
Retrieving the worklist
WorkflowRuntimeAsmxService.WSSoapClient client = new WSSoapClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
WorklistItem[] K2worklist = client.OpenWorklist(false);
foreach(WorklistItem K2WLItem in K2worklist) {
string Folio = K2WLItem.ProcessInstance.Folio;
}
Opening and completing worklist item
WorkflowRuntimeAsmxService.WSSoapClient client = new WSSoapClient();
client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Delegation;
WorklistItem K2WorklistItem = client.OpenWorklistItem("[serialNumber]", false);
K2WorklistItem.ProcessInstance.Folio = "[updated Folio value]";
DataField[] K2Datafields = K2WorklistItem.ProcessInstance.DataField;
foreach(DataField K2DataField in K2Datafields) {
K2DataField.Value = "[some updated field value]";
}
client.ExecuteActionByWorklistItem(K2WorklistItem, "[ActionName]", false);
client.ExecuteActionBySerial("serialNumber", "[ActionName]", false);