【问题标题】:An error occurred when verifying security for the message验证邮件的安全性时出错
【发布时间】:2011-04-15 11:29:49
【问题描述】:

当我尝试调用 WCF 服务时,我收到以下消息“验证消息的安全性时发生错误。”

当我删除自定义身份验证时,服务正常工作。我无法弄清楚我在 web.config 中的配置错误。任何见解将不胜感激。

  <system.serviceModel>
     <services>
        <service behaviorConfiguration="NAThriveExtensions.nableAPIBehavior"
          name="NAThriveExtensions.nableAPI">
           <endpoint 
             address="" 
             binding="basicHttpBinding" 
             bindingConfiguration="basicHttpBinding_Secure"
             contract="NAThriveExtensions.InableAPI">
           </endpoint>
           <endpoint 
             address="mex" 
             binding="mexHttpsBinding" 
             contract="IMetadataExchange" />
        </service>
     </services>
     <behaviors>
        <serviceBehaviors>
          <behavior name="NAThriveExtensions.nableAPIBehavior">
            <serviceMetadata httpsGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="false" />
            <serviceCredentials>
              <userNameAuthentication 
                userNamePasswordValidationMode="Custom" 
              customUserNamePasswordValidatorType= "NAThriveExtensions.Authentication, NAThriveExtensions" />
            </serviceCredentials>
          </behavior>
        </serviceBehaviors>
     </behaviors>
     <bindings>
       <basicHttpBinding>
         <binding name="basicHttpBinding_Secure">
           <security mode="TransportWithMessageCredential">
             <message clientCredentialType="UserName"/>
           </security>
         </binding>
       </basicHttpBinding>
     </bindings>
  </system.serviceModel>

【问题讨论】:

    标签: wcf web-config wcf-binding servicebehavior


    【解决方案1】:

    我收到了同样的错误消息,结果证明是由于我的工作站机器和托管 WCF 服务的服务器之间存在时间差异。服务器比我的机器晚了大约 10 分钟,WCF 安全性似乎不太喜欢。

    为了找到根本问题,我在服务器的配置文件中打开了 serviceSecurityAuditing。将以下内容添加到您的服务的 configuration/system.serviceModel/behaviors/serviceBehaviors/behavior 部分:

    <serviceSecurityAudit 
        auditLogLocation="Application" 
        serviceAuthorizationAuditLevel="Failure" 
        messageAuthenticationAuditLevel="Failure" 
        suppressAuditFailure="true"/>
    

    以下网站有助于解决这个问题:

    http://blogs.microsoft.co.il/blogs/urig/archive/2011/01/23/wcf-quot-an-error-occurred-when-verifying-security-for-the-message-quot-and-service-security-audit.aspx

    【讨论】:

    • 这是一个很棒的诊断技巧!感谢分享。
    • 这确实是一个很棒的提示。看来我缺少一个 DLL,如下所述:stackoverflow.com/questions/14033193/…
    • 我希望我能多次投票!半天试图得到真正的错误信息。
    【解决方案2】:

    此消息的另一个原因是您的某些机器未及时同步。默认情况下,WCF 允许有 5 分钟的间隔;除此之外,如果事情不同步,它会引发错误。

    解决方案是同步所有机器。 time.windows.com 因不工作而臭名昭著,所以我建议使用其他东西。 (如果您在公司环境中,本地域控制器可能是正确的选择。)

    【讨论】:

    • 非常感谢!我拉着头发想知道这是什么问题!
    • 很高兴不仅仅是我@Stealth22 :)
    • 我的服务器和客户端在同一时间。客户端时钟自动配置,但服务器时钟是手动设置的。我在服务器上激活了“自动设置时间”,问题解决了。
    【解决方案3】:

    这最终成为了消费端的问题,而不是服务本身。 Software AG 的 webMethods 8 正在使用此服务器,但没有向服务添加安全处理程序,因此未将凭据添加到标头中,从而导致上述错误。

    【讨论】:

    • 如何确定这是否确实是问题所在?
    • @Maritim:问得好。查看原始 HTTP 请求是我所知道的最好方法 - 例如如果尚未记录,则通过记录它:丢失的(元素)SOAP 标头应该很明显。
    【解决方案4】:

    我遇到了类似的问题。 我正在使用 本地时间 构建日期时间格式的字符串,但我的服务/服务器期待 GMT

    我需要获取 GMT 时间 (JAVA):

    final Date currentTime = new Date();    
    final SimpleDateFormat sdf = 
    new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'.000Z'");
    sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
    System.out.println(sdf.format(currentTime));
    

    【讨论】:

      【解决方案5】:

      我在 IIS 7.5 服务器上遇到了同样的错误。我忘记将证书私钥的读取权限添加到app pool virtual account(例如 IIS AppPool\ASP.NET v4.0)。

      关于信息,在测试帐户和权限的各种组合时,我注意到应用程序池需要回收才能失去对密钥的访问权限,一旦它被检索一次。

      (0x80131501 - 验证消息的安全性时出错。)

      【讨论】:

        【解决方案6】:

        我遇到了同样的错误,以上对我没有任何帮助。

        我最终将其追踪到父 web.config 中的 connectionStrings(我的服务已部署到管理站点的子应用程序)。

        是的,这听起来很荒谬,但是一旦我将连接字符串包装在父 web.config 中并使用 location 元素,所有这些都开始工作了。

        为了清楚起见,在父 web.config 中,我改变了这个

        <connectionStrings>
            <add name="..." />
        </connectionStrings>
        

        到这里

        <location path="." inheritInChildApplications="false">
            <connectionStrings>
                <add name="..." />
            </connectionStrings>
        </location>
        

        注意这个错误也导致了这个非常无用的serviceSecurityAudit日志消息:

        消息验证失败。
        服务:...
        行动:http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT
        客户身份:
        活动 ID:
        ArgumentNullException:值不能为空。
        参数名称:经理

        【讨论】:

          【解决方案7】:

          我遇到了同样的错误。我忘记将成员数据库 aspnetdb 的读取权限添加到 (IIS APPPOOL\DefaultAppPool)。

          消息验证失败。服务:....

          操作:http://schemas.xmlsoap.org/ws/2005/02/trust/RST/SCT

          客户身份:

          活动编号:

          SqlException:无法打开登录请求的数据库“aspnetdb”。登录失败。

          用户 'IIS 登录失败 APPPOOL\DefaultAppPool'。

          【讨论】:

            【解决方案8】:

            用户名和密码是您连接的服务器,而不是您的 系统登录用户名和密码。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-07-28
              • 2020-05-19
              • 2011-10-20
              • 2014-05-14
              • 1970-01-01
              • 2013-10-18
              相关资源
              最近更新 更多