Sample code to connect Office 365 users to CRM 2011 online

Sharing a sample code that can be used to connect to CRM 2011 online with Office 365.

// Add refereneces to the following dll
 // microsoft.crm.sdk.proxy
 // microsoft.xrm.sdk
 // system.runtime.serialization
 // system.servicemodel

IServiceManagement<IOrganizationService> orgServiceManagement =
 ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri("https://democrm.api.crm5.dynamics.com/XRMServices/2011/Organization.svc"));

AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.ClientCredentials.UserName.UserName = _userName;
authCredentials.ClientCredentials.UserName.Password = _password;
AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);

OrganizationServiceProxy organizationProxy = new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);
Guid userid = ((WhoAmIResponse)organizationProxy.Execute(new WhoAmIRequest())).UserId;

Bye.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

3 thoughts on “Sample code to connect Office 365 users to CRM 2011 online”

  1. Hi,

    I tried this connecion to CRM online 2015 with office 365 and i get the error: Value cannot be null.\r\nParameter name: identityProvider

    at object:
    AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);

    Do you have any idea

    Like

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s