Service CRM 2011使用C连接到organization.svc#
CRM 2011是使用ADFS和HTTPS设置的。我正在尝试从自定义网页连接到organization.svc,该网页与CRM 2011位于同一IIS上,但作为不同的网站,使用以下代码:Service CRM 2011使用C连接到organization.svc#,service,dynamics-crm-2011,credentials,discovery,Service,Dynamics Crm 2011,Credentials,Discovery,CRM 2011是使用ADFS和HTTPS设置的。我正在尝试从自定义网页连接到organization.svc,该网页与CRM 2011位于同一IIS上,但作为不同的网站,使用以下代码: IDiscoveryService discoveryService = new DiscoveryServiceProxy(discoveryUri, null, userCredentials, null); RetrieveOrganizationRequest orgReque
IDiscoveryService discoveryService = new DiscoveryServiceProxy(discoveryUri, null, userCredentials, null);
RetrieveOrganizationRequest orgRequest =
new RetrieveOrganizationRequest()
{
UniqueName = "organization name",
AccessType = EndpointAccessType.Default,
Release = OrganizationRelease.Current
};
RetrieveOrganizationResponse org =
(RetrieveOrganizationResponse)discoveryService.Execute(orgRequest);
OrganizationServiceProxy-serviceProxy;
ClientCredentials ClientCredentials=新的ClientCredentials();
clientCredentials.UserName.UserName=“admin”;
clientCredentials.UserName.Password=“通过”;
Guid contactId=Guid.Empty;
Uri OrganizationUri=新Uri(String.Format(“https://organization.crmdev.com:port/XRMServices/2011/Organization.svc"));
Uri HomeRealmUri=新Uri(String.Format(“https://organization.crmdev.com:port/XRMServices/2011/Discovery.svc"));
使用(serviceProxy=neworganizationserviceproxy(OrganizationUri,null,clientCredentials,null))
{
serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(新的ProxyTypesBehavior());
IOrganizationService=(IOrganizationService)服务代理;
实体联系人=新实体(“联系人”);
contact.Attributes[“lastname”]=“oi oi”;
contactId=服务。创建(联系人);
}
它返回错误消息:
从另一方收到未担保或未正确担保的故障。请参阅内部FaultException以了解故障代码和详细信息。ID3242:无法对安全令牌进行身份验证或授权
在事件查看器中,我看到错误:
Account For Which Logon Failed:
Security ID: NULL SID
Account Name: admin
Account Domain:
Failure Reason: Unknown user name or bad password.
虽然我给出了正确的用户名和密码
如果我试图替换:
使用(serviceProxy=new-OrganizationServiceProxy(OrganizationUri,null,clientCredentials,null))
与:
使用(serviceProxy=new-OrganizationServiceProxy(OrganizationUri、HomeRealUri、clientCredentials、null))
它返回:
对象引用未设置为对象的实例
因为serviceProxy是空的。所以,我自己才刚刚开始使用ADFS,我建议您阅读一下,如果您还没有 从你的代码来看,我认为你的HomeRealmUri是不对的。您似乎已为其提供了CRM发现服务的地址。我认为如果你只有一个ADF在使用中,你可以将它保留为空。如中所述 我本来希望它看起来更像这样:urn:federation:contoso 对于用户名,我认为您需要指定域,通常必须使用以下格式:username@domain 您可能还想看看这一点,这是一个与Crm对话的单一登录网页,听起来很像您试图实现的目标
祝你好运。我终于明白了:) 我缺少“/organization”,这意味着organizationUri应该是:
Uri OrganizationUri = new Uri(String.Format("https://organization.crmdev.com:port/organization/XRMServices/2011/Organization.svc"));
当我使用这段代码时,我发现了这一点:
IDiscoveryService discoveryService = new DiscoveryServiceProxy(discoveryUri, null, userCredentials, null);
RetrieveOrganizationRequest orgRequest =
new RetrieveOrganizationRequest()
{
UniqueName = "organization name",
AccessType = EndpointAccessType.Default,
Release = OrganizationRelease.Current
};
RetrieveOrganizationResponse org =
(RetrieveOrganizationResponse)discoveryService.Execute(orgRequest);
并查看了组织在Uri中包含“/组织”的端点 它有助于将用户名写为“username@domain“它确实对用户进行了身份验证:),但现在当我尝试使用服务代理检索某个实体时出现了新的异常:访问被拒绝:(该用户在CRM中有权限吗?我在clientCredentials.UserName.UserName中输入的用户凭据是ideas的CRMOut管理员帐户的凭据,那么我很抱歉谢谢James,你的回答帮了我一半忙:)它是如此的琐碎和愚蠢,以至于我敢打赌你会觉得自己真的很愚蠢,因为你被困在上面好几天了……;)