2013-10-16 53 views
4

我有一個wcf服務,用於查詢ADFS的SAML令牌。這是從Web查詢ADFS的常見片段,並取回SAML令牌。 然而,它總是在行返回channel.Isue(rst); 。錯誤ID3082:請求範圍無效或不受支持。 至少在高層次上,我無法弄清楚錯誤是在ADFS服務器端,還是在配置WCF服務的方式或代碼。請幫忙。使用WCF託管在Windows服務上針對ADFS進行身份驗證

public SecurityToken GetSamlToken() 
    { 
      using (var factory = new WSTrustChannelFactory(
      new UserNameWSTrustBinding(SecurityMode.TransportWithMessageCredential), 
      new EndpointAddress(new Uri("https://serv/adfs/services/trust/13/usernamemixed")))) 
      { 
      factory.Credentials.UserName.UserName = "username"; 
      factory.Credentials.UserName.Password = "password"; 
      factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None; 
      factory.TrustVersion = TrustVersion.WSTrust13;     
      WSTrustChannel channel = null;     
      try 
      { 
       string KeyType; 
       var rst = new RequestSecurityToken 
           { 
            RequestType = WSTrust13Constants.RequestTypes.Issue, 
            AppliesTo = new EndpointAddress("net.tcp://localhost:xxxx/Service1/mex"),       
            KeyType = Microsoft.IdentityModel.Protocols.WSTrust.WSTrust13Constants.KeyTypes.Bearer,           
           }; 

       channel = (WSTrustChannel)factory.CreateChannel(); 

       return channel.Issue(rst); 
      } 
      finally 
      { 
       if (channel != null) 
       { 
        channel.Abort(); 
       } 

       factory.Abort(); 
      } 
     } 
    } 

回答

3

的問題是與

AppliesTo = new EndpointAddress("net.tcp://localhost:xxxx/Service1/mex") 

我有依賴方URI代替它,它會發出我的令牌。這裏唯一的問題是令人困惑的錯誤消息。

0

該錯誤很可能與ADFS端點的配置有關。下面的文章似乎提供與步驟沿ADFS Web服務通信的一個很好的概述,以解決一些問題:

http://msinnovations.wordpress.com/2011/03/28/some-tips-on-active-federation-with-adfs-2-0/

爲了獲得在哪裏(也許是爲什麼)的錯誤發生,您的詳細信息可能需要/需要配置WCF跟蹤/日誌記錄。下面的鏈接提供了概述:

http://msdn.microsoft.com/en-us/library/ms733025.aspx

問候,

+0

博客上顯示「ID3082:請求範圍無效或不受支持,其中一個原因可能是您的應用程序沒有在ADFS中設置依賴方信任關係。」那麼這是否意味着我的wcf服務必須作爲依賴方加入?我是ADFS 2.0的完全新手。我看過關於如何配置依賴方的文章,但是我們是否也爲WCF服務做了同樣的事情?在這個時候,我還沒有物理訪問ADFS服務器。 – simba

+0

既然你特別提到ADFS的觀點,我認爲我必須接受你的答案 – simba

相關問題