Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Tuesday, August 02, 2011

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!



"Visit the Dynamics AX Community Page today!"

Labels: , , , , , , , , , ,

Wednesday, November 11, 2009

Reflection - Where and why

With Dynamics AX, the ability to make use of Reflection, or Reflective Programming, exist.

For those that don't quite understand what reflection is, please check out the following wikipedia link, which explains it well.:
Wikipedia.org Link



As described on the wikipdeia article.:
"In computer science, reflection is the process by which a computer program can observe and modify its own structure and behavior. The programming paradigm driven by reflection is called reflective programming. It is a particular kind of metaprogramming.

In many computer architectures, program instructions are stored as data - hence the distinction between instruction and data is merely a matter of how the information is treated by the computer and programming language. Normally, instructions are executed and data is processed; however, in some languages, programs can also treat instructions as data and therefore make reflective modifications. Reflection is most commonly used in high-level virtual machine programming languages."


So the idea of reflection, or meta-programming, has actually been around for a long while. Since the mid 1980's. And the ability to perform reflective programming exists in many langauges, including C#, Java, and X++.

There are plenty of examples actually of reflection, that are common use with Dynamics AX. These may not be considered full reflective based programming, but aspects of this exists all through the common code base of Dynamics AX.

Take for example the Common object. All tables actually extend from this Common object.

As it's base, you have then the ability to send a table of unknown type, and operate it on a method that does not know until runtime, what the Common object actually represents.

So there eixsts, for the Common object, the ability for it to describe itself to later executing code, and therefore can then be acted upon at runtime.

For example.:

public void SomeMethod(Common Rec)
{
Table1 tbl1var;
Table2 tbl2var;
;

switch(tableid2name(rec.tableid))
{
case "Table1" :
tbl1var = Rec;
break;

case "Table2" :
tbl2var = Rec;
break;
}

// Do some code here on the Tables...
}


In the above example we see a somewhat common approach for having a method find out what kind of table that is being passed in, and then operate on that table based on the table name.

Now if you expand this further, there are other classes, and objects that exists inside Dynamics AX that help us really implement Reflection.

These classes include.:

  • SysDictTable

  • SysDictField

  • SysDictClass

  • Etc.



You can browse the AOT, Classes and go to SysDict* and see what all exists there.

The reason I bring reflection up, is I think it's not a well understood topic, and one that if more people understood could really benefit from.

I have done some development work before, that making use of reflection could read an entire SQL Server databse, read in datatypes, field lengths, tables names, and use that to create tables, extended data types, and import the data into these new tables, with a single object.

There is also possibilities for making use of reflection for say you want to have a class framework, and have a class tied to a given customer to operate some kind of acknowledgement to that customer.

You don't however want to have a mega object that operates all this for you, and you want flexibility. What to do?

Well you can make use of reflection, to create a framework that will execute code, not knowing for sure what it's executing actually. Only knowing that the given class it is executing has a specific method. And you made sure of that this method exists, because you make use of reflection to see if it actually does exists.

This can be done with making use of the SysDictClass, and the Object, Object. You could also get fancy, if need be, and create code at run time, compile that code and run time, execute that code at run time, and have that code return it's output to operate on. Again, All at run time!

To see a decent example of this, check the following out.: Generating and running code RUNTIME

Also, a great resource on this very matter, with X++ as the focus is the SysDictCoder blog, found here.: SysDictCoder Blog

The following are just some of the great highlights that have been from this blog, and I myself have made use of most or not all of these in my lifetime of AX.:


Those are just some recent few actually, and there is a lot more.

The whole idea of reflective development, making use of reflection is smart coding. Sometimes people look at it as code that makes code. If I can create a single object that saves me time from coding 200 objects, that that is the better way.

And that last example, true example. Not a made up number. I have done this before, specifically relating to data imports.

That's all for now, I hope this is enough to get you thinking about reflection, some of it's common uses in X++, and maybe how it can help you solve that next need.

Till next time!




"Visit the Dynamics AX Community Page today!"


Labels: , , , , , , , , , , , ,

Sunday, November 08, 2009

Blog spot lioght: Gotdax?

I try to spotlight great resources I find from time to time. Places on the web that has some great peices of information, spanning the entire Microsoft stack, and how that relates to Dynamics AX.

In doing so, I will do these Blog spot light posts. Well today is one of those post, and I want to spotlight a blog called: Gotdax? - click here to visit.

This blog, was recently started this year it seems in July, by a one Jacob Sørensen who seems to be from around the north sea area of Europe, where AX was actually born.

His post, some we have see similar at the SysDict Blog and I myself have posted about, focus on the 'out of the box' ways to get things done inside Dynamics AX.

See I am a big fan of reflection, and reflective development. Meta-programming or meta-development as it is sometimes referred too. And Jacob touches some of that with his post.

Here are some of the interesting one's that he has posted so far.:


I always encourage my fellow bloggers to continue to push the envolope in being creative, and posting relavent information that helps the Dynamics AX community.

This is for sure some good post, Jacob, and I hope to see more from you! Thanks for taking the time to post!

That's all for now. I have more planned post for the upcoming week, so see you then!




"Visit the Dynamics AX Community Page today!"


Labels: , , , , , , , ,


Copyright 2005-2011, J. Brandon George - All rights Reserved