Workflow WCF Services Samples
This topic contains some sample code showing how to interact with the workflow WCF Web Service.
These samples assume that you have added a project reference called
WorkflowRuntimeWCFService
to your project, which points to the URL of the workflow WCF web service, something similar to http://[k2server]/K2Services/WCF.svc
Starting a new workflow with the WCF web service
WorkflowRuntimeWCFService.ProcessNavigationServiceClient SvcWorklist = new WorkflowRuntimeWCFService.ProcessNavigationServiceClient(); //instantiate a process instance object and set the properties/values WorkflowRuntimeWCFService.ProcessInstance K2ProcInst = new ProcessInstance(); K2ProcInst.FullName = @"projectname\workflowname"; K2ProcInst.Folio = "some Folio value"; //to set datafields, is a List<> collection and then convert it to an array
//set up the collection of datafields
List<DataField> dataFieldsCollection = new List<DataField>(); //string field example dataFieldsCollection.Add(new DataField() { Name = "FieldName", Value = "FieldValue"}); //dates require special massaging, otherwise you get XMLAny errors. In this sample we’ll take the current date
//note the use of the XmlConvert function. You may need to do this with other datafields, too. dataFieldsCollection.Add(new DataField() { Name = "FieldName", Value = XmlConvert.ToString(DateTime.Now,XmlDateTimeSerializationMode.Local)}); //pass the collection to datafields into the workflow K2ProcInst.DataField = dataFieldsCollection.ToArray(); //start the workflow (setting one datafield parameter to true since we added datafields to the process instance) SvcWorklist.StartNewProcessInstance(K2ProcInst, false, false, false, true, false);
Retrieving the worklist with the WCF web service
WorkflowRuntimeWCFService.WorklistNavigationServiceClient SvcWorklist = new WorkflowRuntimeWCFService.WorklistNavigationServiceClient(); WorklistItem[] K2WorklistItems = SvcWorklist.OpenWorklist(false, false, false, false); //iterate over the collection of worklist items
foreach (WorklistItem K2WorklistItem in K2WorklistItems) { //Do something with the worklist item }
Opening and completing worklist item using the WCF web service
WorkflowRuntimeWCFService.WorklistNavigationServiceClient SvcWorklist = new WorkflowRuntimeWCFService.WorklistNavigationServiceClient(); WorklistItem[] K2WorklistItems = SvcWorklist.OpenWorklist(false, false, false, false); //iterate over the collection of worklist items
foreach (WorklistItem K2WorklistItem in K2WorklistItems) { //Do something with the worklist item }