Microsoft Dynamics AX 2012 - A Dive into System Services, Metadata Service
Recently I wrote last week about Microsoft Dynamics AX 2012, talking about a dive into Services.
One of the area's that I covered in this post was around System Services. To recap:
"System Services are meant to give a window into the Dynamics AX 2012 world. Part of that world involves Query Service, as well as the Metadata Service. These two services are meant to be very specific uses. The Query Service is meant to take and offer an ad-hoc ability to query datasets, from AX 2012."
With this initial post as our guide, lets take and step through these different area's of services, get some real examples, and talk about what kind of value each type can bring to an implementation.
System services, are new in AX 2012, and so their value will develop overtime, and more and more people find ways to make use of them, to drive value. The Query service is meant, as stated, to give the ability to have an ad-hoc nature to query data from an AX 2012 instance. I don't actually recommend using this that much, as we get into Document Services in a later post, and see that most all data access should take place, starting with a query object inside Dynamics AX 2012.
With that said, lets focus our time for this post, on the Metadata service. To start, the system services are auto deployed out of the box, and so there is nothing that you have to do, in other than make a reference to the given Metadata service's WSDL.
To do that, the following is the format for accessing the metadata service.: http://servername:port/DynamicsAx/Services/MetadataService
This, if placed in a web broswer, will bring back the WSDL for this given service, which is true for any service, or service group I should say. You will notice that this is how you make a reference, from say Visual Studio 2010.
In doing so, and if you look at the app.config file from within your project, you will notice though, that the binding is actually net.tcp//. This is because these system services are hosted, out-of-the-box, within the AOS itself. More in a later post on options for hosting services.
Example app.config
You will notice, in the above example app.config file, that I have changed the maxBufferSize and the maxReceivedMessageSize. The reason this is the case, is because my example, with getting metadata about a given table, pulls back a larger resultset than the default settings for this WCF net.tcp binding is configured to receive. If you don't do this, the first time you use the Metadata service, it will error out. Keep in mind, this is WCF we are dealing with, and though it's gotten a lot easier to deal with bindings and settings, it's still something that must be done.
Now that we have our reference within our Visual Studio 2010 project, lets take and dive into working with it.
For our example, lets create some unit of code, that will take and call the metadata service, and in turn ask for metadata about a specific table. The following is the C# code for doing just that.:
For reference, and being able to search with google or bing, the following is that code in plain text:
"Ax2012MetadataService.AxMetadataServiceClient cl =
new Ax2012MetadataService.AxMetadataServiceClient();
cl.Open();
string[] axTableNames = new string[1];
axTableNames[0] = "CustTable";
Ax2012MetadataService.TableMetadata[] axTableMetaData =
cl.GetTableMetadataByName(axTableNames);
MessageBox.Show("Title Field1: " + axTableMetaData[0].TitleField1.Name +
", Title Field2: " + axTableMetaData[0].TitleField2.Name);
cl.Close();"
Now what we have here is straight forward, I'm taking and creating an instance of the AX2012MetadataServiceClient which was generated for me by VS2010, when adding the service reference to the project.
After that, I open the given client object, and fill a string[] array with a single entry, for the "CustTable". After doing this, I take and fill a TableMetadata[] array, which is part of the WSDL DataContracts supplied from AX 2012, with calling the client and a .GetTableMetadataByName(axTableNames) and pass it my string array of tables that only contains, for this example, the CustTable.
After this, I'm able to simply call a message box, and show the Title Fields 1 & 2, that are supplied by AX 2012, and passed back within that TableMetaData[] array.
The result is as follows.:
As you can see, we get back the Title Field information, and really we can get back anything that is contained within the properties of a given table object, which is the metadata for this given type of object.
This is the same for classes, EDT's, enums, forms, etc. etc. This is actually a pretty powerful class, as you can start to see uses of this new service, for given the ability of AX 2012 to describe itself to other LOB applications, as with the correct rights, you can get a list of tables, and then from those tables, a list of every field within those tables, and there EDT's or base enums, and then information about every single one of those.
One thing I will add, is that I have noticed the Autoreports, that run from File > Print > Print for a given form, actually make use of the MetadataService for fulfilling part of it's needs for generating the autoreports in AX 2012. So that is a solid use, of this new offering.
As me move into AX 2012, which was released as GA in 25 countries yesterday, see: Drum Roll Pleaseā¦ Microsoft Dynamics AX 2012 is now on the market!, we will start to see uses of these system services that help enable, extend and the bottom line, drive business value for customers that make use of this great new ERP platform.
Well that's all for now, but check back soon as a whole lot more to come! Till next time!
Labels: AX 2012, Dynamics AX, Dynamics AX 2012, LOB, Metadata, Metadata Service, Microsoft, Reflection, Services, SOA, System Services
2 Comments:
Such a great article it was which System services, are new in AX 2012, their value will develop overtime, and more and more people find ways to make use of them, to drive value.In which illustrate the process of the code. Thanks a lot for sharing.
Its such a informative article,the ability of AX 2012 to describe itself to other LOB applications, as with the correct rights, you can get a list of tables, and then from those tables, a list of every field within those tables, and there EDT's or base enums, and then information about every single one of those.In deed system services that help enable, extend and the bottom line, drive business value for customers that make use of this great new ERP platform.
Post a Comment
<< Home