Configuring the K2 REST Services for use with K2 SQL User Manager
K2 REST services are setup to use the Active Directory User Manager by default. Use the following steps to enable K2 REST Services with K2 SQL User Manager (SQLUM):
-
Change the security label in the <sourcecode.services> section of the WebServices web.config file to K2SQL.
This file is located in “%PROGRAMFILES%\K2\WebServices\K2Services\” -
In the HostServer.SecurityLabel table of the K2 databse, set the DefaultLabel to True for the K2SQL SecurityLabelName.
-
In your application, construct the CredentialCache for the HttpRequest header using the following code sample as an example:
string restServiceURL = "http://[K2Server]/K2Services/Rest.svc/worklist/Items";
string username = "[username]";
string password = "[password]";
//get the Worklist as a XML document
System.Xml.Linq.XDocument document = null;
try {
var request = (HttpWebRequest) WebRequest.Create(restServiceURL);
request.PreAuthenticate = true;
CredentialCache cache = new CredentialCache();
cache.Add(new Uri(restServiceURL), "Basic", new NetworkCredential(username, password));
request.Credentials = cache;
using(HttpWebResponse response = request.GetResponse() as HttpWebResponse) {
StreamReader reader = new StreamReader(response.GetResponseStream());
document = XDocument.Load(reader);
}
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}