Windows服务中的WCF安全性

Windows服务中的WCF安全性,wcf,windows-services,wcf-security,Wcf,Windows Services,Wcf Security,我有一个WCF服务,可以作为控制台应用程序和Windows服务运行。我最近使用以下安全设置将console应用程序复制到W2K3服务器: <wsHttpBinding> <binding name="ServiceBinding_Security" transactionFlow="true" > <security mode="TransportWithMessageCredential" > <message clientCredent

我有一个WCF服务,可以作为控制台应用程序和Windows服务运行。我最近使用以下安全设置将console应用程序复制到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服务访问系统资源有关。我试着用与控制台应用程序相同的帐户运行它,但没有成功。有人有什么想法吗?

您正在使用自定义用户名验证程序-Windows服务是否有权访问该文件

您使用哪个帐户运行NT服务

它在所有安全关闭的情况下工作吗??(只是想看看)


Marc

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

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


此外,如果您在同一台计算机上运行console应用程序和windows service应用程序,请确保在启动windows服务之前停止console应用程序,以避免端口冲突,从而启用服务诊断功能。这会让您很好地了解服务是否正在接收消息,以及服务在哪里抛出异常

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

自定义验证器使用App.config中的自定义配置部分来验证用户ID和密码。不过,我原以为这在windows服务中是可行的


感谢所有发布回复的人。

哎哟,这让我头疼……安全信息是:诊断错误消息=安全协议无法验证传入消息。没有别的了。我可以确认服务在没有安全的情况下工作。我已尝试在“本地系统”和“管理员”下运行该服务。自定义名称验证程序正在根据app.config中的自定义部分进行验证。
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."