Wednesday, June 04, 2008 9:08 AM
nicholas.kotze@k2workflow.com
Connection via the API to the K2 Server
There are many ways to connect to the K2 Server which all vary depending on what you want to do. I found myself in a situation where I need to create a connection as a particular user and the usual way to connect to the K2 Server (as seen at the end of this post) was giving authentication issues. Remember, I am talking about making a connection to the K2 Server (default port 5252) and NOT the SmartObject server (default port 5555).
Here is the good way to connect that worked:
ConnectionSetup consetup = new ConnectionSetup();
consetup.ConnectionString = "DOMAIN,USER,PASSWORD";
conn.Open(consetup);
I dug around on the K2 Underground and found some addition code around the ConnectionSetup object for alternative ways to connect to the K2 Server, and found the following:
using (Connection K2Con = new Connection())
{
ConnectionSetup K2ConSetup = new ConnectionSetup()
K2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Host, ConfigurationManager.AppSettings["K2Server"]);
K2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.TimeOut, ConfigurationManager.AppSettings["K2ConnTimeOut"]);
//Open a connection to the K2[blackpearl] server
K2Con.Open(K2ConSetup);
K2Con.ImpersonateUser(Profile.GetValue(
"WindowsLogin"));
nameLabel.Text = K2Con.User.Name;
Worklist K2WorkList = K2Con.OpenWorklist("ASP");
K2Con.RevertUser();
... more code
K2Con.Close()
}
Other connection options include:
SourceCode.Workflow.Client.Connection conn = new SourceCode.Workflow.Client.Connection();
conn.Open("[HOST]");
//or if you wish to open the connection as a specfic user replace conn.Open("[HOST]") with:
conn.Open("[HOST]", "[DOMAIN], [USER], [PASSWORD");
I am confident that using one of the methods above you will successfully be able to connect to the K2 Server.