Calling ax class from .net class library using .net clr

Question Status

Verified
Kuppusamy S asked a question on 11 May 2014 10:38 PM

Hi Everyone,

                  I have a requirement to read xml document and pass the values to ax method to create sales order. May I know how to call ax class/method from .net using .net framework? I dont have .net business connector to do this and my Axapta version is 2009. Thank you.

Reply
Gyan Chand Kabra responded on 11 May 2014 10:50 PM

Hi,

You can directly read the XML files from AX. there are certain classes to read the XML files.

Why do you want to call the classes from .net ?

Reply
Kuppusamy S responded on 11 May 2014 11:09 PM

Hi Gyan Chand Kabra,

        It's for integration purpose. I get xml document from web services and I should read each node values and pass it to ax method to create sales order. Whenever a PO is created in other ERP, it triggers a web service and xml document is passed as an argument to .net method from web service and I need to read values of node and pass to ax method to create and post sales order. Thank you.

Reply
Suggested Answer
Nitesh Ranjan responded on 11 May 2014 11:17 PM

You can do this using AIF,

In AX 2009 you need to configure a web service for Sales Order creation.

and you need to deploy that web service on IIS and from .net VS project you need to consume that web service by referencing them

Please follow following link for more details

msdn.microsoft.com/.../bb496535(v=ax.50).aspx

Reply
Kuppusamy S responded on 11 May 2014 11:29 PM

Hi Nitesh,

            Thank you for your reply. Actually I don't wanna use either .net business connector or AIF to perform this process. I have to do only using .net clr in Ax 2009 version. Please suggest me any ideas to do. Thank you.

Reply
Verified Answer
Nitesh Ranjan responded on 11 May 2014 11:47 PM

Please explain what mean when you say .net clr in AX 2009

Do you mean you want to use .net library functions from AX 2009?

if so then,

you need to create dynamic link library in .net and reference it in AX 2009

and then you can use this dynamic link library in X++, by creating object

once you have object then you can call it function.

Please let us know if you are looking about this or provide more information.

Reply
Suggested Answer
Martin Dráb responded on 11 May 2014 11:55 PM

You don't necessarily need .NET to read XML files - you can use XMLDocument class in X++. You can also call .NET classes through the .NET Interop; you can even create a custom class library utilizing frameworks such as LINQ to XML (which would be impossible to use directly from X++). Nevertheless if you can convert the input file to a XML file expected by the integration framework (AIF) in AX, you can let the AIF file system adapter to handle everything for you, so that's the recommend way. It's all the opposite direction than you asked about, but it would be the right approach if your goal was to read a file.

If you actually want to trigger AX business logic from another application (whether the application gets data from files or somewhere else is irrelevant), you should use AIF again, just not the file system service adapter this time. Expose a web service from AX, add a service reference in Visual Studio and call methods of the generated proxy classes. Your other option is the Business Connector, but you're already aware of it. Even AIF web services on IIS (in AX 2009 and older) actually communicate with AX through the Business Connector.

Reply
Kuppusamy S responded on 12 May 2014 12:26 AM

Hi Nitesh,

              Yes, I did as you explained. I created a class library in .net that reads xml document and copied dll file to ax bin folder and added it in AOT - References - Add reference. In Axapta, no action will be triggered to get records( I mean when a record is created in other ERP application, that record is passed as xml document through web service and I need to read it in .net class library and call ax method to create and post sales order).  May I know how to create data in Ax using .net interoperabilty? Please refer the following link http://msdn.microsoft.com/en-us/library/aa868997.aspx I have to do the same using .net interoperabilty. Thank you.

Reply
Kuppusamy S responded on 12 May 2014 12:35 AM

Hi Martin,

           Thank you for your ideas. I would like to know that how to create data in Ax using .net interoperability. I'm told to use only .net clr way to complete this functionality.

Reply
Verified Answer
Martin Dráb responded on 12 May 2014 12:54 AM

.NET Interop from X++ is used to call CLR (= .NET) classes from X++, not the other way around. You can, though, call a .NET method that returns some data and use the data in X++.

As I already said, you have to use web services or the .NET Business Connector to call AX classes from other applications.

Reply
Kuppusamy S responded on 12 May 2014 1:05 AM

Hi Martin,

          Thank you. Let me try to use web services to call Ax class. Thank you again!

Reply
Verified Answer
Nitesh Ranjan responded on 11 May 2014 11:47 PM

Please explain what mean when you say .net clr in AX 2009

Do you mean you want to use .net library functions from AX 2009?

if so then,

you need to create dynamic link library in .net and reference it in AX 2009

and then you can use this dynamic link library in X++, by creating object

once you have object then you can call it function.

Please let us know if you are looking about this or provide more information.

Reply
Verified Answer
Martin Dráb responded on 12 May 2014 12:54 AM

.NET Interop from X++ is used to call CLR (= .NET) classes from X++, not the other way around. You can, though, call a .NET method that returns some data and use the data in X++.

As I already said, you have to use web services or the .NET Business Connector to call AX classes from other applications.

Reply
Suggested Answer
Nitesh Ranjan responded on 11 May 2014 11:17 PM

You can do this using AIF,

In AX 2009 you need to configure a web service for Sales Order creation.

and you need to deploy that web service on IIS and from .net VS project you need to consume that web service by referencing them

Please follow following link for more details

msdn.microsoft.com/.../bb496535(v=ax.50).aspx

Reply
Suggested Answer
Martin Dráb responded on 11 May 2014 11:55 PM

You don't necessarily need .NET to read XML files - you can use XMLDocument class in X++. You can also call .NET classes through the .NET Interop; you can even create a custom class library utilizing frameworks such as LINQ to XML (which would be impossible to use directly from X++). Nevertheless if you can convert the input file to a XML file expected by the integration framework (AIF) in AX, you can let the AIF file system adapter to handle everything for you, so that's the recommend way. It's all the opposite direction than you asked about, but it would be the right approach if your goal was to read a file.

If you actually want to trigger AX business logic from another application (whether the application gets data from files or somewhere else is irrelevant), you should use AIF again, just not the file system service adapter this time. Expose a web service from AX, add a service reference in Visual Studio and call methods of the generated proxy classes. Your other option is the Business Connector, but you're already aware of it. Even AIF web services on IIS (in AX 2009 and older) actually communicate with AX through the Business Connector.

Reply