Web Services
K2 Services provide legacy SOAP Web service (WS) endpoints for a portion of the SourceCode.Workflow.Client APIs. Developers familiar with using the SourceCode.Workflow.Client APIs as locally referenced resources will be immediately productive accessing these same resources via WS endpoints.
The SourceCode.Workflow.Client Namespace documentation contains information on the underlying classes, properties, methods and sample code. Reference this namespace when utilizing the WS endpoints.
Detailed information on service contracts, data contracts and operation contracts can be found in the endpoint Service Descriptions.
URI – Service Description
{Service Root URI}?wsdl
http://api.denallix.com:81/K2Services/WCF.asmx?wsdl
- Service Root URI = {Scheme}{Server}:{Port}{Service Root}
-
- Scheme = http:// or https:// if SSL is enabled (default)
- Server = Server or Host Name of web site hosting K2 services
- Port = Port of web site hosting K2 Services
- Service Root = Virtual directory and service endpoint exposed by K2 Services. The values for Service Root are configurable. The defaults is:
-
- /K2Services/WS.asmx
WS Methods
The following operations are supported by the WS.asmx endpoint.
- ExecuteActionBySerial
- ExecuteActionByWorklistItem
- OpenProcessInstance
- OpenWorklist
- OpenWorklistItem
- ReleaseWorklistItem
- StartNewProcessInstance
- StartNewProcessInstanceScalar
- UpdateProcessInstance
Accessing Datafields returned by the WebService
The WS.asmx WebService consumes Datafields differenlty from the standard K2 API usage. For instance, in the satandard K2 API one can access the Datafield like this:
Datafield x = processInstance.Datafields[“MyDatafield”];
As WebServices maps everything as array objects it is not possible to follow the normal K2 API usage. The following example code demonstrates how to access the contents of a Datafield that has been returned using the WebService:
WSServiceWorklistItem item = client.OpenWorklistItem(serialNumber, true); item.ProcessInstance.DataField.GetDataFieldByName("MyValue").Value = "New DataField Value"; public static class ExtensionMethods { public static WSService.DataField GetDataFieldByName(this WSService.DataField[] dataFields, string name) { foreach (WSServiceDataField dataField in dataFields) { if (string.Equals(dataField.Name, name, StringComparison.OrdinalIgnoreCase)) { return dataField; } } return null; } }
Populating Datafields or XMLFields
To enable Datafields/XMLfields to be populated, the settings in the web.config located in the K2Services folder needs to be changed:
<inclusions userExtendedProperties=”False” hiddenFields=”False” maxWorklistItems=”0” processDataFields=”True” processXmlFields=”True” activityDataFields=”False” activityXMLFields=”False”>
Accessing Datafields by Name
Default Webservice behavior will cause a 'collection' call to be changed to an 'array object'. Therefore one cannot simply use the Webservice to return Datafields by name. The work around for accessing a Datafield by name is to create a custom extension method to handle the collection. The following sample code is an example custom extension to handle this situation:
WSServiceWorklistItem item = client.OpenWorklistItem(serialNumber, true);
item.ProcessInstance.DataField.GetDataFieldByName("MyValue").Value = "New DataField Value";
public static class ExtensionMethods
{
public static WSService.DataField GetDataFieldByName(this WSService.DataField[] dataFields, string name)
{
foreach (WSServiceDataField dataField in dataFields)
{
if (string.Equals(dataField.Name, name, StringComparison.OrdinalIgnoreCase))
{
return dataField;
}
}
return null;
}
}