gpt4 book ai didi

service - CRM 2011使用C#连接到organization.svc

转载 作者:行者123 更新时间:2023-12-03 07:17:11 24 4
gpt4 key购买 nike

CRM 2011 使用 ADFS 和 HTTPS 设置。我正在尝试从自定义网页连接到organization.svc,该网页与CRM 2011位于同一IIS上,但使用以下代码作为不同的网站:

OrganizationServiceProxy serviceProxy;
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "admin";
clientCredentials.UserName.Password = "pass";

Guid contactId = Guid.Empty;

Uri OrganizationUri = new Uri(String.Format("https://organization.crmdev.com:port/XRMServices/2011/Organization.svc"));

Uri HomeRealmUri = new Uri(String.Format("https://organization.crmdev.com:port/XRMServices/2011/Discovery.svc"));

using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, null, clientCredentials, null))
{
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
IOrganizationService service = (IOrganizationService)serviceProxy;
Entity contact = new Entity("contact");
contact.Attributes["lastname"] = "oi oi";
contactId = service.Create(contact);
}

它返回错误消息:

从另一方收到不安全或安全错误的错误。请参阅内部FaultException 了解故障代码和详细信息。ID3242:无法对安全 token 进行身份验证或授权。

在事件查看器中我看到错误:

Account For Which Logon Failed:
Security ID: NULL SID
Account Name: admin
Account Domain:
Failure Reason: Unknown user name or bad password.

虽然我提供了正确的用户名和密码..

如果我尝试替换:

using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, null, clientCredentials, null))

与:

using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealUri, clientCredentials, null))

它返回:

未将对象引用设置为对象的实例。

因为 serviceProxy 为空。

最佳答案

所以,我自己刚刚开始使用 ADFS,我建议阅读 Active Directory and Claims-Based Authentication如果您还没有。

另外,通过查看您的代码,我认为您的 HomeRealmUri 不正确。您似乎已向其提供了 CRM Discovery 服务的地址。我认为如果您只使用单个 ADFS,则可以将其保留为空。如 the MSDN here. 中所述

我希望它看起来更像这样:urn:federation:contoso

对于用户名,我相信您需要指定域,通常必须采用以下格式:username@domain

您可能还想看看这个 example它是网页上与 Crm 对话的单一登录,这听起来很像您想要实现的目标。

祝你好运。

关于service - CRM 2011使用C#连接到organization.svc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11849470/

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