Announcements
No record found.
Hello,
I need some guidelines using DataContract class with [datamember] clauses in Dynamics AX - For Serialization.
Thanks :)
*This post is locked for comments
Hi Eitan
Take a look at this blog, sumitsaxfactor.wordpress.com/.../data-contracts-and-custom-services-ax-2012
Hope can help you.
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?
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.
(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?
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).
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?
It's trivial.
getAllAttributes() returns an array of attribute objects. Cast them to DataMemberAttribute and call the Name() method.
Thank you!
Can I add two or more attributes?
The specific second attribute is table (name or id).
Yes, you can.
[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?
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.
Congratulations to our 2026 Super Stars!
We are thrilled to have these Champions in our Community!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Joris dG 5
Alexey Lekanov 2
Henrik Nordlöf 2 User Group Leader