How to create and test the DLL of AX2012 service
This post will demonstrate the creation of DLL with AX2012 service and than testing the DLL from Visula studio.
Hi guys this requirement is not very common and I could hardly found any post which share the details about this. I did a POC for a requirement where the third party software was not enough capable to directly consume the AX2012 SVC.
In order to provide a solution we created DLL out of the AX2012 service and than tested the same DLL using as a reference in visual studio.
Step: 1 Create DLL for your existing service.
Goto Visual Studio --> New --> Project --> C# --> ClassLibrary --> Add service reference
Step 2: Set your project to release mode.
Step 3: Build the project and copy the dll from release folder.
Release folder path
Step 4: Go to config in same VS project and copy the endpoint address and save it for later use.
Now close the VS solution. Your DLL is ready to be used copy this dll to any other location on your system.
Step 5: To test the same dll we need to create another VS solution.
Goto --> File --> New --> Projects --VisualC# --> ConsoleApplication.
Step 6: Add reference to you dll.
Goto --> Solution Explorer --> Reference --> Right click --> Add new reference
Step 7: Browse to the dll folder path and select dll file to be added.
Step 8: Repeat step 6 and add one more service reference from Assembly.
Step 9: Add below code to your console application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudentTableDll.StudentService;
using System.Configuration;
using System.ServiceModel;
namespace TestDLLDemo
{
class Program
{
static void Main(string[] args)
{
EndpointAddress ep = null;
System.ServiceModel.NetTcpBinding tcpb = new System.ServiceModel.NetTcpBinding();
System.ServiceModel.ChannelFactory channelFactory = new System.ServiceModel.ChannelFactory<StudentTableService>(tcpb);
// End Point Address taken from step 4 in same blog
string strEPAdr = "net.tcp://ax2012r3dev:8201/DynamicsAx/Services/StudentTable";
ep = new EndpointAddress(strEPAdr);
StudentTableServiceClient client = new StudentTableServiceClient(tcpb, ep);
AxdStudentTable axd = new AxdStudentTable();
CallContext context = new CallContext();
context.Company = "EAM";
context.Language = "en-au";
AxdEntity_StudentTable studentTable = new AxdEntity_StudentTable();
studentTable.Name = "Kumar";
studentTable.Standard = "Eight";
studentTable.RollNumber = 01;
axd.StudentTable = new AxdEntity_StudentTable[1] { studentTable };
try
{
EntityKey[] returnFloc = client.create(context, axd);
EntityKey returnedFloc = (EntityKey)returnFloc.GetValue(0);
Console.WriteLine("the record has been created RECID- " + returnedFloc.KeyData[0].Value);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
}
}
}
Step 9: Before running the code please ensure the below highlighted points.
Step 10: Run to code to create the record in student table.
Happy daxing :)