How to Integrate AX Services in .Net
Some times we require to consume AX services in .NET based solution like in Console/Asp.Net/Win Store 8 App. This is very simple for Console/Asp.net while Win Store 8 app takes a little difference.
MS Dynamics AX services come in 2 types Document and Custom. I will explain in other blog what are they. Once AX Developer publishes these services. We need which type of binding is provided. Like Http, netTcp. Usually netTcp is default. So if we require the data thin client then we need Http Binding also. Once services are publishes.
We are taking for reference Loyalty Customer AX Data with http://ax2012r2a.contoso/MicrosoftDynamicsAXAif60/TRLoyaltyCustomer/xppservice.svc service.
where ax2012r2a.contoso is the server name.
Just go to application and add service reference as we normally do in any .NET based application.
Give desired proxy class name like CustomerService.
Now you are ready to consume AX data into your .NET Application. Following is the example for console based application.
using System;
using System.Collections.Generic;using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using AXSrv.CustomerService;
namespace AXSrv
{class Program
{
static void Main(string[] args)
{
LoyaltyCustomerServiceClient client = new LoyaltyCustomerServiceClient();
CallContext Contex = new CallContext();
Contex.Company = "abcrt";
Contex.MessageId = Guid.NewGuid().ToString();
Contex.LogonAsUser = String.Format("Contoso\\{0}", "admin@ax2012.com");
try
{LoyalityCustomerDetailsContract[] k = client.getLoyaltyCustmerDetails(Contex, Contex.LogonAsUser, Contex.Company);
foreach (LoyalityCustomerDetailsContract c in k)
{Console.WriteLine(c.CustName +" : " + c.CustomerAddress +" : "+ c.LoyalCustId+" : "+
c.RetailExpiredPoints);
}
}catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}
Thank you for posting the valuable information.
ReplyDeleteMicrosoft Dynamics AX Online Training
It’s interesting to read content nice post.
ReplyDeleteD365 Finance and Operations Online Training
valuable infomation you shared.thanks a lot
ReplyDeleteFull Stack Training in Chennai | Certification | Online Training Course | Full Stack Training in Bangalore | Certification | Online Training Course | Full Stack Training in Hyderabad | Certification | Online Training Course | Full Stack Training in Pune | Certification | Online Training Course | Full Stack Training | Certification | Full Stack Online Training Course