Created
June 2, 2021 15:54
-
-
Save melamriD365/77f718d9a5802d4d087722d9e6a61d0a to your computer and use it in GitHub Desktop.
Dataverse Sample ConsoleApp Client (oAuth2.0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Crm.Sdk.Messages; | |
using Microsoft.Xrm.Sdk; | |
using Microsoft.Xrm.Sdk.Messages; | |
using Microsoft.Xrm.Sdk.Query; | |
using Microsoft.Xrm.Tooling.Connector; | |
using System; | |
namespace MEA | |
{ | |
class sampleConsoleApp | |
{ | |
static void Main(string[] args) | |
{ | |
CrmServiceClient crmSvc = getOrganizationService(); | |
Console.ReadLine(); | |
} | |
public static CrmServiceClient getOrganizationService() | |
{ | |
CrmServiceClient crmSvc = null; | |
String connectionString = "AuthType=OAuth;[email protected]; Password=passcode;Url=https://contosotest.crm.dynamics.com;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d; RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97;LoginPrompt=Auto" | |
try | |
{ | |
crmSvc = new CrmServiceClient(connString); | |
if (crmSvc != null) | |
{ | |
var whoAmIResponse = ((WhoAmIResponse)crmSvc.Execute(new WhoAmIRequest())); | |
if (whoAmIResponse != null) | |
{ | |
Console.WriteLine("Connection OK...."); | |
Console.WriteLine(whoAmIResponse.UserId); | |
} | |
else | |
{ | |
Console.WriteLine("Connection KO...."); | |
} | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine("ERROR..."); | |
Console.WriteLine(e.Message); | |
} | |
return crmSvc; | |
} | |
} | |
} |
and it does require an azure app hence the RedirectUri=app://
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A number of errors in this code, at least make it usable before publishing it