Credentials,tokens sample in Microsoft CRM 2011 from SDK by Late Bind Approach with IFDS deployment


First of all, Download Microsoft CRM 2011 SDK from Microsoft Web Site.Please ask
google for exact URLs.

do not forget adding Microsoft.xrm.sdk library from SDKs.

IServiceManagement orgServiceManagement =

ServiceConfigurationFactory.CreateManagement( new Uri("http(s)://crm.???.com(:444)/organization_name/XRMServices/2011/Organization.svc"));

Set the credentials.
AuthenticationCredentials authCredentials = new AuthenticationCredentials();

authCredentials.ClientCredentials = new ClientCredentials();
authCredentials.ClientCredentials.UserName.UserName = "muhammet.atalay";
authCredentials.ClientCredentials.UserName.Password = "I Love CRM";

AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);
Retrieve Token
SecurityTokenResponse orgTokenResponse = null;
if (tokenCredentials != null)
if (tokenCredentials.SecurityTokenResponse != null)
orgTokenResponse = tokenCredentials.SecurityTokenResponse;

if (orgServiceManagement == null)
throw new ArgumentNullException("serverConfiguration.OrganizationServiceManagement");

if (orgServiceManagement != null && orgTokenResponse != null)
_serviceProxy = new OrganizationServiceProxy(
Obtain the organization service proxy for the ActiveDirectory environment.
_serviceProxy = new OrganizationServiceProxy( orgServiceManagement, authCredentials.ClientCredentials);

Early bound needs creating class from Microsoft CRM 2011 do this use crmsvcutil.exe which comes from CRM SDK (...SDK\bin\).
Built Class includes both standart Entities and Custom Entities.
Usage : crmsvcutil.exe /url:http(s)://crm.???.com(:444)/company_name/XRMServices/2011/Organization.svc /out:"\OrganizationCodes.cs " /username:muhammet.atalay /password:ILoveCrm /domain:??? /serviceCon textName:...ServiceContext
you can add OrganizationCodes.cs file to the solution.
ServiceContext uses as below.
ServiceContext context;
context = new ServiceContext((IOrganizationService)_serviceProxy);

} hopes it is helpfull. Please do not hesitate to ask or leave message .


  1. This similar method I have tried but get below error - CRM (on Premise)

    tokenCredentials = orgServiceManagement.Authenticate(authCredentials);

    responseToken = tokenCredentials.SecurityTokenResponse;

    is getting below error "Value cannot be null.

    Parameter name: securityTokenResponse".

    For all deployments other than on-premises (Active Directory, without claims), the Authenticate method is invoked and then the service proxy is instantiated. Do this above method only work for Active Directory, without claims not for on premise.


Post a comment

Popular posts from this blog

Assembly Microsoft.Dynamics.Service.Plugins.dll can not be loaded. Dynamics CRM 365 Engine version 9 - CRM User creation error

Exception caught instantiating TERADATA report server extension SQL Reporting Services

Could not load file or assembly 'System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified at Configuration class initiation in