Hi, I've defined some data contract classes in AX (through the DataContractAttribute) and now I would like to serialize / deserialize these to and from an xml-string. From within AX (x++). Should be fairly easy, but I don't seem to find the code that does the trick.
Anyone any suggestions ?
Tx !!
*This post is locked for comments
Hi Martin,
This is great, you got this thing to work ! I knew it should be possible, but I didn't get there... I have to admit, I eventually started writing a serializer in x++ (which was not that hard after all), but this is a way better solution.
Took me a while to answer your comment, since I wanted to verify the solution. But it works like a charm.
Tx !
I think that looking for "a piece of existing code" is a wrong approach here. You should be rather prepared to do some research and development.
Nevertheless find a solution in Data contract serialization from X++.
I have no controller involved in my process, but if I understand your suggestion correctly, you suggest to fill the data contract from code, but that's actually the same as writing your own deserializer.
I'm looking for a piece of 'existing' code in which I can pass any XML and I expect it to fill any DataContract.
Code should then look someting like this:
AifCurrencyInfo dc = new AifCurrencyInfo();
System.Runtime.Serialization.DataContractSerializer ser;
System.Type dcType;
dc.parmCurrencyCode("EUR");
dcType = CLRInterop::getType('Dynamics.Ax.Application.AifCurrencyInfo');
ser = new System.Runtime.Serialization.DataContractSerializer(dcType);
ser.WriteObject(writer, dc);
writer.Close();
But unfortunately doesn't work :)
'Dynamics.Ax.Application.AifCurrencyInfo' is not known in x++. CIL does not recognize it either. Adding the Dynamics.Ax.Application.dll to the bin-dir doesn't seem like a good solution
and even then, how to convert from AifCurrencyInfo to 'Dynamics.Ax.Application.AifCurrencyInfo' ? Although that might be automatically, once in CIL ...
Hi,
Do you have a controller class also playing some role in the process? You can override the prePromptModifyContract method of your controller class to read the XML and set the values of the data contract members.
I am not sure if I understood your problem correctly.
Thanks,
Rachit Garg
I suspect that AX actually never uses that from X++. When a data contract class is compiled to CIL, DataContractAttribute defined in X++ is converted to System.Runtime.Serialization.DataContractAttribute. This allows AX components (such as the ones integrating AX with WCF) to use the usual .NET DataContractSerializer. I would utilize the same approach, although doing it from X++ may be a bit awkward, but still better than writing your own serializer.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,902 Super User 2024 Season 2
Martin Dráb 229,297 Most Valuable Professional
nmaenpaa 101,156