Sitemap
1 min readDec 19, 2021

Hi Andy, I will update my code that will support the latest connection method recommended by Microsoft. Meanwhile you can use below code:

CrmServiceClient crmConn = null;

// Get the CRM connection string and connect to the CRM Organization

IOrganizationService service = null;

string URL = <URL>;

string userName = <Username>;

string password = <Password>;

string AuthType =OAuth ;

//if you are using App password then add AuthType=Office365

try

{

string conn = $@"Url = {URL};AuthType = {AuthType};UserName = {userName};Password = {password};AppId = 51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri = app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Auto;RequireNewInstance = True";

var svc = new CrmServiceClient(conn);

service = svc.OrganizationWebProxyClient != null ? svc.OrganizationWebProxyClient : (IOrganizationService)svc.OrganizationServiceProxy;

if (service != null)

{

Guid userid = ((WhoAmIResponse)service.Execute(new WhoAmIRequest())).UserId;

if (userid != Guid.Empty)

{

log.Info("Connection Established Successfully...");

}

}

else

{

log.Info("Failed to Established Connection!!!");

}

}

catch (Exception ex)

{

log.Info("Exception caught - " + ex.Message);

}

return service;

Amit Prajapati
Amit Prajapati

Written by Amit Prajapati

I am Technical Consultant from Mumbai, India. I like to contribute my knowledge to the community and good social cause.

No responses yet