C# 为什么我能';在WCF服务中找不到证书?

C# 为什么我能';在WCF服务中找不到证书?,c#,xml,wcf,wcf-endpoint,endpointbehavior,C#,Xml,Wcf,Wcf Endpoint,Endpointbehavior,我正在尝试使用WCF开发服务,但找不到我创建的证书,该证书位于TrustedPeple文件夹下。到目前为止,这是我编写的代码块: client.ClientCredentials.ServiceCertificate.SetDefaultCertificate( StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName,

我正在尝试使用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中指定客户端证书。”


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

如果您查看此处,您将看到您尝试使用的存储不是来自trusted people文件夹的存储,而是来自personal文件夹的存储

你应该使用

StoreName.TrustedPeople
查看此处了解更多详细信息


您很可能还需要StoreLocation.LocalMachine。

如何知道找不到证书?您是否遇到异常或其他错误?在您的问题中包含更多信息。@user469104我更新了我的问题以包含它引发的异常