需要帮助以确保我的WCF服务使用证书
问题描述:
我正在写服务的互联网场景。我必须实现消息加密。我得到了一切,但当我从IIS浏览这个服务时,我得到以下异常。
'/ MyTestService'中的服务器错误 应用程序。
键集不存在
说明:未处理的异常 的 当前Web请求的执行过程中发生。请查看 堆栈跟踪以了解有关 错误的更多信息,以及它源自 的代码。
异常详细信息: System.Security.Cryptography.CryptographicException: 键集不存在 ............................ ...................................
........... .................................................. .......
这似乎是证书问题。有人可以解释如何处理证书的东西,请详细。只要认为我是证书的新手。
<system.serviceModel>
<services>
<service name="Test.MyService" behaviorConfiguration="MyServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="MyTestService" binding="wsHttpBinding" bindingConfiguration="WebserviceHttpBinding" contract="Test.IMyService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="WebserviceHttpBinding">
<security mode="Message">
<message clientCredentialType="UserName" negotiateServiceCredential="false"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Test.CredentialValidator, Test"/>
<serviceCertificate findValue="RPKey" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
</serviceCredentials>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
答
您是否设置了对证书私钥的访问权限?私钥在默认情况下受到保护,因此只有管理员才能访问它们。您必须为运行您服务的AppPool的帐户设置读取权限。
编辑:设置权限打开MMC并为本地计算机添加管理单元。导航至个人>证书> RPKey,然后从上下文菜单中选择所有任务>管理私钥。
有没有任何链接,我可以在哪里阅读有关公共和私人证书或视频教程? – Saghar 2010-08-18 11:41:51
条款私人和公共证书可能不正确。证书是密钥和相关信息的标准化容器(如发行人,到期日,主题,序列号等)。存储在服务器上的证书必须包含私钥和公钥。提供给客户的证书只能包含公钥 - 公钥基础设施。 – 2010-08-18 19:54:38
您的解决方案为我工作 - 比你。 – Vlad 2012-09-24 11:11:15