Friday, April 27, 2012

Creating a Service in AX 2012 / Consuming a Service in Visual Studio 2010

Hi There!

As promised, in this post we’ll see how to create a simple demo service using AX 2012. Please refer to my last post about AX 2012 Service Documents Types and A Simple Introduction to AX 2012 Services Architecture to get a more detailed explanation to AX 2012 Services.

Also, I would like to point out that AX 2012 services are hosted on the AOS, and that both internal and external applications will be authenticated through the AOS.  With this being said, the following example will be an internal application that will get the customer name from AX services.

If I wanted to have an external application executing the same operation I would have to host the services in IIS. For more information on services please refer to this white paper.

Further, when working with AX 2012 WCF services, we will have to dive into data contracts. In this sample service will use a DataContractAttribute. The string DataContractAttribute indicates that this class is a Data Contract. The square brackets [] indicate that this string is an attribute. We are also going to be using Data Members, which would help us define the default values for our data contracts.

If you are new to this, don’t worry, you can find a lot of information about Data Contracts and Data Members out there.

Another concept that we’ll be exposed on this example is the SysEntryPointAttribute, which helps with authorization checks and how they are performed for a method that is called on the server. Further, this is a very important class when working with Services in AX 2012 as we have to use it for all service operations.

So, let’s start working on our simple service. (Please note that I’m working on a project that involves a lot more detail. When done I will share it with you, so we can understand many other concepts about AX 2012 that won’t be covered in this post)

1.       Open the AOT.
2.       Create a new class.
3.       Enhance the class by adding the [DataContractAttribute] attribute.

4.       Create a new method.
5.       Enhance the class by adding the [DataMemberAttribute] attribute.

6.       Create another class.
7.       Create a method that instantiates the class created in Step 2.
8.       Enhance the class that uses the [SysEntryPointAttribute] attribute.

9.       Right-click the Services node in the AOT and select New Service.
10.       Enter a name into the Name property.
11.       Set the Class property to the class created in Step 6.
12.       Expand the new service node.
13.       Right-click the Operations node and select Add Operations.

14.       Right-click the Services Group node in the AOT and select New Service Group.
15.       Enter a name into the Name property.
16.       Drag-and-drop the service created in step 9 under the Service Group node.
17.       Right-click the service group and select Deploy service group.

Ok, so at this point we should have our new AX 2012 service already working. The next step is to learn how to use this service from Visual Studio 2010. Please refer to this article if you are new to adding services references to Visual Studio. It will help you understand the underlying concepts of this operation.

1.       Select File > New > Project to create a new project of type Console Application.
2.       Enter a name into the Name field and then click OK.

3.       Right-click the Service reference node under the project.
4.       Select Add Service Reference.
5.       Enter the address and then click GO.
6.       Select the service and then click OK.

NOTE: The address format in step 5 is http://<machinename>:8101/DynamicsAx/Services/Xpp. 

7.       Invoke the service from the client.

8.       Click F5 to run the service.

As you can see, when you run the service, the first customer name that are available in your system will be presented as an output.  There is a lot more to services and you can start learning more about it by going to partner source and/or downloading the new AX 2012 white papers focusing on services.

I will be posting a lot more on this later soon, so keep reading my blog as there is a lot more to come.

Take Care and have a great weekend!


  1. Nice post!! Thanks a lot for the info

    1. You are very welcome!

      Thanks for reading my blog

  2. HI John,

    I need your help ,a vendor will provide me a webservice which will consume by me on ax side .Its a update function ,i will first retrieve the values from ax side pass those values using their webservice .Please help me on this .Kindly mail me on

  3. Hi John,
    I am quiet new to the AX world. I have a job in hand to integrate sales order from Dynamic CRM 2011 to AX 2012. Can you give me your valuable inputs please like where should i start from or any steps that is should follow.
    Thanks Mate for sharing your knowledge.


    1. Hey Dawson,

      It is fairly simple. AX 2012 has the capability to integrate with CRM.

      Check the following links for instructions:

      I hope this helps

    2. Hey John,
      I have already tried the connector. It has plenty of limitations and restrictions in CRM after integration.
      Lately i have been checking out webservices that are availaible in AX through AIF. I did notice there is CustFreeTextInvoice service availaible but i am not sure how can i use it C#. You can please throw some light on it.
      I have tried doing it looking at this link
      but it was not much of help.

      For now i am only looking out to move invoices from CRM to AX as free text invoice without the using Excel Addin.

    3. Hi,

      By the way my name is not John. John is the name that said the quote i have in my blog. My name is Eduardo :)

      Anyway, for that specific requirement, look at the course 80416 is partner source or customer source ( There is an example there to get what you need.

      I hope this helps

    4. Sorry Eduardo,
      For some reasons I thought your name is John.
      I do have access to partner source but dont have access to that particular course.
      So is it anywhere possible for you to copy paste the example from there to here or email me Please.



Thank you for your thoughts. Your comment will appear in my blog shortly after review.

Have a great day!