Retrieving purchase order from Microsoft Dynamics AX 2012 with help of custom Application Integration Framework (AIF) service
(1) Create a new class – first we will create a new class in AX which will contain the service operations
(2) open AOT. Go to Classes and create a new class.
Name=Test_PurchOrderService, and set the RunOn property of the class to Server.
(3) Add a new method and name it as getPurchOrderList
[SysEntryPointAttribute(true),
AifCollectionTypeAttribute('return',Types::String)]
public List getpurchaseorderlist()
{
PurchTable purchtable;
List list=new List(Types::String);
while select * from purchtable
{
list.addEnd(purchtable.PurchId);
}
return list;
}
(4) Create a new service
Name- PurchOrderService, property of class -Test_PurchOrderService
Open the properties of the newly created service and select the PurchOrderService class in the Class field.
(5) Now expand the PurchOrderService service node and add a new Operation by right clicking on Operations and selecting Add Operation.
(6) Create a new service group – the next step is to create a service group and deploy the service to the Inbound Port
Go to Service Groups, right click and select New Service group, and Name it as PurchOrderServiceGroup.
(7) Set the AutoDeploy to Yes and set the Description as Purchase Order Service
(8) Drag and drop PurchOrderService to PurchOrderServiceGroup
(9)Now right click the service group and select Deploy Service Group.
(10) Verify the service
(11) go to System administration > Setup > Services and Application Integration Framework > Inbound ports
(12) The WSDL URI is the URL of the service which can be used by external systems to access the service.
In Visual Studio, create a new project of type Windows Form Application and name it TestPurchOrderService.
(12) File-- New Project-->Visual C#-->Windows Form Application -- Name of Project(TestPurchorderService)
(13) In Solution Explorer, expand the node for your project. Right-click the References node, and then click Add Service Reference.
http://HOME:8101/DynamicsAx/Services/PurchOrderServiceGroup
(14) Click Go.
The form becomes populated with a node for your service. Click the option button for your service.
(15) Click OK, and the service reference will be added as below.
- Now we are now ready to use the proxy classes in our program.
- Run the form – open the form and add a button and a list box control to the form.
(16) Add the below code to the Get Purchase Order List button click event:
(17) below code write in button click
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TestPurchOrderService.PurchOrderServiceRef;
namespace TestPurchOrderService
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string[] purchorderlist;
try
{
PurchOrderServiceRef.CallContext callcontext = new PurchOrderServiceRef.CallContext();
// StudentInfoRef.StudentInfoServiceClient _Client = new StudentInfoRef.StudentInfoServiceClient();
PurchOrderServiceRef.PurchOrderServiceClient client = new PurchOrderServiceRef.PurchOrderServiceClient();
callcontext.Company = "ceu";
// StudentInfoRef.CallContext _callContext = new StudentInfoRef.CallContext();
purchorderlist = client.getpurchaseorderlist(callcontext);
for (int i = 0; i < purchorderlist.Length; i++)
{
listBox1.Items.Add("Line" + i.ToString() + ":Purchase order Number " + purchorderlist[i].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
(18) Click Get Purchase Order List button and the output will be like below:
No comments:
Post a Comment