Hi there,
I am trying Integration through OData and followed the code from below github link.
https://github.com/Microsoft/Dynamics-AX-Integration/tree/master/ServiceSamples/ODataConsoleApplication
All of my projects are build successfully.(authentication utility , clientconfiguration utility , Odata utility).
But i am getting below error when trying to execute console application project to bring list of legal entities.
An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.OData.Client.dll
Below is the code i am using to bring list of legal entities.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.OData.Client;
using ClientConfigurationUtility;
using ODataUtilityTest.Microsoft.Dynamics.DataEntities;
namespace OdataConsoleApplication
{
class Program
{
public static string ODataEntityPath = ClientConfiguration.Default.UriString + "data";
static void Main(string[] args)
{
Uri oDataUri = new Uri(ODataEntityPath, UriKind.Absolute);
var context = new Resources(oDataUri);
context.SendingRequest2 += new EventHandler<SendingRequest2EventArgs>(delegate (object sender, SendingRequest2EventArgs e)
{
var authenticationHeader = OAuthHelper.GetAuthenticationHeader(useWebAppAuthentication: true);
e.RequestMessage.SetHeader(OAuthHelper.OAuthHeader, authenticationHeader);
});
QueryExamples.ReadLegalEntities(context);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ODataUtilityTest.Microsoft.Dynamics.DataEntities;
namespace OdataConsoleApplication
{
class QueryExamples
{
public static void ReadLegalEntities(Resources d365)
{
foreach (var legalEntity in d365.LegalEntities.AsEnumerable())
{
Console.WriteLine("Name: {0}", legalEntity.Name);
}
}
}
}