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();


No comments:

Post a Comment