2011-07-01 66 views
14

服務器配置:至少一個安全令牌無法驗證

<?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。
內部例外:
消息中至少有一個安全令牌無法驗證。

如何解決此異常?

回答

21

我認爲問題是您的用戶名和密碼。使用默認配置,用戶名和密碼被驗證爲windows帳戶。如果您需要其他驗證,您必須使用membership providercustom user name password validator

+1

非常感謝,我在這個簡單的例子中工作了一個星期,沒有你的幫助我會工作更多。現在它可以工作。 – croisharp

+0

歡呼,這是一個超級酷的答案..作品像一個魅力! – Sandepku

3

由於錯誤信息相當模糊,我想我會把它作爲另一種可能的解決方案。

我的環境使用Single Sign On(或STS,如果您願意)通過ASP.NET MVC網站對用戶進行身份驗證。 MVC站點反過來通過向服務端點發送一個服務調用,將之前使用Bootstrap令牌從STS服務器請求的不記名令牌傳遞給服務端點。我得到的錯誤是當我從MVC網站進行服務調用時。

在我的情況下,這是由我的服務配置造成的,如下所述。尤其是audienceUris節點,它必須與服務端點完全匹配:

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

HTH。

相關問題