28.10.2006, 16:40 | #1 |
Участник
|
Dynamics AX: Make use of DotNet Assemblies from DAX 4.0
Источник: http://dynamics-ax.blogspot.com/2006...-from-dax.html
============== As part of my AIF series of post, I thought that it would only be right to prepend and post about how to make native .Net assembly calls from DAX 4.0 X++ code. This is a great addition to DAX, being able to take given .Net assemblies and create objects from classes, and make use of .Net code through native references and X++ code, rather than through COM. With that said, let's jumpe right in and Talk about what it takes to make use of a .Net assembly from within Dynamics AX 4.0. (1) First the given .Net assembly must be a signed one. Meaning that it must have a public token associated with it. (2) Second the assembly needs to be installed into the GAC Once you are for sure these two are done next is creating a reference within DAX. From the AOT you can go to close to the bottom and you will see references. From there right click and add a reference. The reference form will pop up and you will have to click on the browse button and select your .DLL .Net Assembly. Once the reference is made, then you can move on to creating code that makes use of the given .Net assembly. I say start with a new job. ONce you have the new job created, add code that looks similar to this: static void DotNetIntegration(Args _args) { DotNetAssembly.DNClass DNC; str s; CLRObject clrDNC; ; clrDNC = new DotNetAssembly.DNClass(); DNC = clrDNC; s = DNC.DNMethod("Test"); info(strfmt("%1",s)); } Now to speak a little bit about this code. The first line DotNetAssembly.DNClass DNC; Is a declaration that makes use of the Referenced Assembly, and one of it's exposed classes. Next we have a standard str s declaration, and then what makes the interaction possible, the CLRObject declaration. From there we move on to the execution of code, which shows the following line first: clrDNC = new DotNetAssembly.DNClass(); This line is very important, in that it creates a new instance of the clrDNC CLRObject class. What you have to realize at this point is that all .Net Assembly Classes are CLRObjects, and therefore must be created as so. Notice the next line is we set the newly created clrDNC object and make the DNC object equal to that. By doing this we get the look ahead ability to view the methods within the .Net assembly, for example the line of code: s = DNC.DNMethod("Test"); So you can take any .Net assembly, make sure the assembly is signed and installed into the GAC, and then make use of the CLRObjects you can interact with Dot Net with native X++ calls, without having to make use of COM. Check back soon for more! Find a job at: www.DynamicsAXJobs.com ============== Источник: http://dynamics-ax.blogspot.com/2006...-from-dax.html |
|
|
|