【问题标题】:Why I can't find the certificate in a WCF Service?为什么我在 WCF 服务中找不到证书?
【发布时间】:2015-11-17 16:36:56
【问题描述】:

我正在尝试使用 WCF 开发服务,但找不到我创建的证书,该证书位于 TrustedPeple 文件夹下。到目前为止,这是我编写的代码块:

client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
            StoreLocation.CurrentUser,
            StoreName.My,
            X509FindType.FindBySubjectName,
            "WCfClient");

从上面的代码可以看出,我也试过手动设置证书特征,但还是找不到。

我还将发布我的 conif xml 文件的一部分以便更好地理解:

<services>

      <service 
        name="XMLServices.CriDecServices.CriDecService"
        behaviorConfiguration="wsHttpCertificateBehavior">
        <endpoint name="CriDecPoint"
          address=""
          binding="wsHttpBinding"
          bindingConfiguration="wsHttpEndpointBinding"
          contract="XMLContracts.ServiceContracts.ICriDecService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/XMLServices/CriDecServices/CriDecService" />
          </baseAddresses>
        </host>
        </service>


      <service
        name="XMLServices.UtenteServices.UtenteService"
        behaviorConfiguration="wsHttpCertificateBehavior">
        <endpoint
          name="UserPoint"
          address="" 
          binding="wsHttpBinding"
          bindingConfiguration="wsHttpEndpointBinding"
          contract="XMLContracts.ServiceContracts.IUtenteService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8766/XMLServices/UtenteServices/UtenteService" />
          </baseAddresses>
        </host>
      </service>
      </services>

这是我得到的例外:

“未提供客户端证书。在 ClientCredentials 中指定客户端证书。”

谁能帮我理解为什么我找不到我的证书?谢谢

【问题讨论】:

  • 你怎么知道没有找到证书?您是否收到异常或其他错误?在您的问题中包含更多信息。
  • @user469104 我更新了我的问题以包含它抛出的异常

标签: c# xml wcf wcf-endpoint endpointbehavior


【解决方案1】:

如果您看这里,您会发现您尝试使用的商店不是受信任的人文件夹中的商店,而是个人文件夹中的商店

你应该使用

StoreName.TrustedPeople

查看这里了解更多详情https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storename(v=vs.110).asp

您也很可能需要 StoreLocation.LocalMachine。

【讨论】:

    猜你喜欢
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 2021-09-23
    • 2015-12-03
    • 2010-11-15
    • 2012-08-06
    • 1970-01-01
    • 2014-05-11
    相关资源
    最近更新 更多