连接到MS Dynamics CRM 2011桌面CrmConnection

时间:2014-03-06 17:30:46

标签: c# dynamics-crm-2011

我的客户使用的是Dynamics CRM 2011的托管版,而非在线版。使用我的C#代码,如何获取用户名,密码,URL和设备ID进行身份验证?在线使用CRM 2011,我可以使用此代码进行连接。我相信设备ID是硬编码的。

CrmConnection crmConnection = CrmConnection.Parse(String.Format("Url={0}; Username={1}; Password=   
{2};DeviceID=enterprise-ba9f6b7b2e6d; DevicePassword=passcode;", url, username, password));

OrganizationService service = new OrganizationService(crmConnection);
var xrm = new XrmServiceContext(service);
return xrm;

3 个答案:

答案 0 :(得分:1)

托管版本(OnPremise)依赖于Active Directory身份验证(DOMAIN\USERNAME),因此您需要将Domain添加到连接字符串并删除DeviceIDDevicePassword(他们仅适用于使用LiveId身份验证的CRM Online)

代码将是:

CrmConnection crmConnection =
CrmConnection.Parse(String.Format("Url={0}; Username={1}; Password={2}; Domain={3}", url, username, password, domain));

答案 1 :(得分:0)

尝试删除deviceid和devicepassword。另请检查描述如何使用CrmConnection类的this article

答案 2 :(得分:0)

ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

/此URL需要与环境的服务器名称和组织相匹配。

Uri OrganizationUri = new Uri("http://crm/XRMServices/2011/Organization.svc");
Uri HomeRealmUri = null;

using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
{

    IOrganizationService service = (IOrganizationService)serviceProxy;
    if (Context.User.Identity.IsAuthenticated)
       {
         string EUserName = Context.User.Identity.Name;
          string WinUserName = WindowsIdentity.GetCurrent().Name;
          UserName.InnerText = EUserName;
       }
}


Also add references
**microsoft.crm.sdk.proxy**
**microsoft.xrm.sdk**