簡體   English   中英

為什么我在WCF服務中找不到證書?

[英]Why I can't find the certificate in a WCF Service?

我正在嘗試使用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文件夾中的商店,而是個人文件夾中的商店

你應該使用

StoreName.TrustedPeople

在此處查看更多詳細信息https://msdn.microsoft.com/zh-cn/library/system.security.cryptography.x509certificates.storename(v=vs.110).asp

您也很可能需要StoreLocation.LocalMachine。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM