We can expose AOT query as service which can consume in any WCF client. We can call and fetch data from any AX table, without Static AOT query. For this purpose Dynamics Ax provide the methods to create a query at run time and call with Query service.
This Query service is built in feature if during Application Interface framework component installed with Dynamics Ax Setup.
http://[HostName]/DynamicsAx/Services/QueryService
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; //using Microsoft.Dynamics.AX.Framework.Services.Metadata.Contracts; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { testService.QueryServiceClient _QueryClient = new testService.QueryServiceClient(); DataSet dataSet; testService.Paging paging = null; testService.QueryMetadata query; testService.QueryDataSourceMetadata customerDataSource; query = new testService.QueryMetadata(); // Set the properties of the query. query.QueryType = testService.QueryType.Join; query.AllowCrossCompany = true; query.DataSources = new testService.QueryDataSourceMetadata[1]; // Set the properties of the Customers data source. customerDataSource = new testService.QueryDataSourceMetadata(); customerDataSource.Name = "DataArea"; customerDataSource.Enabled = true; customerDataSource.FetchMode = testService.FetchMode.OneToOne; customerDataSource.Table = "DataArea"; // Setting DynamicFieldList property to true returns all fields. customerDataSource.DynamicFieldList = true; //Add the data source to the query. query.DataSources[0] = customerDataSource; dataSet = _QueryClient.ExecuteQuery(query, ref paging); foreach (DataRow dr in dataSet.Tables[0].Rows) { Console.WriteLine(dr["Id"].ToString()); } Console.ReadKey(); } } }
if you got error with similar message “The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
update the binding section of app.config
<bindings>
<netTcpBinding>
<binding name=”QueryServiceEndpoint” transferMode=”Streamed”
maxReceivedMessageSize=”20000000″
maxBufferSize=”20000000″
maxBufferPoolSize=”20000000″
>
<readerQuotas maxDepth=”32″
maxArrayLength=”200000000″
maxStringContentLength=”200000000″/>
</binding>
</netTcpBinding>
</bindings>