gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 15:38:05 25 4
gpt4 key购买 nike

我在我的 CRM 实例上配置了基于声明的身份验证。我正在使用自定义 STS(可用示例 here)现在我想从某个测试应用程序访问 Web 服务。有人有这方面的例子吗?在 Windows 身份验证的情况下,我尝试使用相同的代码进行连接。但是,当然,不成功。我收到一个错误:

{"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 = "P@$$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";

...

authCredentials.ClientCredentials.UserName.UserName = _userName;
authCredentials.ClientCredentials.UserName.Password = _password;

此后的错误是:在配置的安全 token 服务上找不到身份验证端点用户名!

最佳答案

如果您只是使用 CRM 2011 网络服务界面,我认为声明根本不重要。以下代码允许进行身份验证并连接到 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();
}
}
}

关于c# - 如何使用 SDK 连接到 CRM(基于声明的身份验证和自定义 STS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11826612/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com