简体   繁体   中英

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? Using the CRM 2011 online, I can connect using this code. I believe device ID is hard coded.

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)

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. Also check this article that describes how to use CrmConnection class.

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

/This URL needs to match the servername and Organization for the environment.

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**

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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