【问题标题】:At least one security token in the message could not be validated无法验证消息中的至少一个安全令牌
【发布时间】:2011-09-26 14:06:44
【问题描述】:

服务器配置:

<?xml version="1.0"?>
<configuration>
<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceCredentialsBehavior">
                <serviceCredentials>
                    <serviceCertificate findValue="cn=cool" storeName="TrustedPeople" storeLocation="CurrentUser" />
                </serviceCredentials>
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="ServiceCredentialsBehavior" name="Service">
            <endpoint address="" binding="wsHttpBinding" bindingConfiguration="MessageAndUserName" name="SecuredByTransportEndpoint" contract="IService"/>
        </service>
    </services>
    <bindings>
        <wsHttpBinding>
            <binding name="MessageAndUserName">
                <security mode="Message">
                    <message clientCredentialType="UserName"/>
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client/>
</system.serviceModel>
<system.web>
    <compilation debug="true"/>
</system.web>

我的客户端配置:

<?xml version="1.0" encoding="utf-8"?>
  <configuration>
<system.serviceModel>
    <behaviors>
        <endpointBehaviors>
            <behavior name="LocalCertValidation">
                <clientCredentials>
                    <serviceCertificate>
                        <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="CurrentUser" />
                    </serviceCertificate>
                </clientCredentials>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService" >
                <security mode="Message">
                    <message clientCredentialType="UserName" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:48097/WCFServer/Service.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="WSHttpBinding_IService"
                  contract="ServiceReference1.IService"
                  name="WSHttpBinding_IService" behaviorConfiguration="LocalCertValidation">
            <identity>
                <dns value ="cool" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

服务:

public string TestAccess()
{
    return OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name;
}

客户:

        ServiceClient client = new ServiceClient();
        client.ClientCredentials.UserName.UserName = "Admin";
        client.ClientCredentials.UserName.Password = "123";
        Console.WriteLine(client.TestAccess());
        Console.ReadLine();

错误:
从另一方收到不安全或不正确安全的故障。有关故障代码和详细信息,请参见内部 FaultException。
内部异常:
无法验证消息中的至少一个安全令牌。

如何解决这个异常?

【问题讨论】:

    标签: wcf web-services security certificate wshttpbinding


    【解决方案1】:

    我认为问题出在您的用户名和密码上。使用默认配置,用户名和密码被验证为 windows 帐户。如果您需要其他验证,则必须使用 membership providercustom user name password validator

    【讨论】:

    • 非常感谢,我在这个简单的例子上工作了 1 周,如果没有你的帮助,我会做得更多。现在可以了。
    【解决方案2】:

    由于错误消息相当模糊,我想我会把它作为另一种可能的解决方案放在那里。

    我的环境使用单点登录(或 STS,如果您愿意)通过 ASP.NET MVC 站点对用户进行身份验证。 MVC 站点反过来通过传递它从 STS 服务器请求的承载令牌与先前的引导令牌来对我的服务端点进行服务调用。我遇到的错误是从 MVC 站点进行服务调用时。

    就我而言,这是由我的服务配置引起的,如下所述。特别是 AudienceUris 节点,它必须与服务端点完全匹配:

    <system.identityModel>
        <identityConfiguration>
            <audienceUris>
                <add value="https://localhost/IdpExample.YService/YService.svc" />
            </audienceUris>
            ....
        </identityConfiguration>
    </system.identityModel>
    

    HTH。

    【讨论】:

      猜你喜欢
      • 2020-05-19
      • 2019-08-31
      • 2013-02-12
      • 2017-03-20
      • 1970-01-01
      • 2014-04-16
      • 2010-12-10
      • 1970-01-01
      • 2012-04-14
      相关资源
      最近更新 更多