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

63 comments:

  1. 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
  2. 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
  3. Great post going through your articles..this is really helping.

    QTP Training in Chennai

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


  5. 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
  6. 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
  7. 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
  8. Really Good article.provided a helpful information about Microsoft dynamics AX 2012 class libraries.keep updating...
    E-mail marketing company in india

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

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    Machine learning training in chennai
    machine learning course fees in chennai
    top institutes for machine learning in chennai

    ReplyDelete

  19. I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again.

    Deer Hunting Tips Camping Trips Guide DEER HUNTING TIPS travel touring tips

    ReplyDelete
  20. Are you looking for a business loan, personal loans, mortgage loans, car loans, student loans, unsecured consolidation loans,project funding etc ... Or simply refuse loan from a bank or financial institution for one or more reasons? We are the right solutions for credit! We offer loans to businesses and individuals with low and affordable interest rate of 2%. So if you are Interested in an urgent and secured loan. For more information kindly email us today Via: elegantloanfirm@hotmail.com.



    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. Thanks dear. Very useful. Appreciated.

    ReplyDelete
  23. I truly love this post..
    Thanks for sharing with us,
    We are again come on your website,
    Thanks and good day,
    Please visit our site,
    buylogo

    ReplyDelete
  24. I now own a business of my own with the help of Elegantloanfirm with a loan of $900,000.00 USD. at 2% rate charges, at first i taught with was all a joke until my loan request was  process under five working days and my requested funds was transfer to me. am now a proud owner of a large business with 15 staffs working under me. All thanks to the loan officer Russ Harry he is a God sent, you can contact them to improve your business on.. email-- Elegantloanfirm@hotmail.com.

    ReplyDelete
  25. azure online training Thanks for sharing such a great information..Its really nice and informative..

    ReplyDelete
  26. Thanks for sharing such a great information..Its really nice and informative.. azure online training

    ReplyDelete
  27. I think this is a really good article.Thank you so much for sharing.It will help everyone.Keep Post.
    Data Science Training in Hyderabad

    ReplyDelete
  28. Effective blog with a lot of information. I just Shared you the link below for Courses .They really provide good level of training and Placement,I just Had Microsoft Dynamics Classes in this institute,Just Check This Link You can get it more information about the Microsoft Dynamics course.


    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  29. Good Post! Thank you so much for sharing this pretty post of Digital marketing, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    python Training in chennai

    python Course in chennai

    ReplyDelete
  30. Title:
    Big Data Hadoop Training in Chennai | Infycle Technologies

    Description:
    Did you want to set your career towards Big Data? Then Infycle is with you to make this into reality. Infycle Technologies gives the combined and best Big Data Hadoop Training in Chennai, in 100% hands-on training guided by specialized trainers in the field. In addition to this, the mock interviews will be given to the candidates, so that they can face the interviews with complete confidence. Apart from all, the candidates will be placed in the top MNC's with a great salary package. To get it all, call 7502633633 and make this happen for your happy life.

    Best training in Chennai

    ReplyDelete
  31. Link:
    https://infycletechnologies.com/java-training-in-chennai/

    Keywords:
    If Java Development is a field that you're dreaming of, then we, Infycle, are with you to make your dream into reality. Infycle Technologies offers the best Java Training in Chennai, with various highly demanded software courses such as Big Data, AWS, Python, Hadoop, AWS, etc., in 100% practical training with specialized tutors in the field. Along with that, the pre-interviews will be given for the candidates to face the interviews with complete knowledge. To know more, dial 7502633633 for more.

    best training institute in chennai

    ReplyDelete
  32. HELLO GET OUT OF FINANCIAL MESS WITH THE HELP OF drbenjaminfinance@gmail.com

    I have been in financial mess for the past months, I’m a single mum with kids to look after. My name is REBECCA MICHAELSON, and am from Ridley Park, Pennsylvania. A couple of weeks ago My friend visited me and along our discussion she told me about DR BENJAMIN OWEN FINANCE of (drbenjaminfinance@gmail.com); that he can help me out of my financial situation, I never believed cause I have spend so much money on different loan lenders who did nothing other than running away with my money. She advised, I gave it a try because she and some of her colleagues were rescued too by this Godsent lender with loans to revive their dying businesses and paying off bills. so I mailed him and explain all about my financial situation and therefore took me through the loan process which was very brief and easy. After that my loan application worth $278,000.00USD was granted, all i did was to follow the processing and be cooperative and today I am a proud business owner sharing the testimony of God-sent Lender. You can as well reach him through the Company WhatsApp +19292227023 Email drbenjaminfinance@gmail.com

    THANK YOU VERY MUCH

    ReplyDelete
  33. Very Informative blog thank you for sharing. Keep sharing.

    Best software training institute in Chennai. Make your career development the best by learning software courses.

    blue prism course in chennai
    rpa training in chennai
    best msbi training institute in chennai

    ReplyDelete
  34. This is one of the brilliant article, spent plenty of time reading and understanding it. Thanks for posting this useful information.

    Web Application Development

    ReplyDelete
  35. This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses.
    data analytics training in hyderabad

    ReplyDelete
  36. wow really good informision got lot to learn. looking forward for more informative posts from you.
    French Online Course | French Language Course | Online French Courses

    ReplyDelete
  37.  Herbal Supplement for Health and Skin Diseas to help improve the appearanceHome Remedies for Granuloma Annulare, grape seed extract is one of my favorite ingredients. In medical science, grape seed extractNatural Remedies for Granuloma Annulare is Vitamin E oil.— Herbal Supplement for Granuloma Annulare which may help explainHerbal Remedies for Granuloma Annulare for soothing your skin and reducing inflammation.

    ReplyDelete
  38. One of several ways you can treat granuloma annulare is using a potent and effective Herbal Remedies for Granuloma Annulare. Herbal supplements for granuloma annulare include milk thistle, borage oil, dandelion root, red clover extract, burdock root, white willow bark, and St. John’s wort, among others. It would help if you chose a 100% natural herbal supplement that contains only pure herbs without fillers or additives.

    ReplyDelete
  39. The typical symptom of Hydrocele is enlargement or swelling around a testicle.The Natural Remedies for Hydrocele involves surgery to correct any anatomical defect in your child’s scrotum. These additional Herbal Remedies for Hydrocele include herbal medicine like Celdeton Hydrocele.Natural Cure Zone strongly recommends that you consult with your primary healthcare provider before starting any Herbal Supplements.Herbal Supplement for Hydrocele can be treated naturally with herbal supplements.

    ReplyDelete
  40. Ginger is used as Natural Remedies for Abdominal Adhesions,Turmeric is a well-known herb and Natural Treatment for Abdominal Adhesions discomfort, which can be caused by a variety of factors.It has antispasmodic, cardioprotective, and heart muscle strengthening effects, and it is also Alternative Treatment for Abdominal Adhesions.Herbal Supplement for Abdominal Adhesions, you should seek medical attention.

    ReplyDelete
  41. After being diagnosed with the problem, Natural Treatment for Abdominal Adhesions should be started right away. Sedeton, a herbal supplement, is the best treatment for it.But if you are afeared from surgical treatment then must try Herbal Supplement for Abdominal Adhesions.. It's also been shown to help regulate bowel motions and ease stomach pains and cramps, which are signs of partial intestinal obstruction caused by abdominal adhesions. Follow the instructions on the package for the most effective Alternative Treatment for Abdominal Adhesions.

    ReplyDelete
  42. Hey,
    This comprehensive tutorial on integrating Microsoft Dynamics AX 2012 with external class libraries and web services is invaluable. The step-by-step instructions and code examples make it easy to follow. Great work!
    Data Analytics Courses In Dubai

    ReplyDelete
  43. Your commitment to sharing your knowledge and expertise in this area is greatly appreciated. Thank you for sharing your expertise.
    Data Analytics Courses In Chennai

    ReplyDelete
  44. This thorough guide on use external class libraries and web services with Microsoft Dynamics AXE 2012 is quite helpful. It is simple to follow thanks to the step-by-step instructions and code examples.
    Data Analytics Courses in Agra

    ReplyDelete
  45. The step-by-step instructions and insights you've provided are invaluable for developers and business professionals looking to streamline their operations.

    Digital marketing courses in illinois

    ReplyDelete
  46. thanks for sharing such well written blog post, great work
    Digital marketing business

    ReplyDelete