Using the credential management dll from a WCF REST service

Feb 25, 2014 at 12:17 PM
Edited Feb 25, 2014 at 12:34 PM
I am trying to consume the Credential management dll from a WCF REST service which is hosted via Windows Service. Just trying in a developer machine, the OS is windows 7 and later on i want to host in a Server OS.

The Credential class object creation and other properties code is as below.
  Credential cred = new Credential("", "", "some-target", CredentialType.Generic);

            if (cred.Load() == false)
            {
                cred.Username = userName;
                cred.Password = passWord;
                cred.PersistanceType = PersistanceType.Session;
                cred.Type = CredentialType.Generic;
                cred.Target = "some-target";
                cred.Save();
            }
In this code, the the save call succeeding, but i could not see any change in the windows vault/credential manager of control panel. When i read the credentials with the same target name, it is returning the previously stored credentials.
So, i understood that it is storing the credentials in somewhere other than windows Vault.
-Is my understanding of storing the credentials in credential manager available in control panel is wrong ?
-Or is it storing the credential somewhere else than the local credential manager?
-Really is it storing somewhere in the machine ?
Please provide me some some information to solve this issue.

Thanks in advance.

-Kiran
Coordinator
Apr 15, 2014 at 9:43 PM
Kiran,

How is this service hosted?
If it is hosted through IIS then most likely the credentials are going to be stored with the account that is used to host the WCF service.
Just as a quick test, try to set the account used to host the WCF service as your own account on that developer system and see if the credentials start showing up in Credential Manager.
Hopefully this helps.
Jan 2, 2015 at 10:31 AM
Kiran, Any solution about it?
Jan 22, 2016 at 11:31 AM
Hi,

i'm had a similar very easy code.

just
public static UserCredentials GetCredentials(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return new UserCredentials
                {
                    Exists = false
                };
            }
            TraceSource.TraceInformation("try get credentials with name {3} for {0}\\{1} on {2}", Environment.UserDomainName, Environment.UserName, Environment.MachineName,name);
            Credential credential = new Credential {Target = name};
            if (credential.Exists())
            {
                credential.Load();
            }
            return new UserCredentials
            {
                Exists = credential.Exists(),
                UserName = credential.Username,
                Password = credential.Password,
                CredentialStoreName = name
            };
        }
this works fine from a console application, but not from MVC Application hosted on an iis.
The applicationpool identity was set to my account.