Establishing a connection with the Workflow.Client class is the first step to perform workflow runtime interaction. The Connection object is the entry point for subsequent calls to the K2 server when using the Workflow Client assemblies, and once you have opened a connection, you can perform actions like retrieving worklists, completing worklist items or starting process instances.
Under the covers, the Connection object uses RPC calls to the K2 server to execute methods with a proprietary message format. By default, communication to the K2 server when using the Workflow Client API is via Port 5252, although you may have selected a different port when installing K2
The simplest way to open a connection is just to specify the K2 server name, in which case the connection to K2 will be established as the current Windows user account (so-called Integrated authentication). The code snippet below shows how to open and close a K2 connection in the simplest possible way, using the current user’s Active Directory credentials and opening a connection on the default 5252 port.
If you need to build up a more advanced connection (for example a different security provider, username or port) you can import the SourceCode.Hosting.Client namespace from the SourceCode.HostClientAPI.dll assembly and instantiate a ConnectionStringBuilder object to construct a more advanced connection string. This is especially important when you need to pass through alternative security credentials or are using a custom security provider to authenticate a non-Active Directory user account. The code snippet below illustrates how to build up a custom connection string and then open the connection as a user, using the K2 SQL User Manager authentication provider for authentication.
See the topic Connection String Samples for some more samples of typical connection strings.
Once the connection is open, the process instance can be accessed and used. Once the required interaction with a process has finished the connection must be closed using the connection.Close() method. The recommended approach is to use try{...} catch{...} finally{...} blocks or using{...} blocks to ensure that connections are closed once they are no longer needed. The code samples below illustrate some ways you can manage connections when using the Workflow Client classes.
Video | Links | Learn | Support |
No videos found for this article K2 on YouTube
No Additional links found for this article
No self-learning content for this article Try some scenarios...
No relevant support links available for this article
|