简体   繁体   English

连接到MS Dynamics CRM 2011桌面CrmConnection

[英]Connect to MS Dynamics CRM 2011 Desktop CrmConnection

My client is using the hosted edition, and not the online version, of Dynamics CRM 2011. Using my C# code, how would I obtain the user name, password, URL and device ID to authenticate? 我的客户端使用的是Dynamics CRM 2011的托管版本,而不是在线版本。如何使用C#代码获取用户名,密码,URL和设备ID进行身份验证? Using the CRM 2011 online, I can connect using this code. 通过在线使用CRM 2011,我可以使用此代码进行连接。 I believe device ID is hard coded. 我相信设备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;

Hosted version (OnPremise) relies on Active Directory authentication ( DOMAIN\\USERNAME ), so you need to add Domain to your connection string and remove DeviceID and DevicePassword (they are necessary only for CRM Online using LiveId authentication) 托管版本(OnPremise)依赖于Active Directory身份验证( DOMAIN\\USERNAME ),因此您需要将Domain添加到连接字符串中,并删除DeviceIDDevicePassword (只有使用LiveId身份验证的CRM Online才需要它们)

The code will be: 该代码将是:

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

Try just delete deviceid and devicepassword. 尝试仅删除deviceid和devicepassword。 Also check this article that describes how to use CrmConnection class. 还请检查本文介绍如何使用CrmConnection类。

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

/This URL needs to match the servername and Organization for the environment. /此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**

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM