0

我正在尝试使用 wsHttpBinding 托管 WCF 服务。我使用 makecert 创建了一个证书,并在 web.config 中放置了一些行。

这是我得到的错误:

System.ArgumentException: The certificate 'CN=WCfServer' must have a private key that is capable of key exchange. The process must have access rights for the private key.

在谷歌搜索时,证书文件的访问权限似乎存在一些问题。我使用 cacls 授予 NETWORK SERVICE 和我的用户名的读取权限,但它没有改变任何内容。

我还进入了证书文件属性中的安全设置,并完全控制了 NETWORK SERVICE 和我的用户名。再次无济于事。

您能指导我解决问题所在以及我需要做什么吗?我对这些证书的东西真的很不满意。

这是我的 web.config:

<system.serviceModel>

<services>
        <service name="Abc.Service" behaviorConfiguration="Abc.ServiceBehavior">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Abc.BindConfig" contract="Abc.IService">
                <identity>
                    <dns value="localhost"/>
                </identity>
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
    </services>

<behaviors>
    <serviceBehaviors>
        <behavior name="Abc.ServiceBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>

            <serviceCredentials>
                <clientCertificate>
                  <authentication certificateValidationMode="PeerTrust"/>
                </clientCertificate>
                <serviceCertificate findValue="WCfServer" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
            </serviceCredentials>

        </behavior>
    </serviceBehaviors>
</behaviors>

<bindings>
  <wsHttpBinding>
    <binding name="Abc.BindConfig">
      <security mode="Message">
        <message clientCredentialType="Certificate" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

</system.serviceModel>
4

3 回答 3

3

从我可以从网上收集的信息来看,这似乎不是权限问题,更像是证书配置有问题。

这里有关于如何允许访问私钥的说明。

您是否安装并运行了 IIS7。那里有一个非常简单的工具来创建我已成功用于 WCF 通信的证书(而不是 makecert)。

于 2010-05-03T12:12:30.390 回答
2

好的..我想出了问题所在。使用 makecert 创建证书时,必须使用 -pe 选项,这使得生成的私有可导出,以便可以在证书中使用。问题是与 vs2008 捆绑在一起的 makecert 是 5.131 版本,它没有 -pe 选项。我在 microsoft sdk 6 中找到了 6.0 版,它有这个选项。

这是我作为 .net 初学者发现的最大问题。同一个东西有很多不兼容的版本,当你在互联网上查找东西时,你不知道有人在谈论哪个版本。

于 2010-05-04T05:30:55.860 回答
1

查看Windows HTTP 服务证书配置工具 (WinHttpCertCfg.exe)。它允许向 Windows 帐户授予对 X.509 证书的私钥的访问权限。

这是一篇解释如何使用该工具的博客文章。

于 2010-05-03T13:09:36.690 回答