>

Category Archives: AIF

How to Integrate AX 2012 with Other Applications

You can use the following methods to integrate Microsoft Dynamics AX with other applications:

1- Services and the Application Integration Framework

Services are the preferred option for integration with Microsoft Dynamics AX. Services in Microsoft Dynamics AX are used to expose its functionality through WCF-based services. Microsoft Dynamics AX code and external applications can consume Microsoft Dynamics AX services. AIF supports the processing of inbound and outbound messages such as message transforms and value lookups. Together, services and AIF provide the programming model, tools, and infrastructure support for XML-based integration with external applications and data

 2- .NET interop to X++

You can use the .NET interop to X++ feature to call X++ code using C# or another managed language. A proxy is an automatically generated .NET class, in C# or another managed language, that mimics an X++ class of Microsoft Dynamics AX.

3- .NET interop from X++

The .NET interop from X++ (also known as the CLR Interop in the previous release) provides interoperability with external .NET components and you can execute managed-code components from within X++ code. .NET interop from X++ is useful when you want your X++ code to access functionality provided by a CLR-managed assembly. This includes assemblies that are installed with the .NET Framework and any assemblies that you create with a language such as C# or Visual Basic.NET.

4- Consume external web services

You can use the Microsoft Dynamics AX programming model to consume external web services from within X++ code. To consume an external web service from X++, you must first create a reference to the web service. After creating a reference to the web service, you can invoke it from X++
and view the available methods with IntelliSense. Calling and managing external web services is done completely within Microsoft Dynamics AX.

The following figure shows how the AIF integration components interact with Microsoft Dynamics AX through the AOS.

image

How to create an item using ( AIF ) ItemServices and EcoResProductServices in AX 2012

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.ServiceModel.Description;

using System.Text;

using Tutorial.AIF.CreateItem.EcoResProductServices;

using Tutorial.AIF.CreateItem.InventItemServices;

 

namespace Tutorial.AIF.CreateItem

{

class Program

{

static void Main(string[] args)

{

try

{

ItemServiceCreateRequest request = new ItemServiceCreateRequest();

ItemServiceClient client = new ItemServiceClient();

 

EcoResProductServiceCreateRequest prodRequest = new EcoResProductServiceCreateRequest();

EcoResProductServiceClient prodClient = new EcoResProductServiceClient();

 

ReqItemTableServiceCreateRequest reqItemRequest = new ReqItemTableServiceCreateRequest();

ReqItemTableServiceClient reqItemClient = new ReqItemTableServiceClient();

 

reqItemRequest.CallContext = new InventItemServices.CallContext();

reqItemRequest.CallContext.Company = "CAD";

reqItemRequest.CallContext.Language = "en-us";

reqItemRequest.CallContext.MessageId = Guid.NewGuid().ToString();

 

prodRequest.CallContext = new EcoResProductServices.CallContext();

prodRequest.CallContext.Language = "en-us";

prodRequest.CallContext.Company = "CAD";

prodRequest.CallContext.MessageId = Guid.NewGuid().ToString();

request.CallContext = new Tutorial.AIF.CreateItem.InventItemServices.CallContext();

request.CallContext.Language = "en-us";

request.CallContext.Company = "CAD";

request.CallContext.MessageId = Guid.NewGuid().ToString();

 

AxdEntity_Product_EcoResProduct[] ecoResProduct = new AxdEntity_Product_EcoResProduct[1];

ecoResProduct[0] = new AxdEntity_Product_EcoResDistinctProduct();

ecoResProduct[0].ProductType = AxdEnum_EcoResProductType.Item;

ecoResProduct[0].SearchName = "68727900121";

ecoResProduct[0].DisplayProductNumber = "ITEM002";

 

AxdEntity_Translation prodTranslation = new AxdEntity_Translation();

prodTranslation.Name = "ITEM002";

prodTranslation.LanguageId = "en-us";

 

ecoResProduct[0].Translation = new[] { prodTranslation };

 

 

AxdEntity_Identifier identifier = new AxdEntity_Identifier();

identifier.ProductNumber = "68727900121";

 

ecoResProduct[0].Identifier = new AxdEntity_Identifier[1];

ecoResProduct[0].Identifier[0] = identifier;

 

 

AxdEcoResProduct product = new AxdEcoResProduct();

product.Product = ecoResProduct;

 

prodClient.Open();

Tutorial.AIF.CreateItem.EcoResProductServices.EntityKey[] keys = prodClient.create(prodRequest.CallContext, product);

prodClient.Close();

 

AxdEntity_InventTable[] inventTable = new AxdEntity_InventTable[1];

inventTable[0] = new AxdEntity_InventTable();

inventTable[0].ItemId = "ITEM002";

inventTable[0].NameAlias = "ITEMNAMEALIAS";

inventTable[0].Product = "ITEM002";

//inventTable[0].Product = keys[0].KeyData[0].Value.Trim();

 

inventTable[0].StorageDimensionGroup = new[] { new AxdEntity_StorageDimensionGroup { StorageDimensionGroup = "DEF", ItemId = inventTable[0].ItemId } };

inventTable[0].TrackingDimensionGroup = new[] { new AxdEntity_TrackingDimensionGroup { TrackingDimensionGroup = "DEF", ItemId = inventTable[0].ItemId } };

inventTable[0].InventModelGroupItem = new[] { new AxdEntity_InventModelGroupItem { ModelGroupId = "DEF", ItemId = inventTable[0].ItemId } };

inventTable[0].InventItemGroupItem = new[] { new AxdEntity_InventItemGroupItem { ItemGroupId = "ALL", ItemId = inventTable[0].ItemId } };

 

//if you want to insert reqItemTable (item coverage settings) you need to create a service for that

//INVENTDIMID

inventTable[0].InventItemPurchSetup = new[] {

new AxdEntity_InventItemPurchSetup {

//HERE WE WILL ADD ORDER SPECIFIC SETTINGS FOR THIS PARTICULAR ITEM

ItemId = inventTable[0].ItemId,

InventDimPurchSetup = new AxdEntity_InventDimPurchSetup[] {

new AxdEntity_InventDimPurchSetup() {

InventDimId = "AllBlank"

}

},

DefaultInventDimPurchSetup = new [] {

new AxdEntity_DefaultInventDimPurchSetup() {

InventDimId = "AllBlank",

InventSiteId = "MTL-01"

}

}

},

//HERE WE WILL ADD SITE SPECIFIC SETTINGS FOR THIS PARTICULAR ITEM

new AxdEntity_InventItemPurchSetup {

ItemId = inventTable[0].ItemId,

InventDimPurchSetup = new AxdEntity_InventDimPurchSetup[] {

new AxdEntity_InventDimPurchSetup() {

InventSiteId = "MTL-01"

}

},

DefaultInventDimPurchSetup = new [] {

new AxdEntity_DefaultInventDimPurchSetup() {

InventLocationId = "01"

}

}

},

};

 

 

inventTable[0].InventItemSalesSetup = new[] {

new AxdEntity_InventItemSalesSetup {

ItemId = inventTable[0].ItemId,

InventDimSalesSetup = new AxdEntity_InventDimSalesSetup[] {

new AxdEntity_InventDimSalesSetup() {

InventDimId = "AllBlank"

}

},

DefaultInventDimSalesSetup = new [] {

new AxdEntity_DefaultInventDimSalesSetup() {

InventDimId = "AllBlank",

InventSiteId = "MTL-01"

}

}

 

},

new AxdEntity_InventItemSalesSetup {

ItemId = inventTable[0].ItemId,

InventDimSalesSetup = new AxdEntity_InventDimSalesSetup[] {

new AxdEntity_InventDimSalesSetup() {

InventSiteId = "MTL-01"

}

},

DefaultInventDimSalesSetup = new [] {

new AxdEntity_DefaultInventDimSalesSetup() {

InventLocationId = "01"

}

}

 

}

};

 

inventTable[0].InventItemInventSetup = new[] {

new AxdEntity_InventItemInventSetup {

ItemId = inventTable[0].ItemId,

InventDimInventSetup = new AxdEntity_InventDimInventSetup[] {

new AxdEntity_InventDimInventSetup() {

InventDimId = "AllBlank"

}

},

DefaultInventDimInventSetup = new [] {

new AxdEntity_DefaultInventDimInventSetup() {

InventDimId = "AllBlank",

InventSiteId = "MTL-01"

}

}

 

},

new AxdEntity_InventItemInventSetup {

ItemId = inventTable[0].ItemId,

InventDimInventSetup = new AxdEntity_InventDimInventSetup[] {

new AxdEntity_InventDimInventSetup() {

InventSiteId = "MTL-01"

}

},

DefaultInventDimInventSetup = new [] {

new AxdEntity_DefaultInventDimInventSetup() {

InventLocationId = "01"

}

}

 

}

};

 

 

AxdItem items = new AxdItem();

items.InventTable = inventTable;

 

client.Open();

client.create(request.CallContext, items);

client.Close();

}

catch (Exception e)

{

Console.WriteLine(e.Message);

Console.Read();

}

 

 

}

}

}

 

Imparted from here

How to: Call an AIF Web Service from C# to Create a Sales Order – Sample Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using ConsumeSalesOrderService.SalesOrder;

// Add a using statement for the service reference.

using System.Collections;

namespace ConsumeSalesOrderService

{

    class Program

    {

        static void Main(string[] args)

        {

            // Instantiate an instance of the service client class.

            SalesOrderService proxy = new SalesOrderService();

            // Create an instance of the document class.

            AxdSalesOrder salesOrder = new AxdSalesOrder();

            // Create instances of the entities that are used in the service and

            // set the needed fields on those entities.

            AxdEntity_SalesTable salesTable = new AxdEntity_SalesTable();

            salesTable.CurrencyCode = “USD”;

            salesTable.CustAccount = “1101”;

            salesTable.DeliveryDate = Convert.ToDateTime(“2/14/2010”);

            salesTable.Payment = “N060”;

            salesTable.PurchOrderFormNum = “PO”;

            AxdEntity_SalesLine salesLine = new AxdEntity_SalesLine();

            salesLine.ItemId = “1001”;

            salesLine.SalesQty = 88;

            salesLine.SalesUnit = “ea”;

            AxdEntity_InventDim inventDim = new AxdEntity_InventDim();

            inventDim.configId = “HD”;

            inventDim.InventColorId = “01”;

            inventDim.InventSizeId = “42”;

            // Add the sub-entity instances to their parent entities as an array

            // of the sub-entity type.

            salesLine.InventDim = new AxdEntity_InventDim[1] { inventDim };

            salesTable.SalesLine = new AxdEntity_SalesLine[1] { salesLine };

            salesOrder.SalesTable = new AxdEntity_SalesTable[1] { salesTable };

            try

            {

                // Call the create method on the service passing in the document.

                EntityKey[] returnedSalesOrderEntityKey = proxy.create(salesOrder);

                // The create method returns an EntityKey which contains the ID of the sales order.

                EntityKey returnedSalesOrder = (EntityKey)returnedSalesOrderEntityKey.GetValue(0);

                Console.WriteLine(“The sales order created has a Sales ID of ” + returnedSalesOrder.KeyData[0].Value);

                Console.ReadLine();

            }

            catch (Exception e)

            {

                Console.WriteLine(e.ToString());

                Console.ReadLine();

            }

        }

    }

}

Consume an AX AIF Document Service from .NET

Imparted from here

This article appears in the Third Party Products and Tools section. Articles in this section are for the members only and must not be used to promote or advertise products in any way, shape or form. Please report any spam or advertising.


Introduction

This article shows how a .NET client (in our case Windows Client) can consume an AX WCF document service. For this purpose, the service will be hosted on the AOS (Application Object Server) instead of IIS.

Scope

We take the class room (course rooms) administration module as an example. We want to expose a (document) service which makes it possible for external clients to exchange data (CRUD-operations) with AX.

Steps

The remainder of the document explains the different steps to meet our goals. This post assumes that the reader has some experience with the AX AIF (Application Integration Framework) which means that next steps briefly explains the creation, deployment and consumation of an AX document service.

Step 1: Create a document query

Each document service is based on a document query stored in the AOT (Application Object Tree) in AX. This document query holds the appropriate data objects which will be exposed by the service. The datasources of the document query will be exposed by the (WCF) service which will contain the appropriate XML message schema.

Step 2: Create a document service

The wizard takes the created document query (from the previous step) as input parameter and will create a corresponding service class (details omitted). This service class hosts the different methods to invoke CRUD (Create; Read; Update; Delete) operations on the datasource (in our case Course Rooms).

Step 3: Check generated service project

The service wizard created a service project. Besides the service itself, the project contains the service query, the service document class, and the data classes which hold the actual data. What’s interesting is that the service wizard also created a job: GenerateXSDSchema_AxdEMNU_AxdHRMCourse which provides the XML that will be sent over the wire to the consuming client. When you execute the job, you will get the corresponding XML file, as shown below:


Step 4: Expose the document service as a WCF WebService

Create an (enhanced) inbound port for the service (use inbound ports for messages which originate from within AX and should be consumed by external clients). In our demo case, we will expose the service as a tcp-ip service, which will be consumable by external clients from within the scope of the intranet. (If the service should be consumable from the internet, we should choose the Http adapter instead).

Step 5: Select the appropriate service operations

Once you have created an integration port, you must select the service operations which can be invoked by the consuming client.

Step 6: Consume the exposed document service by an external (.NET) client

The service can be consumed by an external client (in our case, a .NET winforms application) … but could be any other type of application … Just below, I briefly explain the interaction code within the .NET client (code executed when the user selects the load or save button). In our demo case, we expose the find, create, update & delete methods.

Step 6.1: .NET Winforms client

The service will be consumed by a simple (C#) .NET client. The client will load the data into a datagrid, make changes to the data (CRUD operations) and submit those changes to AX.

Step 6.2: Load data in .NET client

When the users “clicks” the “Load” button, next will happen:

  • Set query criteria, in our case we will return all course rooms.
  • Set the company from which data will be loaded.
  • Call the repository GetCourseRooms() method which returns all rooms from AX.
Step 6.3: Save the changes to AX

When the user “clicks” the “Save” button, next will happen:

  • Apply last changes to the current dataset (.NET DataSet holds the AX records)
  • Get all added, modified & deleted rows
  • Call the repository SaveCourseRooms() method which will update the data to AX.
.NET Data Repository


Implementing the “find” method in the repository class


Implementing the “create, update & delete” method in the repository class

WCF and AIF in Dynamics AX 2009

Imparted from here

AIF is a standards-based framework that allows you to publish and consume web services.  It’s used primarily in integration scenarios when connecting Dynamics AX with other systems.  AX also has .NET Business Connector (BC.NET) for integrating with .NET applications.  BC.NET is more for client side integration.  AIF is all about web services and is completely standards-based. Under the covers AIF takes full advantage of .NET using Windows Communication Foundation (WCF).  For more complex integration scenarios AIF can also help expose services using MSMQ and BizTalk.

With Dynamics AX 2009, the team ships a bunch of services (about 60 out of the box) that are ready for use.  That includes, for example, the more common scenarios like integration with sales orders or customers.  AIF allows you to create, read, update and delete those sales orders while maintaining the integrity of the database (i.e. without directly touching the database at all).  This is done independent of the transport so when developing you could begin by updating via http and later switch to MSMQ.  This can be as simple as enabling the service then “generating” which generates the WCF interface (i.e. WSDL).  That web service is then available to be consumed by any standards-based client (including apps written in php, java and naturally any of the languages in Visual Studio).  You can also configure the service endpoints to change the binding or authentication parameters.

In the video, Michael walks us through using a standard Excel Visual Studio Tools for Office (VSTO) project to consume a AX 2009 sales order service that is exposed using AIF.  He also shows us how, by using WS-Addressing in the WCF headers, you can pass a target company for a web service call. By default, AX limits error messages coming back from the server for security reasons.  Michael shows us how to configure AX to propagate those errors when you need to see them.

Dynamics AX is a rich platform for supply chain management and financials.  AIF opens up AX so that ISVs can build on that richness by integrating their own applications.  Sometimes when you do that you need to consume a web service exposed by external applications.  We see here how you can plug external web services into the AX processes.  In this case, Michael shows us how when trying to create a customer in Dynamics AX with a name that has been blacklisted by the US government (“Bin Laden”, for instance.  Yikes!  Smiley ) the customer create process calls out to an external web service in the cloud to verify the customer name.  This seamless integration of external processes is a boon for ISVs that need those deep integration points.  Michael explains how. In order to do this sort of integration you build a Service Reference in the Application Object Tree (AOT) to provide the parameters.  AX takes care of much of work by generating the artifacts (compilation, deploying, bundling etc) that are deployed and executed on the server.  CLR interop is available in order to use .NET DLLs and their classes.

Some code samples are available here:

Follow

Get every new post on this blog delivered to your Inbox.

Join other followers:

error: Content is protected !!