【问题标题】:WCF Security :The service certificate is not provided. Specify a service certificate in ServiceCredentialsWCF 安全:未提供服务证书。在 ServiceCredentials 中指定服务证书
【发布时间】:2014-10-13 14:49:09
【问题描述】:

我通过重载“UserNamePasswordValidator”并使用消息安全性实现了带有自定义验证的 WCF 服务,但在我的开发机器上没有证书,但在 LIVE 环境中存在 SSL 证书。所以我用下面的代码在 LIVE 服务器上托管了服务,但我仍然遇到错误

    'The service certificate is not provided. Specify a service certificate in ServiceCredentials'

    '<system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="customBehavior">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
              <serviceCredentials>
                <userNameAuthentication 
                  userNamePasswordValidationMode="Custom" 
                  customUserNamePasswordValidatorType="Myassembly.UserNameValidator,Myservice"/>
    <serviceCertificate findValue="MyCertName" storeLocation="CurrentUser" storeName="TrustedPeople" x509FindType="FindBySubjectName" />
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
        </behaviors>

        <bindings >
          <wsHttpBinding>
            <binding name="RequestUserName" >
              <security mode="Message">
                <message clientCredentialType="Certificate"/>
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>

        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />

        <services>
          <service name="CRMServices" behaviorConfiguration="customBehavior">
            <!--For basic http binding endpoint-->
            <endpoint address="" binding="wsHttpBinding" 
                      bindingConfiguration="RequestUserName"
                      contract="ICRMServices">
              <!--<identity>
                <dns value="localhost" />
              </identity>-->
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            <host>
              <baseAddresses>

              </baseAddresses>
            </host>
          </service>
        </services>
      </system.serviceModel> '

I have applied SSL to the deployed WCF service but when try to access the hosted URL it is giving '404' and in event viewer it is showing 
 'InvalidOperationException 
   Cannot find the X.509 certificate using the following search criteria: StoreName 'TrustedPeople', StoreLocation 'CurrentUser', FindType 'FindBySubjectName', FindValue 'Mycert'. at System.ServiceModel.Security.SecurityUtils.GetCertificateFromStoreCore(StoreName storeName, StoreLocation storeLocation, X509FindType findType, Object findValue, EndpointAddress target, Boolean throwIfMultipleOrNoMatch '

请帮帮我

【问题讨论】:

  • 回滚已损坏配置的编辑 - 由于&lt;serviceCertificate&gt; 元素丢失,因此无法再理解答案

标签: wcf ssl-certificate x509certificate wcf-security


【解决方案1】:

找不到证书。您指定:

<serviceCertificate findValue="MyCertName" storeLocation="CurrentUser" storeName="TrustedPeople" x509FindType="FindBySubjectName" />

因此它将在 CurrentUser 存储中的 TrustedPeople 中查找主题中带有 MyCertName 的证书。 当您在 Visual Studio 中运行 WCF 服务时,它会在您的帐户下运行,因此在这种情况下当前用户可以使用。但是当你在 IIS 上部署服务时,它会在应用池用户下运行(默认是 IIS APPPOOL\DefaultAppPool 用户)。

我愿意

  • 检查您要使用的证书在哪里(在什么存储中)。我敢打赌它在 LocalMachine\Personal 商店中。您可以使用mmc 进行检查
  • 如果我可以选择放置服务证书的位置,它会是 LocalMachine\Personal。我将为运行该服务的应用程序池用户的证书设置对私钥的访问权限。可以在mmc完成。
  • 我会选择x509FindType="FindByThumbrint" 作为我的搜索条件。您可以确定商店中只有一张证书。

【讨论】:

    猜你喜欢
    • 2012-03-24
    • 1970-01-01
    • 2012-08-06
    • 2014-05-11
    • 2012-01-23
    • 2015-08-17
    • 2014-06-19
    • 1970-01-01
    • 2010-12-06
    相关资源
    最近更新 更多