Wednesday, May 6, 2015

Microsoft Dynamics AX 2012 – Calling SOAP Web Services from JavaScript

Microsoft Dynamics AX 2012 – Calling SOAP Web Services from JavaScript
Purpose: The purpose of this document is to illustrate how to call Microsoft Dynamics AX 2012 SOAP Web Services from Windows 8 application using JavaScript.
Challenge: Application Integration Framework (AIF) supports Web services for Windows Communication Foundation (WCF). In AIF, each document is represented by a service that can be exposed from an integration port. To consume services over the Internet, you must host services on Internet Information Services (IIS). AIF uses standard WCF processing to receive and process SOAP requests. Please find more info on AIF and Services here: For the purposes of POC or app development you may need to consume Microsoft Dynamics AX 2012 SOAP Web Services from Windows 8 application using JavaScript
Solution: In this walkthrough I'm going to deploy an instance of Microsoft Dynamics AX 2012 R3 in the Cloud on Windows Azure using Microsoft Dynamics AX Lifecycle Management Services (LCS), write my own Custom WCF Web Service exposing business data and call this SOAP-based Web Service from Windows 8 application using JavaScript WinJS.xhr (XML Http Request) object. Please find more info about asynchronous programming, WinJS promises and xhr (XML Http Request) object here:
First of all I'll deploy an instance of Microsoft Dynamics AX 2012 R3 using LCS. Please visit to access LCS Cloud service
After successful deployment I'll be able to access my Demo VM on Azure portal
What I'll need to do for my walkthrough is to enable HTTP/HTTPS endpoints for my Demo VM so I can reach out to my Web Service over internet
Please note that enabling HTTP/HTTPS endpoints for Demo VM is suitable for the purposes of POC, but it is not secure and not suitable for production applications accessing Microsoft Dynamics AX 2012. In order to build production application securely accessing Microsoft Dynamics AX 2012 please utilize Windows Azure Service Bus. Please find detailed guidance on how to leverage Windows Azure Service Bus to establish secure cross-domain connection to Microsoft Dynamics AX 2012 here:
Continuing in this walkthrough I'll focus on mechanics of what's going on with Web Service request behind the scenes. But before we get there I'll do some necessary plumbing  
My plan is to expose custom business data based on newly created table. Please see the structure of my project below
By using my simple WCF Custom Services Class Wizard ( I quickly created Data contract and Service contract classes to expose necessary business data
Data Contract
public class AlexTableContract
    AlexName    Name;
    AlexID      ID;
public AlexID ID(AlexID _ID = ID)
         ID = _ID;
         return ID;
public AlexName Name(AlexName _Name = Name)
         Name = _Name;
         return Name;
Service Contract
public class AlexServiceContract
[AifCollectionTypeAttribute('return', Types::Class, classStr(AlexTableContract)), SysEntryPointAttribute(true)]
public List getList()
    AlexTable           alexTable;
    AlexTableContract   alexTableContract;
    List                list;
    list = new List(Types::Class);
    while select alexTable
        alexTableContract = new AlexTableContract();
    return list;
Then I will wrap up my classes with Microsoft Dynamics AX Service (AlexService) and execute right click > Add-ins > Register service command for AlexService

At this point I'll populate my table with a few records using Table Browser

Table browser
Next I'll create Inbound port for newly created Web Service using HTTP adapter
Inbound port
Then I will add AlexService.getList operation to the Web Service
Select service operations
As the next step I'll write a simple Windows Console client application to better understand how my Web Service request looks like behind the scenes when I call my Web Service. As I create new Windows Console application I will need to add Web Service Reference as shown below 
Add Service Reference
The code for the client looks like below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ConsoleApplication1.ServiceReference1;
namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            AlexServiceClient client = new AlexServiceClient();
            CallContext context = new CallContext();
            context.Company = "usmf";
            client.ClientCredentials.Windows.ClientCredential.UserName = "Admin";
            client.ClientCredentials.Windows.ClientCredential.Password = "pass@word1";
            AlexTableContract[] list = client.getList(context);
            foreach (AlexTableContract item in list)
                Console.WriteLine(item.ID + ": " + item.Name);
As the result I'll output the list of values from my table
Now the most interesting part. Before I ran my client program to fetch the data from Microsoft Dynamics AX 2012, I launches Fiddler to listen to HTTP/HTTPS traffic and see HTTP/HTTPS requests and responses taking place. You can download Fiddler from here:
In Fiddler I can clearly see how HTTP/HTTPS request and response looked like when I execute my client application and called Microsoft Dynamics AX 2012 Web Service
Content-Type: text/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo9P2U4sA1ENFu3GK474gpEsAAAAA7d1xyqrazUe5zAsDszpG8Js/kfbqE3NPrANxMKaGnFUACQAA
Accept-Encoding: gzip, deflate
Content-Length: 595
Expect: 100-continue
<s:Envelope xmlns:s=""><s:Header><h:CallContext xmlns:h="" xmlns:i=""><h:Company>usmf</h:Company><h:Language i:nil="true"/><h:LogonAsUser i:nil="true"/><h:MessageId i:nil="true"/><h:PartitionKey i:nil="true"/><h:PropertyBag i:nil="true" xmlns:a=""/></h:CallContext></s:Header><s:Body><AlexServiceGetListRequest xmlns=""/></s:Body></s:Envelope>
Please note that POST method was used to call Web Service. Also appropriate envelope was added to the request
The response is returned in form of structured XML also wrapped with envelope

<s:Envelope xmlns:s=""><s:Body><AlexServiceGetListResponse xmlns=""><response xmlns:b="" xmlns:i=""><b:AlexTableContract><b:ID>1</b:ID><b:Name>Alex</b:Name> </b:AlexTableContract><b:AlexTableContract><b:ID>2</b:ID><b:Name>Test><b:Name> </b:AlexTableContract></response></AlexServiceGetListResponse></s:Body></s:Envelope>
At this point I have enough knowledge to call my Web Service from Windows 8 application using JavaScript WinJS.xhr object. WinJS is a Windows library for JavaScript which implements Windows look and feel for your apps as well as a lot of useful objects such as xhr (XML HTTP request). Please find more info about WinJS here:
In order to create my Windows 8 app I'll use JavaScript Hub App template as shown below
Hub App (Windows)
For my app I'll implement a simple HTML page List.html to display the list of records from Microsoft Dynamics AX 2012 after calling Web Service. Here's how related List.js file looks like which implements business logic calling Web Service using WinJS.xhr object 
(function () {
    "use strict";
    WinJS.UI.Pages.define("/pages/list/list.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
    function doClickSync() {
        var data = '<s:Envelope xmlns:s=""><s:Header><h:CallContext xmlns:h="" xmlns:i=""><h:Company>usmf</h:Company><h:Language i:nil="true"/><h:LogonAsUser i:nil="true"/><h:MessageId i:nil="true"/><h:PartitionKey i:nil="true"/><h:PropertyBag i:nil="true" xmlns:a=""/></h:CallContext></s:Header><s:Body><AlexServiceGetListRequest xmlns=""/></s:Body></s:Envelope>';
        var options = {
            url: "",
            type: "post",
            headers: {
                "Content-Type": "text/xml; charset=utf-8",
                "SOAPAction": ""
            user: 'Admin',
            password: 'pass@word1',
            data: data
            function (request) {
                var dataItems = [];
                var xmlResponse = request.responseXML.documentElement;
                var fullNodeList = xmlResponse.getElementsByTagName("b:AlexTableContract");
                for (var i = 0; i < fullNodeList.length; i++) {
                    var dataItem = { id: fullNodeList[i].childNodes[0].textContent, name: fullNodeList[i].childNodes[1].textContent };
                var dataList = new WinJS.Binding.List(dataItems);
                var alexView = document.getElementById('alexList').winControl;
                alexView.itemDataSource = dataList.dataSource;
            function (error) {
            function (progress) {
Please note that I included envelope and passed it as data into WinJS.xhr. Also I used post method to call Web Service, explicitly defined SOAP Action, provided authentication details as a part of request (please take into account security concerns when developing your apps, for the purposes of POC and simplicity I just hard-coded authentication details into the request). Finally when I receive asynchronous response I'll need to parse it out using XML DOM model and re-assign the data source for List element in HTML
As the result I successfully display the list of records from Microsoft Dynamics AX 2012 in my app
Similarly you can implement not only data retrieval scenarios but also data manipulation scenarios calling Microsoft Dynamics AX 2012 Web Services. For example, creation of Sales order or creation/posting of General journal or Inventory journal
Summary: In this walkthrough I illustrated how to call Microsoft Dynamics AX 2012 SOAP Web Services from Windows 8 application using JavaScript and shed some light into what's happening behind the scenes when you call Web Service, how request and response look like and what you have to do to successfully call Microsoft Dynamics AX 2012 SOAP-based Web Services.
Tags: Microsoft Dynamics AX 2012, Custom Web Services, Data Contract, Service Contract, X++, Windows 8 App, JavaScript, WinJS, XHR, XML HTTP Request/Response, Fiddler.
Note: This document is intended for information purposes only, presented as it is with no warranties from the author. This document may be updated with more content to better outline the issues and describe the solutions.
Author: Alex Anikiev, PhD, MCP


  1. Dear Alex, great post, thx! I have one issue with the C# Console client application. Line with "TestTableContract[] list = client.getList(context);" gives error:

    Error 1: The best overloaded method match for 'TestTableService.AX.TestTableServiceClient.getList(TestTableService.AX.CallContext)' has some invalid arguments c:\users\adm_pfis\documents\visual studio 2013\Projects\TestTableService\TestTableService\Program.cs

    Error 2: Argument 1: cannot convert from 'TestTableService.AX.CallContext [c:\users\adm_pfis\documents\visual studio 2013\Projects\TestTableService\TestTableService\Service References\AX\Reference.cs(20)]' to 'TestTableService.AX.CallContext' c:\users\adm_pfis\documents\visual studio 2013\Projects\TestTableService\TestTableService\Program.cs

    Data Type for Service Reference is: System.Collections.Generic.List. Do you know what the problem could be?


  2. Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.

    Selenium training in Chennai

  3. I cant wait to check out some of these blogs! I’ve really wanted to start learning more about cars and auto repairs lately and I think this will help a lot. I think it can save my family some money if we knew how to do some repairs at home.! Thanks again for all the options.

    bike spa services in mumbai
    house cleaning services in mumbai
    car wash services in mumbai

  4. A nice article here, i think that people who have grown up with the idea of using computers are showing more responsibility towards writing posts that are thoughtful, do not have grammar mistakes and pertinent to the post..

    Study Abroad Consultants in Chennai | Study in Germany Consultants in Chennai | Germany Education Consultants in Chennai

  5. Such a great articles in my carrier, It's wonderful commands like easiest understand words of knowledge in information's.

    seo training in chennai

  6. Great site for these post and i am seeing the most of contents have useful for my Carrier.Thanks to such a useful information.Any information are commands like to share him.

    digital marketing company in india

  7. It is little bit confusing me and i looking forward more things from your blog. it is really very well done.

    Web Design Company in Chennai

  8. This blog is having the general information. Got a creative work and this is very different one.We have to develop our creativity mind.This blog helps for this. Thank you for this blog. This is very interesting and useful.

    Dotnet Training in Chennai

  9. Great post! I am see the great contents and step by step read really nice information.I am gather this concepts and more information. It's helpful for me my friend. Also great blog here with all of the valuable information you have.
    Security Services in Chennai

  10. There are many interesting information included and i can easily understand all given information.I post something on my blog to post something, or wait to post something worth saying. Keep update more information....
    Office Interiors in Chennai
    Home Interior Decorators in Chennai

  11. hi,
    how to call Microsoft Dynamics AX 2012 – Calling SOAP Web Services from java.


  12. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

    Personal Installment Loans
    Payday Cash Advance loan
    Title Car loan
    Cash Advance Loan

  13. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Android Training in Chennai
    Ios Training in Chennai

  14. Anyone here have an idea why I can't seem to get sharepoint 2013 BCS to consume data from dynamics AX 2012 r3 web services? (The article is fine, but it seems I can't access the methods within sharepoint design, they don't show up).

  15. awesome post presented by you..your writing style is fabulous and keep update with your blogs thank you for sharing the postMicrostrategy Online Course Bangalore


  16. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.

    Restaurant in OMR
    Apartments in OMR
    Villas in OMR
    Resorts in OMR

  17. Hi,
    Its really interesting post and much informative. Here anybody having idea about my following requirement.

    I have integrate AX item master details to e-commerce portal via .net application as middle ware. I need a clarification which method i can follow effectively.
    What I have done so far.
    I created a custom service as per alex post here to export the item details using list. Its working now. but here the question is they want to receive as xml file format from ax when the send request to get list . How can i achieve this in ax with effective solution for integration.

    Thanks in Advance.

  18. Thanks for providing your information and keep share with us Azure Online Course Bangalore

  19. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.

    AWS Online Training | Online AWS Certification Course - Gangboard
    AWS Training in Chennai | AWS Training Institute in Chennai Velachery, Tambaram, OMR
    AWS Training in Bangalore |Best AWS Training Institute in BTM ,Marathahalli

  20. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    Java Training in Pune

  21. Thank you so much for a well written, easy to understand article on this. It can get really confusing when trying to explain it – but you did a great job. Thank you!
    python training in tambaram | python training in annanagar | python training in jayanagar

  22. Nice post. By reading your blog, i get inspired and this provides some useful information. Thank you for posting this exclusive post for our vision. 
    advanced excel training in bangalore

  23. Pleasant Tips..Thanks for Sharing….We keep up hands on approach at work and in the workplace, keeping our business pragmatic, which recommends we can help you with your tree clearing and pruning in an invaluable and fit way.
    Java training in Chennai | Java training in Bangalore

    Java online training | Java training in Pune

  24. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    best rpa training in bangalore
    rpa training in bangalore | rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

  25. Java is an Open source Platform. Open source platforms allows people to customize everything according to their needs, which intern creates lots of updates in Java periodically.

    Its mandatory to have the below skills in Java,

    Core Java
    Frameworks – Spring, Hibernate
    Web Services

    All The above and more process are available in JAVA Training. All tactics and facts of programming will be conducted in our institute. So the students are called us best Java Training Institute in Chennai.

    Java Training Course in Chennai | Java Training Course | Java Training | Java Training Institute | Java Training in Chennai | Java Training Institute in Chennai

  26. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
    Python Online certification training
    python Training institute in Chennai
    Python training institute in Bangalore

  27. This comment has been removed by the author.