AX Consulting

Just another site

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 };



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



catch (Exception e)









Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: