2013-08-13 3 views
0

나는 Secure Store에 문제가 있습니다. 내가 배포하거나 IISRESET을 수행 할 때, 내 보안 저장소는 몇 시간 동안 작동하지만 다음 보안 저장소 죽는다, 나는 오류 아래 얻을 : 여기 요구하고 왜보안 저장소 .... EndpointNotFoundException : Secure Store Service가 작업을 수행하지 못했습니다.

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) 

나는 선택의 여지 실행하고, 그건.

는 이미 ... 널링 개체로 보았다 내가 여기 읽을 것과 같은 .. http://davidlozzi.com/tag/secure-store-service/ 여기

내 보안 저장소 자격 증명을 검색하는 내 코드입니다

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

아래 코드를 참조하십시오. 우리는 수개월 동안 문제없이 백 엔드 타이머 작업과 프런트 엔드 용도에서이 코드를 사용합니다.

자격 증명을 요청할 때마다 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); 
     } 
    } 
}