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.

The .asmx service is intended for support of legacy protocols or platform that cannot consume WCF-based services. It is not as extensive as the WCF/REST based services and will not be extended with additional functionality in future releases of K2

URI – Service Description

{Service Root URI}?wsdl
http://api.denallix.com:81/K2Services/WCF.asmx?wsdl

WS Methods

The following operations are supported by the WS.asmx endpoint.

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=FalsemaxWorklistItems=0processDataFields=TrueprocessXmlFields=TrueactivityDataFields=FalseactivityXMLFields=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;
							}
							}