Tuesday 8 November 2016

Query Service AIF AX2012


 AIF query service can be used to fetch ad hoc data from AX2012 without creating a new service.
Its a common service which can be used to retrieve the data from AX database. There are three types of queries that you can run through a query service but I am discussing only the first two options here:


In the below code I will demonstrate the use of query service for fetching all the records from the SalesTable through the user defined query. In order to run this snippet, please make sure that AIF services are deployed and you are able to access the query service.  URI for the query service WSDL is:

http://<AOS_HOST>:8101/DynamicsAx/Services/QueryService


C# code for fetching the records

QueryServiceClient client = new QueryServiceClient();
QueryMetadata queryMetaData = new QueryMetadata();
queryMetaData.DataSources = new QueryDataSourceMetadata[] {
new QueryDataSourceMetadata() { DynamicFieldList=true, Table=”StudentTable”,  Name=”StudentTable”,  Enabled=true}
};

Paging paging = null;

DataSet ds = client.ExecuteQuery(queryMetaData, ref paging);

foreach (DataRow dr in ds.Tables[0].Rows)
{
Console.WriteLine(dr[“PersonnelNumber”].ToString());
}

Console.ReadLine();


Sunday 6 November 2016

How to debug AIF AX2012

In this post I will demonstrate the debugging of AX2012 AIF services, which makes the lives of developers easy :).

We can simply debug the AIF service, triggered from C# code which was written to consume the AIF services.

I have created a document service and written some custom code in service classes. Now I want to debug and see the impact.

Follow below steps:

Prerequisite: Your environment should be full CIL compiled.

Step 1: Create a console application in visual studio C#, to consume the AIF service. This was demonstrated in my earlier post. For more details visit below link.


Step 2: Open a new visual studio application. Right click visual studio and Run as admin.

Step 3: Open Application explorer in visual studio and find your service class.




Step 4: Now go to Debug option and attach the process to server.
 Step 5: Make sure that the symbol loading is completed and the debugger symbol is completely turned Red.


Step 5: Now the service is ready to be debugged. Switch to the first visual studio application where you have written the C# code as per the Step 1. Make sure the two VS applications are running simultaneously.

Step 6:  Run the test code, the debugger will hit the line of code on another VS application where you have attached the server processes.


Note: Debugging is possible in VS only, this will not open AX debugger, also the client side code will not be executed in debugger.

Happy daxing :)