3

我在我的CRM實例上配置了基於聲明的身份驗證。我正在使用自定義STS(可用示例here)現在我想從某個測試應用程序訪問Web服務。 有沒有人有這樣的例子? 我嘗試使用相同的代碼進行連接以防止Windows身份驗證。但是,當然,不成功。 我發現了一個錯誤:如何使用SDK連接到CRM(基於聲明的身份驗證和自定義STS)

{"The authentication endpoint Kerberos was not found on the configured Secure Token Service!"}

這是連接代碼(AD身份驗證類型):

OrganizationServiceProxy orgserv; 
     ClientCredentials clientCreds = new ClientCredentials(); 
     ClientCredentials devCreds = new ClientCredentials(); 


     clientCreds.Windows.ClientCredential.UserName = "user"; 
     clientCreds.Windows.ClientCredential.Password = "[email protected]$$w0rd"; 
     clientCreds.Windows.ClientCredential.Domain = "myDomain"; 
     IServiceConfiguration<IOrganizationService> orgConfigInfo = 
        ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri("https://myCRMServer/myOrg/XRMServices/2011/Organization.svc")); 

     using (orgserv = new OrganizationServiceProxy(orgConfigInfo, clientCreds)) 
     { 
      orgserv.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior()); 
      orgserv.EnableProxyTypes(); 
      connection = orgserv; 
     } 

我發現的地方,基於要求的認證就足以只發送UPN(用戶主要名稱)。但同樣的錯誤發生。我也嘗試使用用戶名/密碼組合,但不成功。

AuthenticationCredentials authCredentials = new AuthenticationCredentials(); 

...

authCredentials.UserPrincipalName = "user"; 

...在此之後

錯誤是:The authentication endpoint Username was not found on the configured Secure Token Service!

回答

1

我終於解決了這個問題。最後,我配置了ADFS併爲我的自定義STS添加了Relaying Party信任。現在這完美地工作。 API調用通過ADFS完成,Web訪問認證通過自定義STS完成。

3

如果你只是用CRM 2011的Web服務界面我不我認爲索賠甚至很重要。以下代碼允許進行身份驗證並連接到CRM 2011並使用REST API

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Net; 
using System.IO; 

namespace CRM_REST_FromConsoleApplication 
{ 
    internal class Program 
    { 
     private static void Main(string[] args) 
     { 
      var url = new Uri(@"https://MyServer/MyOrganiation/xrmservices/2011/organizationdata.svc/AccountSet?$select=Name&$top=10"); 

      HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; 

      //TODO: Set Credentials Here    
      request.Credentials = new NetworkCredential("USERNAME GOES HERE", "PASSWORD GOES HERE", "myDomain"); 


      using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) 
      { 
       StreamReader reader = new StreamReader(response.GetResponseStream()); 

       Console.WriteLine(reader.ReadToEnd()); 
      } 

      Console.WriteLine("Press any key to continue..."); 
      Console.ReadKey(); 
     } 
    } 
} 
+0

我在這裏得到一個錯誤:{嘗試了太多的自動重定向} ... – lazarus 2012-12-18 14:43:38

相關問題