【问题标题】:How to use X509Certificate2 as the credentials for a SharePointService request如何使用 X509Certificate2 作为 SharePointService 请求的凭据
【发布时间】:2011-06-02 09:35:06
【问题描述】:

我有一个需要客户端证书才能访问的 MOSS 2007 场。我编写了几种使用内置 SharePoint 服务从站点检索数据的方法。但是,在我的本地测试环境之外,一切都需要客户端证书才能访问服务。

我获取证书的方法是:

private static X509Certificate2 GetCertCreds()
{
     X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
     try
     {
         store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectKeyIdentifier, "SiteIdentityCertificateSerialNumber", true);

         Assert.IsNotNull(certs);

         return certs[0];
     }
     finally
     {
          store.Close();
     }
}

然后在使用中我必须有一些喜欢的东西:

using (ListsServiceProxy.Lists service = new ListsServiceProxy.Lists())
{
    service.Crendentials = GetCredentials();
    XmlNode idResultsNode = service.GetListItems(documentLibraryName, null, queryNode, viewNode, "1", optionNode, null);
}

由于类型不匹配,无法编译。我会以错误的方式解决这个问题吗?如果没有,有没有办法将证书用作服务凭证?我认为最终我要做的是将 X509Certificate2 转换为 ICredentials。任何帮助或建议将不胜感激。

【问题讨论】:

    标签: sharepoint service x509certificate2


    【解决方案1】:

    原来我错了。为了正确地做到这一点,我替换了:

    service.Credentials = GetCertCreds()

    service.ClientCertificates.Add(GetCretCreds());

    只需将证书添加到服务的客户端证书集合中即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-16
      • 2019-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 2018-08-30
      • 1970-01-01
      相关资源
      最近更新 更多