验证邮件的安全性时发生错误

Mat*_*eis 25 wcf web-config wcf-binding servicebehavior

当我尝试调用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>
Run Code Online (Sandbox Code Playgroud)

Sam*_*Sam 35

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

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

<serviceSecurityAudit 
    auditLogLocation="Application" 
    serviceAuthorizationAuditLevel="Failure" 
    messageAuthenticationAuditLevel="Failure" 
    suppressAuditFailure="true"/>
Run Code Online (Sandbox Code Playgroud)

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

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

  • 这是一个很好的诊断提示!感谢分享. (8认同)
  • 我希望我能不止一次地投票!半天试图得到真正的错误信息. (2认同)

ash*_*999 17

此消息的另一个原因是您的某些计算机未及时同步.默认情况下,WCF允许五分钟的差距; 除此之外,如果事情不同步,它会抛出错误.

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

  • 非常感谢!我拉着我的头发想知道这个问题是什么! (4认同)
  • 我的服务器和客户端处于同一时钟.客户端时钟自动配置,但手动设置服务器时钟.我在服务器上激活了"自动设置时间"并解决了问题. (3认同)

Mat*_*eis 7

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

  • 怎么能发现这确实是问题呢? (5认同)