情景
X.509证书:组织提供证书以进行服务器 - 客户端身份验证。该证书既可用于目的服务器,也可用于客户端身份验证。
WCF服务: WCF服务在IIS中托管并在开发服务器上运行。它由X.509 pfx证书(由组织提供,不是自签名)保护。它在其配置中使用消息安全性。通过个人计算机中的本地计算机上的mmc在开发服务器上成功导入.Pfx
证书。证书和受信任的根证书颁发机构 - >证书
客户端它使用与服务相同的绑定结构。 .cer
文件(在开发服务器上使用相同的证书)在我的本地导入到Personal->证书和受信任的根证书颁发机构 - >证书。
服务配置:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"
minFreeMemoryPercentageToActivateService="0" />
<services>
<service name="WCF_HOST.Service1" behaviorConfiguration="customBehaviour">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:57104/Service1" />
<!--<add baseAddress = "http://****:57104/Service1" />-->
</baseAddresses>
</host>
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="customWsHttpBinding"
contract="WCF_HOST.IService1">
</endpoint>
<endpoint
address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="customWsHttpBinding">
<security mode="Message">
<message clientCredentialType="Certificate"/>
</security>
<!--<readerQuotas
maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />-->
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="customBehaviour">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
<serviceCredentials>
<serviceCertificate findValue="tempCert"
storeLocation="LocalMachine" storeName="My"
x509FindType="FindBySubjectName" />
<clientCertificate>
<authentication certificateValidationMode="PeerOrChainTrust"
revocationMode="NoCheck" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
客户端配置:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="customWsHttpBinding">
<security mode="Message">
<message clientCredentialType="Certificate" negotiateServiceCredential="true"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint
address="http://****:57104/Service1.svc"
binding="wsHttpBinding"
bindingConfiguration="customWsHttpBinding"
behaviorConfiguration="customBehavior"
contract="ServiceClient.IService1">
<identity>
<dns value="tempCert"/>
</identity>
</endpoint>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="customBehavior">
<clientCredentials>
<serviceCertificate>
<defaultCertificate findValue="he f5 l9 f9 41 e1 f5 ea 20 ef 55 bc 99 4c ca 5b c4 c5 31 d9" storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint"/>
<authentication certificateValidationMode="PeerOrChainTrust" revocationMode="NoCheck"/>
</serviceCertificate>
<clientCertificate
findValue="tempCert"
storeLocation="CurrentUser"
storeName="My" x509FindType="FindBySubjectName"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
证书说明
问题
当我尝试在webmethod
调用时使用该服务时,它会抛出异常
证书'CN = tempCert,OU = *** 19,O = **** Inc。,C = SG'必须有私钥。该进程必须具有私钥的访问权限
为什么客户端应用程序需要私钥?
如果我向客户端应用提供相同的.pfx
证书(在服务器上使用),它就可以了。怎么以及为什么?
在这个问题上浪费了无数个小时,任何帮助/建议都非常感谢。