Inside Dynamics AX 4.0: Working with the .NET Business Connector
This section takes a closer look at building applications with the .NET Business Connector, including the following topics:
The .NET Business Connector makes it easier to develop managed applications that integrate with Dynamics AX by bridging two programming environments: the managed .NET Framework environment and the unmanaged Dynamics AX X++ environment. Inevitably, some form of translation is required when passing objects and data between these two environments. In below maps equivalent data types between .NET and Dynamics AX.
Data Type Mappings
The Business Connector managed class methods explicitly support specific data types for parameters and return values. Refer to the Microsoft Dynamics AX SDK for more information.
This section provides an overview of the managed classes in the .NET Business Connector. You develop applications with the .NET Business Connector by instantiating and using the public managed classes described in below table.
.NET Business Connector Managed ClassesExamples of how these classes are used in an application are provided in the following sections.
Request and Response Processing
Much like any integration component, the Business Connector processes requests and returns responses associated with the use of the managed classes by applications across all the established Business Connector user sessions.
The diagram shown in below image depicts the processing steps associated with a request made through the managed classes.
Request processing in the .NET Business Connector.Response Processing
The diagram shown in below image depicts the processing steps associated with generating a response.
Response processing in the .NET Business Connector
The main variation in the request and response cycle is the location where the X++ code being invoked is executed. This is controlled by the declaration associated with the X++ code. By default, the X++ code runs where calledthat is, from the interpreter where it is invoked. If the client keyword is used, this forces execution on either the Business Connector or the Dynamics AX client. If the server keyword is used, the code is executed by the AOS.
The .NET Business Connector has a large set of managed exceptions that can be raised at run time. Although it was originally based on the errors in the COM Business Connector, this set of managed exceptions has been extended in Dynamics AX 4.0 to provide improved granularity, and therefore more flexibility, in handling those exceptions. Most notable is the addition of several remote procedure call (RPC)related exceptions, which you can use to control error handling associated with the connectivity between the Business Connector and the AOS. As a general rule, unhandled exceptions (such as OutOfMemoryException) are not caught by the Business Connector. This type of exception is simply propagated to the calling application and prevents such unhandled exceptions from being masked or hidden by the Business Connector.
A new exception has been added in Dynamics AX 4.0 that provides a consistent way to manage AOS failures. If the AOS to which the .NET Business Connector currently has affinity becomes inaccessible, a BusinessConnectorInstanceInvalidException exception is raised for every call to a method in the managed classes thereafter. This exception can then be used to take other actions, such as terminating the process so it can be restarted.
Refer to the Microsoft Dynamics AX SDK for more information on the data types, managed classes, and managed exceptions referenced in this section.
How do you write C# code that uses the .NET Business Connector? The simple example that follows (the Business Connector equivalent of "Hello World") demonstrates logging on to Dynamics AX. To use the following code, you must be able to log on successfully using the AX client. Also, the .NET Business Connector must be installed from wherever you will execute the code. Create a new project in Microsoft Visual Studio. In the New Project dialog box, select Console Application under Visual C#. This creates the project file structure and files and presents you with a program called Program.cs. Paste the code in the following example between the curly brackets associated with the Main method. In Solution Explorer, right-click References and choose Add Reference. In the Add Reference dialog box, click the Browse tab. Use the file controls to navigate to the Dynamics AX Client\Bin folder. Select Microsoft.Dynamics.BusinessConnectorNet.dll, and then click OK. This makes the .NET Business Connector accessible to the C# application. Now you can build and run the solution.
First, you must instantiate the Axapta class to authenticate, using one of the methods within the Axapta class. Authentication is accomplished by using the Logon() method. If you do not provide any explicit parameter values, the following values, which can be overridden as needed, are used:
To access data in Dynamics AX, you must use the AxaptaRecord class. The following example shows how to retrieve a list of bike-related inventory items that are classified as "raw material."
Here are the important aspects of the code example:
Invoking Business Logic
In addition to accessing data, you can also invoke business logic defined in Dynamics AX directly from the .NET Business Connector. In this example, you call a method in an X++ class to update inventory item details in Dynamics AX based on data from a separate inventory management system. To do this, you use the CallStaticClassMethod method in the Axapta managed class, as shown in this code.
The X++ class returns a Boolean result in this case, which is then used to determine the next action in the application.
As you can see from these examples, developing applications that integrate with Dynamics AX using the .NET Business Connector is relatively straightforward. Although real applications would use the managed classes more extensively, the approach to accessing data and invoking business logic remains the same.
</img> </img> </img> </img> </img>
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
|ax4.0, business connector|
|Arijit Basu: DAX 4.01 .NET Business Connector: Microsoft.Dynamics.BusinessConnectorNet||Blog bot||DAX Blogs||3||30.09.2008 01:17|
|Inside Dynamics AX 4.0: Usage Scenarios||Blog bot||DAX Blogs||0||04.10.2007 05:15|
|Inside Dynamics AX 4.0: Inside the Business Connector||Blog bot||DAX Blogs||0||04.10.2007 05:15|
|Inside Dynamics AX 4.0: The Business Connector||Blog bot||DAX Blogs||0||02.10.2007 04:49|
|ALEG: Проект "Фишка недели" и первый пост - Microsoft Dynamics™ AX .NET Business Connector||Blog bot||DAX Blogs||1||22.11.2006 09:43|
|Опции темы||Поиск в этой теме|