Gre*_*Oks 2 service credentials discovery dynamics-crm-2011
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);
}
Run Code Online (Sandbox Code Playgroud)
它返回错误消息:
从另一方收到了无担保或不正确安全的故障.请参阅内部FaultException以获取故障代码和详细信息.ID3242:无法对安全令牌进行身份验证或授权.
并在事件查看器中我看到错误:
Account For Which Logon Failed:
Security ID: NULL SID
Account Name: admin
Account Domain:
Failure Reason: Unknown user name or bad password.
Run Code Online (Sandbox Code Playgroud)
虽然我给出了正确的用户名和密码..
如果我试图替换:
using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, null, clientCredentials, null))
Run Code Online (Sandbox Code Playgroud)
有:
using (serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealUri, clientCredentials, null))
Run Code Online (Sandbox Code Playgroud)
它返回:
你调用的对象是空的.
因为serviceProxy为null.
所以,我刚刚开始自己使用ADFS,如果您已经拥有,我建议您阅读Active Directory和基于声明的身份验证.
另外,从查看代码我不认为你的HomeRealmUri是正确的.您似乎已经为其提供了CRM发现服务的地址.如果您只有单个ADFS,我认为您可以将其保留为null.如MSDN中所述.
我原以为它看起来更像是这样的:urn:federation:contoso
对于用户名,我认为您需要指定域,您通常必须使用以下格式:domain @ domain
你可能还想看看这个例子,它是一个与Crm对话的网页上的单一登录,这听起来很像你想要实现的.
祝好运.