我遇到了Secure Store的问题。当我部署或执行IISRESET时,我的Secure Store可以工作几个小时,但随后Secure Store Dies,我得到以下错误:
System.ServiceModel.EndpointNotFoundException: Secure Store Service did not
performed the operation.
System.ServiceModel.EndpointNotFoundException: Secure Store Service did not
performed the operation. at Microsoft.Office.SecureStoreService.Server.
SecureStoreServiceApplicationProxy.Execute[T](String operationName, Boolean
validateCanary, ExecuteDelegate`1 operation) at icrosoft.Office.SecureStoreService.
Server.SecureStoreServiceApplicationProxy.GetCredentials(Guid rawPartitionId,
String applicationId) at
Microsoft.Office.SecureStoreService.Server.SecureStoreProvider.
GetCredentials(String appId)
我的选项已经用完了,这就是我在这里问的原因。
我已经研究过Nulling对象......就像我在这里读到的那样:http://davidlozzi.com/tag/secure-store-service/
以下是我的代码,用于检索我的Secure Store凭据..
public static Dictionary<string, string> GetCredentials(string applicationID)
{
var credentialMap = new Dictionary<string, string>();
var serviceContext = SPServiceContext.Current;
var secureStoreProvider = new SecureStoreProvider { Context = serviceContext };
using (var credentials = secureStoreProvider.GetCredentials(applicationID))
{
var fields = secureStoreProvider.GetTargetApplicationFields(applicationID);
for (var i = 0; i < fields.Count; i++)
{
var field = fields[i];
var credential = credentials[i];
var decryptedCredential = ToClrString(credential.Credential);
credentialMap.Add(field.Name, decryptedCredential);
credentials[i].Dispose();
}
}
serviceContext = null;
secureStoreProvider = null;
return credentialMap;
}
..但它似乎也无效。
任何建议都会非常有帮助。谢谢!
答案 0 :(得分:0)
请参阅下面的代码 - 我们在我们的后端计时器作业和前端用例中使用它几个月没有问题。
唯一的区别似乎是每次请求凭据时重新创建SPServiceContext
。尝试不要重复使用当前上下文。
public class ExternalCredentialsRepository
{
private readonly string webUrl;
public ExternalCredentialsRepository(string webUrl)
{
this.webUrl = webUrl;
}
public NetworkCredential GetCredentials(string applicationId)
{
var credentialMap = new Dictionary<string, string>();
using (var site = new SPSite(webUrl))
{
var serviceContext = SPServiceContext.GetContext(site);
var secureStoreProvider = new SecureStoreProvider {Context = serviceContext};
using (var credentials = secureStoreProvider.GetCredentials(applicationId))
PopulateCredentialsMap(secureStoreProvider, credentials, applicationId, credentialMap);
}
string userName = credentialMap["Windows User Name"];
string domain = credentialMap["Windows Domain"];
string password = credentialMap["Windows Password"];
return new NetworkCredential(userName, password, domain);
}
private static void PopulateCredentialsMap(SecureStoreProvider secureStoreProvider, SecureStoreCredentialCollection credentials, string applicationId, Dictionary<string, string> credentialMap)
{
var fields = secureStoreProvider.GetTargetApplicationFields(applicationId);
for (var i = 0; i < fields.Count; i++)
{
var field = fields[i];
var credential = credentials[i];
var decryptedCredential = ExtractString(credential.Credential);
credentialMap.Add(field.Name, decryptedCredential);
}
}
private static string ExtractString(SecureString secureString)
{
var ptr = Marshal.SecureStringToBSTR(secureString);
try
{
return Marshal.PtrToStringBSTR(ptr);
}
finally
{
Marshal.FreeBSTR(ptr);
}
}
}