Thursday, September 29, 2011

How to access Microsoft CRM 2011 online organization service using Live ID (Pass port authentication)

Microsoft CRM 2011 online is a widely used online CRM system with wide range of features. Like On promise installation you can access this service and do CRUD operations.
Let’s start.
Below example is for your understand and its up to you to arrange it with better programming concepts. Some part of the code is same as the code which we use for Active Directory Authentication. Additional part in this code is Device Credentials. Please see the code below.

public OrganizationServiceProxy GetOrganizationServiceProxyLive(string organisationName)
{
Uri organizationUri = new Uri(Your CRM Online site + "/XrmServices/2011/Organization.svc");
Uri HomeRealmUri = null;

var service = new OrganizationServiceProxy(organizationUri, HomeRealmUri, GetCredentials(), GetDeviceCredentials());
service.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

service.EnableProxyTypes();
return service;
}

private ClientCredentials GetDeviceCredentials()
{
ClientCredentials Credentials = new ClientCredentials();

Credentials.UserName.UserName = Generated Device Credential Username;
Credentials.UserName.Password = Generated Device Credential Password;

return Credentials;
}

private ClientCredentials GetCredentials()
{
ClientCredentials clientCredentials = new ClientCredentials();

clientCredentials.UserName.UserName = YOUR Live ID;
clientCredentials.UserName.Password = YOUR Live ID Password;

return clientCredentials;

}

Here you can provide your Live ID and Password as client credentials. (Live ID and Password - Which you used to create the CRM online site)
To create Device Credentials, Please follow following steps.
1. Download and install Microsoft Dynamic CRM 2011 SDK
2. Go to following folder in you SDK “Installed folder\sdk\tools\deviceregistration”
3. Open “deviceregistration.sln” and Run
4. DeviceRegistration.exe file will be created “Installed folder\sdk\tools\deviceregistration\bin\Release”
5. Open Command Prompt and got to “Installed folder\sdk\tools\deviceregistration\bin\Release” folder
6. Then type this command - deviceregistration.exe /operation:Register
7. Then is will generate user name and the password for Device Credentials.
8. Copy and Paste this in to your code
private ClientCredentials GetDeviceCredentials()
{
ClientCredentials Credentials = new ClientCredentials();

Credentials.UserName.UserName = Generated Device Credential Username;
Credentials.UserName.Password = Generated Device Credential Password;

return Credentials;
}

Now it's ready to access the Organization Service..