在生产服务器上找不到WCF Web服务证书

时间:2018-11-02 12:54:59

标签: web-services wcf ssl-certificate x509certificate wcf-security

我正在通过WCF Web服务使用自定义身份验证。我在计算机上创建了本地证书,当我在web.config中引用它时,一切正常。

在生产服务器上,我创建了一个SSL证书并将其绑定到我的网站。该证书称为“ GAAWEBDEV_20Mars2020”。

发布应用程序时,显示以下消息:

Cannot find the X.509 certificate using the following search criteria: StoreName 'My', StoreLocation 'LocalMachine', FindType 'FindBySubjectName', FindValue '‎‎GAAWEBDEV_20Mars2020'.

这是我在web.config中的代码:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="Behavior1">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <serviceCredentials>   
        <!--
          <serviceCertificate findValue="Test" storeLocation="LocalMachine"
          storeName="My" x509FindType="FindBySubjectName" />
        -->
        <serviceCertificate findValue="‎‎GAAWEBDEV_20Mars2020" storeLocation="LocalMachine" x509FindType="FindBySubjectName"/>
        <userNameAuthentication userNamePasswordValidationMode="Custom"
         customUserNamePasswordValidatorType="PSA904.CustomValidator, PSA904" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <wsHttpBinding>
    <binding name="Binding1">
      <security mode="Message">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service behaviorConfiguration="Behavior1" name="PSA904.servPSA904">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
     contract="PSA904.PSA904" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/" />
      </baseAddresses>
    </host>
  </service>
</services>

这是我们网站的链接:https://psa904webdev.gaa.qc.ca/servPSA904.svc您可以看到我们有一个名为“ GAAWEBDEV_20Mars2020”的证书

谢谢!

3 个答案:

答案 0 :(得分:0)

首先,请确保您的证书存在。通过运行certmgr.msc或mmc.exe。 您还可以通过其他方法找到证书,例如通过指纹来验证:

    <serviceCertificate storeLocation="LocalMachine" storeName="My" 
             x509FindType="FindByThumbprint" 
             findValue="14 c2 b1 c2 b8 a1 fd 25 n2 bb 39 5d 32 r3 53 f3 0c vy t1 c4"/>

答案 1 :(得分:0)

您应确保证书已正确安装在证书存储区中。 不要忘记分配证书存储位置。 storeName =“我的”

<serviceCertificate findValue="‎‎GAAWEBDEV_20Mars2020" storeLocation="LocalMachine" x509FindType="FindBySubjectName" storeName="My" />

这些是其枚举值。
enter image description here
它对应于证书管理器中的以下值。 enter image description here
您可以与证书管理器联系,以查看证书是否已正确安装。打开证书管理器的方式。

  

Win + R> certmgr.msc

请让我知道是否有什么可以帮助您的。

答案 2 :(得分:0)

您可以尝试以下方法,运行以下代码,查看您的特定证书是否出现

using (var store = new X509Store(StoreName.My,StoreLocation.LocalMachine))
            {
                store.Open(OpenFlags.ReadOnly);

                var certificates = store.Certificates;
}

您可以使用证书对象列出特定商店中的所有证书,并从该输出中检查您的证书是否存在。

您还可以在此处使用证书对象来获取ThumbPrint等。作为最后的选择,您可以尝试通过代码安装证书,并使用相同的证书通过xmlSerializer或Linq来配置Web配置。