web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

DataContract in AX

(0) ShareShare
ReportReport
Posted on by

Hello,

I need some guidelines using DataContract class with [datamember] clauses in Dynamics AX - For Serialization.

Thanks :)

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Denis Macchinetti Profile Picture
    16,444 on at

    Hi Eitan

    Take a look at this blog, sumitsaxfactor.wordpress.com/.../data-contracts-and-custom-services-ax-2012

    Hope can help you.

  • Community Member Profile Picture
    on at

    Can I add datacontract in X++, and in X++:

    1. Search all of the datacontract members.

    2. Run one by one each datamember.

    Can I use the datacontract in C# code, and not just on WCF?

    Thanks :)

  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    1) Use reflection, e.g. DictClass.getAttribute().

    2) I assume that you mean executing a method decorated by the DataMember attribute if you know its name. Again, use reflection, namely DictClass.callObject().

    3) "Can I use the datacontract in C# code?" It depends. When compiling to CIL, X++ data contracts are translated to .NET data contracts. You can use them in your code by a little hack I described in Data contract serialization from X++. On the other hand, attributes are ignored when creating proxy classes from X++ types.

  • Community Member Profile Picture
    on at

    (I cannot see my previous post).

    For the DataMember - It is just nice to use [datamember] in X++ (For writing convention)

    if DictClass.getAttribute() gets the member attributes (and not the methods), so I can use that - Is that what you meant (That DictClass.getAttribute() can retrieve the DataMemberAttribute?

    Thanks :)

  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    No, you're not looking for right attributes on right places.

    Classes are decorated with DataContractAttribute. DataMemberAttribute is used on methods (the reflection class is DictMethod).

  • Community Member Profile Picture
    on at

    I have tried something like:

    DictClass dictClass;
    DictMethod dictMethod;
    int i;
    Array a;
    str s;
    dictClass = new DictClass(classNum(MyClass));
    
    info(int2str(dictClass.objectMethodCnt()));
    for (i=1; i <= dictClass.objectMethodCnt(); i++)
    {
    info(dictClass.objectMethod(i));
    dictMethod = dictClass.objectMethodObject(i);
    a = dictMethod.getAllAttributes();
    if (a && a.lastIndex() > 0) { 
    s = a.definitionString();
    info("def:" + s);
    s = a.xml();
    info("str:" + s);
    }
    info("****");
    }
    

    For [DataMemberAttribute("MyName")]

    I want to output the "MyName" - How can I do that?

    Thanks :)

  • Verified answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    It's trivial.

    getAllAttributes() returns an array of attribute objects. Cast them to DataMemberAttribute and call the Name() method.

  • Community Member Profile Picture
    on at

    Thank you!

    Can I add two or more attributes?

    The specific second attribute is table (name or id).

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    Yes, you can.

  • Community Member Profile Picture
    on at

    I have tried something like:

    [DataMemberAttribute("MyName"),

    DataMemberAttribute("MyTable")]

    That is not compiled.

    Also, is there any attribute like DataMemberAttribute, but for tableId (or name)? What is that attribute, and where can I find all the attribute list (at least, of system)?

    Just want to add attribute(s) with tableName+Name (such as function/field etc.) - Is there any fixed attribute for that?

    Thanks :)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans