Requirement:
I need to use the external service in my Microsoft Dynamics AX2012 R3 code to fulfill some business requirement.
Solution:
The steps to use wcf service in X++ are quite simple:
- Create the new .Net Class Library project.
- Adding the Service Reference in .Net Class Library.
- Build and Deploy the .Dll (C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin) in Client Folder
- Add the project to AOT if required not necessary
- Open AOT and add the Dll Reference by right click on the Reference node in AOT.
- Now with the following code you can access the external wcf service in your Microsoft Dynamics AX2012 R3 X++ code:static void WCFService(Args _args)
{
SMTP.SMTPService.AXClient service;
boolean ret;
System.Exception ex;
System.Type type;try
{//by this procedure you don’t need to add the service endpoint in AX32.exe.Config
//it will pick from the class library config
type = CLRInterop::getType(‘SMTP.SMTPService.AXClient’);
service = AifUtil::createServiceClient(type);// Service Method
ret = service.InsertCourseItem(“testAXCode”,”ItemName”,”ItemId”,200,”descrip”);}
catch(Exception::CLRError)
{
ex = CLRInterop::getLastException();
info(CLRInterop::getAnyTypeForObject(ex.ToString()));
}
}#MicrosoftDynamicsAX2012 #AX2012 #WCFService#ConsumeWCFService #ConsumeWCFServiceInX++ #AX2012R3 #.Net #Consume.NetC#
Thanks,
Happy Daxing with Rizz 🙂
