Monday, June 1, 2015

Microsoft Dynamics AX 2012 Class Libraries (DLLs)

Microsoft Dynamics AX 2012 Class Libraries (DLLs)
 
Purpose: The purpose of this document is to illustrate how to work with class libraries in the context of Microsoft Dynamics AX 2012.
 
Challenge: For the purposes of POC, integration project or development project you may need to consume Microsoft Dynamics AX 2012 Web Services from external class libraries or call external Web Services from Microsoft Dynamics AX 2012 managed code assemblies.
 
Solution: In this walkthrough I'm going to highlight number of ways you can consume Microsoft Dynamics AX 2012 Web Services from external class library using configuration settings in application config file or handled in the application code. Also I will highlight how develop Microsoft Dynamics AX 2012 managed code assemblies and then call external Web Services from there.
 
Walkthrough
 
Calling Microsoft Dynamics AX 2012 Web Service from external Class Library (DLL)
 
First of all I will expose Microsoft Dynamics AX 2012 Web Services via Inbound ports using NET.TCP and HTTP adapters
 
Inbound port (NET.TCP)
 
 
Inbound port (HTTP)
 
 
IIS
 
 
After Web Services have been exposed through Inbound ports in your client application you can Add Service Reference using WSDL URI as shown below
 
Add Service Reference (NET.TCP)
 
 
Add Service Reference (HTTP)
 
 
Added Service Reference will show up in your project as below
 
Solution Explorer (Console App)
 
 
Please note that corresponding Endpoint and Binding details will be added to App.config after you added Service Reference
 
App.config
 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_AdvancedLedgerEntryService" />
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://ax2012r2a:8201/DynamicsAx/Services/AlexServices"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_AdvancedLedgerEntryService"
contract="ServiceReference1.AdvancedLedgerEntryService" name="NetTcpBinding_AdvancedLedgerEntryService">
                <identity>
                    <userPrincipalName value="admin@Contoso.com" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
 
Now I’ll create a class library project and Add Service Reference too
 
Solution Explorer (Class Library)
 
 
Similarly to above corresponding Endpoint and Binding details will be added to App.config 
 
App.config
 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_AdvancedLedgerEntryService" />
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://ax2012r2a:8201/DynamicsAx/Services/AlexServices"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_AdvancedLedgerEntryService"
contract="ServiceReference1.AdvancedLedgerEntryService" name="NetTcpBinding_AdvancedLedgerEntryService">
                <identity>
                    <userPrincipalName value="admin@Contoso.com" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
 
In fact when leveraging business logic from class library you have to use client application config file instead of original DLL config file. That’s why I will copy Endpoint and Binding details from DLL config file over to client app config file
 
Client application Config file
 
<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name="NetTcpBinding_AlexService" />
            </netTcpBinding>
        </bindings>
        <client>
            <endpoint address="net.tcp://ax2012r2a:8201/DynamicsAx/Services/AlexServices"
                binding="netTcpBinding" bindingConfiguration="NetTcpBinding_AlexService"
                contract="AXServiceReference.AlexService" name="NetTcpBinding_AlexService">
                <identity>
                    <userPrincipalName value="admin@Contoso.com" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
 
Now my client application will be well aware about Endpoint and Binding details for Microsoft Dynamics AX 2012 Web Service
 
Alternatively you can handle Endpoint and Binding details for Microsoft Dynamics AX 2012 Web Service directly in client application code as shown below  
 
Client application Code
 
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
 
EndpointAddress address = new EndpointAddress("http://ax2012r2a.contoso.com/MicrosoftDynamicsAXAif60/AlexWebServices/xppservice.svc");
 
AlexServiceClient client = new AlexServiceClient(binding, address);
 
CallContext context = new CallContext();
context.Company = "usmf";
 
client.ClientCredentials.Windows.ClientCredential.Domain = "contoso";
client.ClientCredentials.Windows.ClientCredential.UserName = "Admin";
client.ClientCredentials.Windows.ClientCredential.Password = "pass@word1";
 
try
{
    client.method1(context);
}
catch (Exception e)
{
 
}
 
Call external Web Service from Microsoft Dynamics AX 2012 Class Library (DLL)
 
In the second part of the walkthrough I’m going to wrap a business logic calling external Web Service with Microsoft Dynamics AX 2012 managed code assembly
 
First off I’ll create Class Library project with minimalistic implementation for a single class and method which mimic calling external Web Service
 
Class Library  
 
 
As coding is complete I’ll add Class Library project directly into Microsoft Dynamics AX 2012 AOT. Please note that I have Microsoft Dynamics AX 2012 Visual Studio Tools installed to accomplish this: https://technet.microsoft.com/en-us/library/dd309576.aspx
 
My project now will change its icon to Microsoft Dynamics specific one, after that I’ll be able to select auto-deployment options in Project Properties. Specifically I will choose to deploy assembly to Microsoft Dynamics AX 2012 Client (Yes) and Server (Yes)
 
Class Library (Deployment)
 
 
After successful deployment my project will show up in Microsoft Dynamics AX 2012 AOT
 
AOT – C Sharp Projects
 
 
Here’s the implementation of class and method which mimic calling external Web Service from within Microsoft Dynamics AX 2012 managed code assembly
 
Source code
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AlexDLL
{
    public class Class1
    {
        public string method1()
        {
            return "External Web Service call";
        }
    }
}
 
Generally it would be a good idea to encapsulate business logic calling external Web Service in a single method in managed code assembly, this way you can simply call a single method in X++ to consume Web Service and obtain the result
 
When deploying assemblies from within Visual Studio you may need to make sure that “Enable the hot-swapping of assemblies for each development session” setting is selected in Microsoft Dynamics AX 2012 Server Configuration Utility in order to avoid deployment errors
 
Microsoft Dynamics AX 2012 Server Configuration Utility
 
 
Before you deploy you will need to Sign the assembly in Project Properties > Signing
 
Create Strong Name Key
 
 
Now we are ready to deploy the assembly
 
Deploy
 
 
Upon successful deployment you will be able to use IntelliSense in X++ and consume elements of managed code assembly namespace just the way you consume native X++ business logic classes
 
X++ code
 
static void DLL(Args _args)
{
    AlexDLL.Class1 class1 = new AlexDLL.Class1();
 
    info(class1.method1());
}
 
The result will look like below
 
Result
 
 
Please learn more about Deploying Managed Code Assemblies here: https://msdn.microsoft.com/en-us/library/gg889192.aspx
 
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, X++, C#.NET, HTTP, NET.TCP, Config file, Class library, DLL, Endpoint, Binding.
 
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

47 comments:

  1. Recipe costing software Our recipe, menu management and food costing software frees up your time so you can focus on running your business.

    ReplyDelete
  2. Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    J2ee training in chennai

    ReplyDelete
  3. Dear Alex,

    We are trying to integrate 2 separate AX implementations using AIF.

    Steps:
    1. Create AIF service in AX environment 1.
    2. Wrote a .NET wrapper around the AIF, using a class library project type and added the service reference.
    3. Deployed class library project in AOT of AX environment 2 and also added classlibrary.dll and classlibrary.dll.config in the Bin folder of 2nd environment and than added reference to dll in the AOT.
    4. We finally wrote X++ job to call(consume) the class library that was added in the AOT.

    Exception :
    System.InvalidOperationException: Could not find default endpoint element that references contract 'AMSSVCSR.HREMPAIFService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.



    ReplyDelete

  4. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.

    Online Reputation Management

    ReplyDelete
  5. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing

    dot net training in chennai

    php training in chennai

    java training in chennai

    ReplyDelete
  6. for preparing bank exam and group exam , we are providing an online test model questions papers

    Bank Exam Questions and Answers

    Group Exam Questions and Answers

    ReplyDelete
  7. Great post going through your articles..this is really helping.

    QTP Training in Chennai

    ReplyDelete
  8. Hi there, You have done an incredible job. I’ll definitely digg it and personally recommend to my friends. I’m sure they’ll be benefited from this site..Keep update more excellent posts..

    Back to original

    ReplyDelete
  9. This idea is mind blowing. I think everyone should know such information like you have described on this post. Thank you for sharing this explanation.


    Best Dental Clinic In Vellore

    ReplyDelete


  10. Truely a very good article on how to handle the future technology. After reading your post,thanks for taking the time to discuss this content.

    Digital Marketing Company in Chennai

    ReplyDelete
  11. This blog is very well done, thus it is very well useful too, so i am expecting more things from your blog.

    Digital Marketing Company in Chennai

    ReplyDelete
  12. I read your articles very excellent and the i agree our all points because all is very good information provided this through in the post.

    Web Design Company in Chennai

    ReplyDelete
  13. I read your articles very excellent and the i agree our all points because all is very good information provided this through in the post.

    Digital Marketing Company in Chennai

    ReplyDelete
  14. Great post!I am actually getting ready to across this information,i am very happy to this commands.Also great blog here with all of the valuable information you have.Well done,its a great knowledge.

    AWS Training in Chennai

    ReplyDelete
  15. I was researching on the best methods of How to Compose a College Research Paper before I landed on this page and I have found an interesting blog with great article and design that is worth commenting on. I am looking forward to reading more interesting and intriguing articles from this site and I hope the writer will continually keep us updated with new articles.

    ReplyDelete

  16. Wonderful blog.. Thanks for sharing informative Post. Its very useful to me.

    Installment loans
    Payday loans
    Title loans

    ReplyDelete
  17. Really Good article.provided a helpful information about Microsoft dynamics AX 2012 class libraries.keep updating...
    E-mail marketing company in india

    ReplyDelete
  18. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic.


    Pawn Shop

    Pawn Loans

    Pawn Shops

    Pawn Loan

    Pawn Shop near me

    ReplyDelete
  19. It is nice blog Thank you porovide importent information and i am searching for same information to save my TimeMicrostrategy Online course Hyderabad

    ReplyDelete
  20. Omrdeals.in is an online platform that allows people to find offers and the greatest deals in and around OMR. It is the directory of the business in and around omr. It helps internet users to surf the required deals and offers.

    Offers in Chennai

    ReplyDelete
  21. This is such a great resource that you are providing and you give it away for free. I love seeing websites that understand the value of providing a quality resource for free. It is the old what goes around comes around routine.
    hotmail.com iniciar sesion

    ReplyDelete
  22. Benefits of reading your post. This will help in the maintenance of our health.The daily routine will help you lose weight quickly and safely.My life is totally transformed after I followed this diet.I feeling great about myself.

    Herbalife in Chennai
    Nutritionclub in Chennai
    Weight Loss in Chennai
    Weight Gain in Chennai

    ReplyDelete
  23. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Click here:
    angularjs training in chennai
    Click here:
    angularjs2 training in chennai
    Click here:
    angularjs4 Training in Chennai
    Click here:
    angularjs5 Training in Chennai
    Click here:
    angularjs training in tambaram

    ReplyDelete
  24. 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

    ReplyDelete
  25. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    DevOps online Training|DevOps Training in USA
    Devops Training in Chennai

    Devops Training in Bangalore

    ReplyDelete
  26. Have you been thinking about the power sources and the tiles whom use blocks I wanted to thank you for this great read!! I definitely enjoyed every little bit of it and I have you bookmarked to check out the new stuff you post

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete
  27. All the latest updates from the Python Automationminds team. Python Automationminds lets you program in Python, in your browser. No need to install any software, just start coding straight away. There's a fully-functional web-based console and a programmer's text-editor
    Phyton training in Chennai

    ReplyDelete
  28. Really very nice blog information for this one and more technical skills are improve,i like that kind of post.

    java training in chennai | java training in bangalore

    java online training | java training in pune

    ReplyDelete
  29. This is good site and nice point of view.I learnt lots of useful information.
    python training in tambaram | python training in annanagar | python training in jayanagar

    ReplyDelete
  30. Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
    advanced excel training in bangalore

    ReplyDelete
  31. Does your blog have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some recommendations for your blog you might be interested in hearing.
    AWS Training in Chennai |Best Amazon Web Services Training in Chennai
    AWS Training in Rajaji Nagar | Amazon Web Services Training in Rajaji Nagar

    Best AWS Training Institute in BTM Layout Bangalore ,AWS Coursesin BTM

    ReplyDelete
  32. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

    Java training in Annanagar | Java training in Chennai

    Java training in Chennai | Java training in Electronic city

    ReplyDelete
  33. Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.
    Data Science training in Chennai | Data science training in bangalore

    Data science training in pune | Data science online training

    Data Science Interview questions and answers

    ReplyDelete
  34. Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.

    angularjs Training in marathahalli

    angularjs interview questions and answers

    angularjs Training in bangalore

    angularjs Training in bangalore

    angularjs Training in chennai

    ReplyDelete
  35. Really very nice blog information for this one and more technical skills are improve,i like that kind of post.

    advanced excel training in bangalore

    ReplyDelete
  36. Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

    DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

    Good to learn about DevOps at this time.


    devops training in chennai | devops training in chennai with placement | devops training in chennai omr | devops training in velachery | devops training in chennai tambaram | devops institutes in chennai | devops certification in chennai | trending technologies list 2018

    ReplyDelete
  37. Amazon has a simple web services interface that you can use to store and retrieve any amount of data, at any time, from anywhere on the web. Amazon Web Services (AWS) is a secure cloud services platform, offering compute power, database storage, content delivery and other functionality to help businesses scale and grow.For more information visit.
    aws online training
    aws training in hyderabad
    aws online training in hyderabad

    ReplyDelete
  38. I’ve bookmarked your site, and I’m adding your RSS feeds to my Google account.
    nebosh course in chennai

    ReplyDelete