How to connect to Crm Dynamics On Premis 2016 with Consol App


private static void ConnectToCRM()
{
try
{
string OrganizationURL = ConfigurationManager.AppSettings["OrganizationURL"];
OrganizationURL += "/XRMServices/2011/Organization.svc";
_orgServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(OrganizationURL));
ClientCredentials Credentials = new ClientCredentials();
Credentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;
_service = new OrganizationServiceProxy(_orgServiceManagement, Credentials);
//LogHelper.Info("\r\nConnected to {0}\r\n ", OrganizationURL);
WhoAmIRequest req = new WhoAmIRequest();
WhoAmIResponse resp = (WhoAmIResponse)_service.Execute(req);
// LogHelper.Info("User ID: " + resp.UserId);
//Guid currentUserId = resp.UserId;
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine("An error occured trying to connect to the MS CRM Server.\nPlease verify your login data.");
Console.WriteLine(ex.Message);
}
}
app.config file



<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<appSettings>
<add key="OrganizationURL" value="http://crmUrl/Organization/" />
</appSettings>
</configuration>

Commentaires

Posts les plus consultés de ce blog

MS CRM Dynamics : Label in the form

Make CRM Faster

Quick Create, open created record