簡體   English   中英

幫助在.net上設置wsHttpBinding WCF服務

[英]help setting up wsHttpBinding WCF service on .net

我正在嘗試使用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>

從我可以從網絡上收集到的信息來看,這似乎不是權限問題,更像是證書配置存在問題。

這里有有關如何允許訪問私鑰的說明。

您是否已安裝並正在運行IIS7。 有一個非常簡單的工具可以用來創建我已成功用於WCF通信的證書(而不是makecert)。

好吧..我知道了問題所在。 使用makecert創建證書時,必須使用-pe選項,使生成的私有文件可導出,以便可以在證書中使用。 問題是與vs2008捆綁在一起的makecert是5.131版,沒有-pe選項。 我在帶有選項的Microsoft SDK 6中找到了6.0版。

作為.net初學者,這是最大的問題。 同一事物有許多不兼容的版本,當您在Internet上查找內容時,您不知道別人在談論哪個版本。

查看Windows HTTP Services證書配置工具(WinHttpCertCfg.exe) 它允許將對X.509證書的私鑰的訪問權限授予Windows帳戶。

這是一篇博客文章 ,介紹了如何使用該工具。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM