LeaderBoard

Showing posts with label AIF. Show all posts
Showing posts with label AIF. Show all posts

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 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();

            }

        }

    }

}

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: