Connect to the Core Server as a different user if you do not want to connect as the currently logged-on user. This requires you to provide a password, or for your current user to have impersonation rights.
Procedure
- If your current user does not have impersonation rights, connect another user by using the following code:
using (ChannelFactory<ISessionAwareCoreService> factory =
new ChannelFactory<ISessionAwareCoreService>("netTcp_2011"))
{
NetworkCredential networkCredential =
new NetworkCredential("username", "password", "domain");
factory.Credentials.Windows.ClientCredential = networkCredential;
ISessionAwareCoreService client = factory.CreateChannel();
Console.WriteLine(client.GetCurrentUser().Title);
}
where domain is the domain that contains the user you want to connect to the Core Service, user is the name of that user, and password is that user's password.
- Alternatively, if the current user does have impersonation rights, you can also connect another user as follows:
using (ChannelFactory<ISessionAwareCoreService> factory =
new ChannelFactory<ISessionAwareCoreService>("netTcp_2011"))
{
ISessionAwareCoreService client = factory.CreateChannel();
client.Impersonate(@"domain\user");
Console.WriteLine(client.GetCurrentUser().Title);
}
where domain is the domain that contains the user you want to connect to the Core Service and user is the name of that user.