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


Hi,

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(
orgServiceManagement,
orgTokenResponse);
}
else
{
Obtain the organization service proxy for the ActiveDirectory environment.
_serviceProxy = new OrganizationServiceProxy( orgServiceManagement, authCredentials.ClientCredentials);
}

_serviceProxy.EnableProxyTypes();
Early bound needs creating class from Microsoft CRM 2011 deployment.to 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 .

Comments

  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.

    ReplyDelete

Post a Comment

Popular posts from this blog

Complex Query in QueryExpression in Microsoft CRM 2011

Exception caught instantiating TERADATA report server extension SQL Reporting Services

Microsoft Power Apps Portal integration with Dynamics 365 CE On-Premise - Step By Step Guide