C# 如何使用SDK连接到CRM(基于声明的身份验证和自定义STS)

C# 如何使用SDK连接到CRM(基于声明的身份验证和自定义STS),c#,dynamics-crm-2011,dynamics-crm,claims-based-identity,sts-securitytokenservice,C#,Dynamics Crm 2011,Dynamics Crm,Claims Based Identity,Sts Securitytokenservice,我在CRM实例上配置了基于声明的身份验证。我正在使用定制STS(示例可用),现在我想从一些测试应用程序访问web服务。 有人举过这样的例子吗? 我尝试使用相同的代码来连接windows auth。当然,这是不成功的。 我得到一个错误: {“在配置的服务器上找不到身份验证终结点Kerberos 安全令牌服务!} 这是连接代码(对于AD身份验证类型): 这之后的错误是:在配置的安全令牌服务上找不到身份验证终结点用户名如果您只是使用CRM 2011 web服务界面,我认为索赔甚至都不重要。下面的代

我在CRM实例上配置了基于声明的身份验证。我正在使用定制STS(示例可用),现在我想从一些测试应用程序访问web服务。 有人举过这样的例子吗? 我尝试使用相同的代码来连接windows auth。当然,这是不成功的。 我得到一个错误:

{“在配置的服务器上找不到身份验证终结点Kerberos 安全令牌服务!}

这是连接代码(对于AD身份验证类型):


这之后的错误是:
在配置的安全令牌服务上找不到身份验证终结点用户名

如果您只是使用CRM 2011 web服务界面,我认为索赔甚至都不重要。下面的代码允许be进行身份验证并连接到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();
        }
    }
} 

我终于解决了这个问题。最后,我配置了ADF,并为我的自定义STS添加了中继方信任。现在这一切都很好。API调用通过ADF进行,Web访问身份验证通过自定义STS进行

AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.UserPrincipalName = "user";
authCredentials.ClientCredentials.UserName.UserName = _userName;
authCredentials.ClientCredentials.UserName.Password = _password;
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();
        }
    }
}