Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Returning .NET Diction...
Finance forum

Returning .NET Dictionary<> Object from Service Operation Endpoint

(0) ShareShare
ReportReport
Posted on by 648

I have a D365FO Service Operation endpoint that I am trying to return an ArrayList of .NET Dictionary<string, object> objects that will be consumed by an external .NET service. If I call the method from within D365FO, it returns the ArrayList of objects correctly but if I call this endpoint from an external service I get the following error.

f4.png

Here is how the project is set up:

D365FO Project

   - X++ Project

   - .NET Project

Example call would be process as follows:

- External service hits X++ service operation endpoint

- Gets passed to .NET intermediate class for business logic

    - This is where the ArrayList of .NET Dictionary<string, object> objects is created

- ArrayList of .NET Dictionary<string, object> objects gets returned to X++ service operation endpoint to be returned to external service

    - This is where the error occurs

External Service .NET code I am using to call the Service Operation endpoint:

using (var client = new HttpClient())
{
...
var response = await client.PostAsync($"api/Services/{serviceGroupName}/{serviceName}/{methodName}", new StringContent(JsonConvert.SerializeObject(requestBody))).ConfigureAwait(false);
}


This code works for other service operation endpoints I have created and am calling so I believe this code to be correct.

From the error it looks like the Service Operations service is trying to serialize the returned object before handing it off to the external service and hitting a cast exception. Since I'm not doing any explicit casts I'm guessing the service is doing it somewhere outside of my control.

I know that AX/D365FO has Maps which is the X++ equivalent of .NET Dictionary (docs.microsoft.com/.../x-csharp-comparison-collections-of-keys-with-values) the only reason I didn't go this route at first is that at the end of this my external .NET application needs this data in IEnumerable<Dictionary<string, object>> format and wasn't sure if there was a conversion between the two?

Are there any other options or anything else I'm missing?

  • Verified answer
    alexmeyer.itguy Profile Picture
    648 on at
    RE: Returning .NET Dictionary<> Object from Service Operation Endpoint

    It turns out a couple of the objects I was adding to the dictionary were X++ utcdatetime objects, apparently the serializer doesn't like that. Once these were converted to be all .NET based objects everything worked fine as described above.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans