Hi ,
I am new to AX and OData Service . One of my team mate has provided me link to AX Odata Service deployed on Azure Cloud .
He sent me the following details
1) Azure Login URL
2) Client Id
3) User Name and Password to access the AX OData Service
4) AX OData Service Base URL
Now I have written a simple C# Console Application to call the OData Service to get the list of Entities and then to get the values of an Entity using GET .
My Code looks like this
*********************************************************************************************************
AuthenticationContext authenticationContext = new AuthenticationContext("<Azure Login URL>");
//To pass the user name and password without showing a pop - up, you can use the following overload of AcquireToken.
UserCredential userCred = new UserCredential("USERNAME", "PWD");
AuthenticationResult authenticationResult = authenticationContext.AcquireToken("AX Odata Service URL", "CLIENTID", userCred);
var settings = new ODataClientSettings("AX Odata Service URL");
settings.BeforeRequest = (message) =>
{
message.Headers.Add("Authorization",authenticationResult.CreateAuthorizationHeader());
};
ODataClient client = new ODataClient(settings);
model = client.GetMetadataAsync().ConfigureAwait(false).GetAwaiter().GetResult();
// Written getEntities method which will return all the Objects from the Odata Service URL
List<string> entities = getEntities(model).ToList();
// Now preparing the query to get the records from one of the entity .
var query = client.For("<Entity Name>");
var data = Task.Run(() => query.FindEntriesAsync()).ConfigureAwait(false).GetAwaiter().GetResult();
************************************************************************************
I am using Simple Odata Client to get the entities in the above example.
So using the above program I am able to connect and get the list of entities . But when I call the method
var data = Task.Run(() => query.FindEntriesAsync()).ConfigureAwait(false).GetAwaiter().GetResult();
I am getting 'Un Authorized' Error . I am not sure what I am doing wrong here . I am setting before the request the Authentication as well .
Could you guide me what is wrong (or) a simple code to get the query executed .
If there is any sample program which will read in the records for an Entity please point me to the correct URL .
If you need any more information please do let me know.
Thanks for your help and positive support.
Regards,
Sasi.