【问题标题】:WCF Security in a Windows ServiceWindows 服务中的 WCF 安全性
【发布时间】:2010-12-06 08:43:48
【问题描述】:

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

【问题讨论】:

  • 哎呀这让我头疼...
  • 安全信息是:

标签: wcf windows-services wcf-security


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    对服务启用诊断。这应该让您很好地了解服务是否甚至接收到消息以及服务在哪里抛出异常。

    【讨论】:

      【解决方案3】:

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

      自定义验证器使用 App.config 中的自定义配置部分来验证用户 ID 和密码。我原以为这可以通过 Windows 服务工作。

      感谢所有回复的人。

      【讨论】:

        【解决方案4】:

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

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

        它是否在所有安全性关闭的情况下工作? (只是为了看看)

        马克

        【讨论】:

        • 诊断错误消息 = 安全协议无法验证传入消息。没有其他的。我可以确认该服务在没有安全性的情况下正常工作。我尝试在“本地系统”和“管理员”下运行服务自定义名称验证器正在验证 app.config 中的自定义部分。
        猜你喜欢
        • 1970-01-01
        • 2013-09-25
        • 2012-02-13
        • 1970-01-01
        • 2023-04-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-07
        相关资源
        最近更新 更多