返回秋毫ERP咨询论坛

- 微软ERP Dynamics AX,Nav,CRM,SL专业论坛,同时包括SAP,Oracle ERP讨论和相关文档下载。



返回本书目录


Previous Page
Next Page

CLR Interoperability

As explained in Chapter 5, "The X++ Programming Language," you can invoke external managed components from Dynamics AX by using CLR interoperability. CLR interoperability can be used from any Dynamics AX kernel, so you can use it from either type of Business Connector included with Dynamics AX 4.0. Why should you consider using CLR interoperability? You might need to invoke functionality provided by an externally managed program during some processing activity in the Business Connector, and rather than invoke the managed program on the AOS, you could choose to exploit the processing capacity of the Business Connector, especially if it is located on a separate machine.

The diagram in Figure 8-10 shows how CLR interoperability works from the .NET Business Connector.

Figure 8-10. Invoking externally managed components from the .NET Business Connector using CLR interoperability.


In this scenario, a bicycle distributor has purchased a third-party managed component, called ThirdPartyUtilities, that contains the business logic necessary to validate an account number. The managed component must be integrated into the Dynamics AX application, which processes account information by using the Business Connector.

The following steps illustrate the use of CLR interoperability from within the .NET Business Connector for enabling the ThirdPartyUtilities managed component:

1.
Create a reference in the AOT under the References node so that Dynamics AX recognizes the third-party component. You can do this by adding a new reference item in the AOT, opening it, and browsing for the .dll file. Save the reference after the required information has been provided.

2.
Create an X++ class, called ProcessingManager, that invokes a method in the managed component by using the CLR interoperability feature. This requires you to instantiate the class that you will use in the ThirdPartyUtilities component, called ValidationManager, and then invoke the appropriate method, called validateAccNum, in that class with a parameter that represents the data to be validated, called inboundAccNum, and return the result, as shown here.

static boolean validateAccNum(inboundAccNum)
{
    ThirdPartyUtilities.ValidationManager valMgr = new
        ThirdPartyUtilities.ValidationManager();
    boolean validationResult;
    ;
    validationResult = valMgr.validateAccNum
(inboundAccNum);

    return validationResult;
}


3.
In the managed application, add code in the appropriate place to invoke the X++ method in ProcessingManager and provide the account number to validate, as shown here.

returnValue = ax.CallStaticClassMethod
("ProcessingManager",
                            "validateAccNum",
                            inboundAccNum);


At run time, the managed application invokes the validateAccNum X++ method in the ProcessingManager class, which then instantiates the CLR object from the Business Connector and returns a Boolean result. By default, the X++ methods execute from the location where they are called, which in this case is the Business Connector. Therefore, the processing associated with this request is performed in the interpreter within the Business Connector, rather than in the AOS.


Previous Page
Next Page