public static void DataverseConnector()
{
try
{
string conn = @"AuthType=OAuth;Username=user@org.onmicrosoft.com;Password=password;Url=https://orgapp.crm.dynamics.com;TokenCacheStorePath=c:\MyTokenCache2;LoginPrompt=Auto";
using (ServiceClient serviceClient = new ServiceClient(conn))
{
if (serviceClient.IsReady)
{
var query = @"<fetch mapping='logical'><entity name='account'><attribute name='accountid'/><attribute name='name'/><attribute name='numberofemployees'/></entity></fetch>";
var recordColl= serviceClient.RetrieveMultiple(new FetchExpression(query));
foreach (var accountrecord in recordColl.Entities)
{
Console.WriteLine(accountrecord.Id);
Console.WriteLine(accountrecord["name"]);
Console.WriteLine(accountrecord["numberofemployees"]);
}
}
else
{
Console.WriteLine("A web service connection was not established.");
}
}
// Pause the console so it does not close.
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
}
No comments:
Post a Comment