1
votes

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;
3

3 Answers

1
votes

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));
0
votes

Try just delete deviceid and devicepassword. Also check this article that describes how to use CrmConnection class.

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