Windows 服务中的 WCF 安全性

标签 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 服务访问系统资源有关。我尝试在与控制台应用程序相同的帐户下运行它,但没有运气。有没有人有任何想法?

最佳答案

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

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

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

关于Windows 服务中的 WCF 安全性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1560906/

相关文章:

c# - 仅使用服务证书的 WCF 消息安全性

c# - 如何在 WCF 服务响应中正确实现自定义 soap 1.2 header 和 WS-Addressing

windows - 使用 FileSystemWatcher 在 Windows 服务中一次处理多个文件时出现问题

jenkins - 如何禁用已安装的 jenkins 作为 Windows 服务并在 cmd 中运行相同的 jenkins?

azure - 在 Azure 应用服务上运行的 WCF 服务的 SSL 设置存在问题

c# - 具有自定义 MembershipProvider 且没有 X.509 证书的 WCF,可能吗?

wcf - 不同服务器上的 MSMQ 和多个 wcf 服务从同一队列读取

serialization - 如何使用 WCF 将派生类型序列化为其基类型

c# - WCF 服务基址与端点地址

winapi - 我可以在进程之间传递 SC_HANDLE 吗?