Hi,
I'm trying to access images from DocuRef,DocuValue, the following code gives me the filemanagement URI part + access token:
var url = Microsoft.Dynamics.AX.Framework.FileManagement.URLBuilderUtilities::GetDownloadUrl(docuValue.FileId, accessToken);
To complete the URL, I use the following code:
var currentHost = new System.Uri(UrlUtility::getUrl());
var generator = new Microsoft.Dynamics.AX.Framework.Utilities.UrlHelper.UrlGenerator();
generator.HostUrl = currentHost.GetLeftPart(System.UriPartial::Authority);
url = generator.HostUrl + '/' + url;
Problem is, the code is executed as published web service and accessed via Postman. The line
var currentHost = new System.Uri(UrlUtility::getUrl());
throws an error, because sometimes(!) - in 85% of the time, not deterministic reproducible - the code behind
SessionContext serverContext = SessionContext::Get_Current();
returns null.
Is this because AX7 has not really a valid session sometimes when accessed via REST without an actual Web Frontend?
How can this be fixed or is there any other approach to deliver a valid URL to get access to the pictures from outside or maybe even deliver a base64 encoded string via data contract?
best regards and thanks in advance