Windows服务中的WCF安全性

时间:2009-10-13 15:18:19

标签: wcf windows-services wcf-security

我有一个WCF服务,可以作为控制台应用程序和Windows服务运行。我最近将控制台应用程序复制到具有以下安全设置的W2K3服务器:

<wsHttpBinding>
 <binding name="ServiceBinding_Security" transactionFlow="true" >
  <security mode="TransportWithMessageCredential" >
    <message clientCredentialType="UserName" />
  </security>           
 </binding>             
</wsHttpBinding> 

<serviceCredentials>
 <userNameAuthentication  userNamePasswordValidationMode="Custom" 
  customUserNamePasswordValidatorType="Common.CustomUserNameValidator, Common" />
</serviceCredentials>

安全性正常,没有任何问题。我有完全相同的代码,但在Windows服务中运行,当我尝试从客户端调用任何方法时,我收到以下错误:

System.ServiceModel.Security.MessageSecurityException was unhandled
Message="An unsecured or incorrectly secured fault was received from 
         the other party. See the inner FaultException for the fault code and detail."
  Source="mscorlib"
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.ProcessReply(Message reply, SecurityProtocolCorrelationState correlationState, TimeSpan timeout)
       ......   
    (lots of stacktrace info - not very useful)

  InnerException: System.ServiceModel.FaultException
       Message="An error occurred when verifying security for the message."

这个例外没有告诉我什么。我假设它与从Windows服务访问系统资源有关。我尝试在与控制台应用程序相同的帐户下运行它,但没有运气。有没有人有任何想法?

4 个答案:

答案 0 :(得分:1)

这是一个有时与安全无关的错误。

我建议你首先尝试让它在没有安全性的情况下工作,然后只使用消息安全性,然后使用传输,最后使用TransportWithMessageCredential。

此外,如果您在同一台计算机上运行控制台应用程序和Windows服务应用程序,请确保在启动Windows服务之前停止控制台应用程序,以避免端口冲突

答案 1 :(得分:1)

启用服务诊断。这应该让你很好地了解服务是否甚至接收消息以及服务抛出异常的位置。

答案 2 :(得分:1)

更新 - 我将customUserNamePasswordValidatorType从Custom更改为Windows。这在Console和Windows服务中都运行良好。我只能假设自定义验证器中的某些内容导致了问题。

自定义验证程序使用App.config中的自定义配置部分来验证用户标识和密码。我原本以为这可以从Windows服务工作。

感谢所有发布回复的人。

答案 3 :(得分:0)

您正在使用自定义用户/名称验证程序 - Windows服务是否可以访问该文件?

您在哪个帐户下运行NT服务?

是否可以关闭所有安全措施? (只是为了看)

马克