2011-06-16 125 views
1

我正尝试创建具有消息安全性的Web服务。WCF在IIS上失败。系统找不到指定的文件

这里是一个配置:

<system.serviceModel> 
    <services> 
     <service name="WCFMessage.Service1" behaviorConfiguration="behaviour1"> 
     <endpoint address="" contract="WCFMessage.IService1" binding="wsHttpBinding" bindingConfiguration="binding1" /> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="behaviour1"> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceCredentials> 
      <serviceCertificate findValue="MyCert" 
           x509FindType="FindBySubjectName" 
           storeLocation="LocalMachine" 
           storeName="My"/> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 

    </behaviors> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="binding1"> 
      <security mode="Message"> 
      <message clientCredentialType="None" negotiateServiceCredential="false"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    </system.serviceModel> 

它运作良好,在本地主机上,但在IIS上,它给了我一个错误:

The system cannot find the file specified.

堆栈跟踪:

It is likely that certificate 'CN=MyCert' may not have a private key that is capable of key exchange or the process may not have access rights for the private key.

我试过this方法,但仍然出现错误。

任何帮助表示赞赏。

回答

1

我在过去几天有类似的情况。我找到了一个可以接受的解决方法,所以我会和你分享。问题出在IIS应用程序池用户帐户无法访问服务证书私钥文件 - 或者没有在它期望的私有密钥中!

注:我将假定你有自己的证书颁发机构的运行。

要解决此问题,请按照下列步骤操作:

  1. 创建您要使用的IIS应用程序池一个新的用户帐户。
  2. 您可以创建一个新的应用程序池以与此用户标识一起使用,或将此新用户标识分配给DefaultAppPool或您的服务使用的任何应用程序池(在IIS管理器中执行此操作)。
  3. 然后打开IE,导航到http://yourserver/certsrv来请求新的服务器认证证书。请求中使用相同的CN(“MyCert”)。
  4. 打开证书颁发机构发出请求的证书。
  5. 再次转到http://yourserver/certsrv,单击“查看挂起证书请求的状态”,然后安装证书。
  6. 现在你需要做出改变你的“serviceCertificate的” web.config部分,在某种程度上,它看起来像这样:

    <serviceCredentials> 
        <serviceCertificate findValue="MyCert" 
             x509FindType="FindBySubjectName" 
             storeLocation="CurrentUser" 
             storeName="My"/> 
        </serviceCredentials> 
    
  7. 保存,重建服务并对其进行测试,它应该工作精细。

(它会更容易,如果这可以使用MMC导出/导入证书功能来实现,但由于某种原因其行为并不像我们希望它是)

+0

感谢。我找到了解决方案,问题和你的一样。 – 2012-01-21 12:59:59

相关问题