AX 2012 has changed a lot with respect to technology and functions. Web services have become an integral part for integrating any 2 applications and AX 2012 itself heavily uses the web services. The way web services are consumed in Dynamics AX 2012 has changed from the way it was done in AX 2009. I worked out a demo application in AX 2012 to consume the Stock Quote web service to learn how it works.

For the demo purpose I consumed the web service provided by WebServiceEx to get the stock quote of the provided company. The web service URL used in this application is :

Step 1

AX 2012 needs us to create a Class Library in Visual Studio which consumes the web service. So, in the first step lets create a Class Library and consume the web service using Visual Studio.

Create a New Project in Visual Studio and select Visual C# Class Library. Specify the name for your Class Library and hit Ok.


Step 2

Now that we have the Class Library created let’s reference the Web service. Right click the References or Project Name under Solution Explorer and select Add Service Reference. On the next screen that pops up input the web service URL in Address and hit the Go button. Visual Studio at this time reads the web service and lists the services available at the mentioned location. Provide the Namespace for your web service and hit the Ok button.


Step 3

Now that we have the web service referenced into our library, we need to add the Project to Dynamics AX AOT. Right click the Project Name under Solution Explorer and select Add StockQuoteLibrary to AOT which will add the Project to Dynamics AX AOT. To accomplish this you need Visual Studio Tools in Dynamics AX Setup installed.


Step 4

After you add the Project to AOT, project properties are enabled that let you define where the project should be deployed. Set Deploy to Client and Deploy to Server to Yes. Setting these properties to Yes deploys the project output (DLL in this case) to server’s and client’s Bin folder.


Step 5

Now that we have the project properties set, Right click the Project Name and hit Deploy button. Once the deployment is complete restart the Dynamics AX Client which is an important step. I am not sure why a restart is needed, but I feel that Dynamics AX Client needs to reload the newly deployed DLL’s and hence a restart (this is my assumption and may not be true Smile).

Step 6

You will now find your Class Library under AOT –> Visual Studio Projects.


Step 7

Now that we have our Class Library which references the Web service available in AX, lets utilize it and write a Job to fetch the Stock Quotes in AX. You can now also see you Class Library as a part of Intellisense.

static void jobStockQuote(Args _args)
    CLRObject clientType;
    StockQuoteLibrary.StockQuoteService.StockQuoteSoapClient _client;
    str response;
    XmlDocument xmlDoc;
    new InteropPermission(InteropKind::ClrInterop).assert();

        clientType = CLRInterop::getType("StockQuoteLibrary.StockQuoteService.StockQuoteSoapClient");
        _client = AifUtil::createServiceClient(clientType);
        response = _client.GetQuote("GOOG");
        xmlDoc = new XmlDocument();

Just run the Job and you should be able to fetch the Stock Quote from the web service. Hope this helps!

Add a Comment