Reputation: 121
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;
Upvotes: 1
Views: 2352
Reputation: 2123
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**
Upvotes: 0
Reputation: 15128
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));
Upvotes: 1
Reputation: 5446
Try just delete deviceid and devicepassword. Also check this article that describes how to use CrmConnection class.
Upvotes: 0