Consuming External Web Services (Dynamics AX 4)
Version: Dynamics AX 4.
In today's world of complex business processes, it is not always desirable or possible for companies to implement or customize all aspects of their business applications in-house. At the same time, service providers offer a wide variery of solutions for specific business problems, such as tax services (sales tax, etc), regulatory services (OFAC, etc), unified messaging (instant messaging, phone notifications, etc), eCommerce (e.g. Amazon, EBay, and many others), etc.
Businesses benefit from outsourcing areas which are not their core competencies to such external service providers. They can rely on the service providers' expertise in the respective area. and don't have to worry about currency of the data, reliability of the service, etc. Various service providers implement different business models and SLAs around the services they offer.
Nowadays, one of the most popular, low-cost ways of integrating external applications with an enterprise application (such as Dynamics AX) is through web services. This blog walks through the steps necessary for consuming external web services from within the Dynamics AX 4 application.
All code used below is meant for illustration purposes only and not intended for use in production. The following disclaimer applies to all code used in this blog:
Copyright (c) Microsoft Corporation. All rights reserved. THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. USE AND REDISTRIBUTION OF THIS CODE, WITH OR WITHOUT MODIFICATION, IS HEREBY PERMITTED.
Visual Studio (in this example, we use version 2005)
3.1Create proxy classes from the WSDL
a. Open Visual Studio
b. Create a new project of type "Class Library" with the name "ClassLibrary1" (default name)
c. Right-click on the project and select "Add Web Reference"
i. For the URL enter: http://soap.search.msn.com/webservices.asmx?wsdl
ii. For the reference name enter: LiveSearch
iii. Click "Add Reference"
d. In the project's properties, under "Signing", check "Sign the assembly" (assembly must be strong-named)
e. Build the solution and verify that a file named "ClassLibrary1.dll" appears in Visual Studio's output folder
f. Add the DLL proxy to the GAC
i. Open a Visual Studio command prompt
ii. Navigate to the folder that contains ClassLibrary1.dll
iii. In the command prompt, type "gacutil /i ClassLibrary1.dll"
Note: Adding this assembly to the GAC is not necessarily recommended and is intended for testing;
an alternative approach for trusted assemblies would be to move the assembly into the .NET Assembly directory for Microsoft Dynamics AX (refer to the product documentation to locate that directory)
3.2 Add the proxy as an AX reference
a. Open the Dynamics AX client
b. Open an AOT instance
c. In AOT, right-click on the AOT node “References”
d. Select “Add Reference”
e. Navigate to the folder that contains "ClassLibrary1.dll" and add the DLL as a reference
f. Verify that the proxy DLL now appears as a child under the AOT node “References”
3.3 Use the proxy from X++ (through CLR Interop)
a. Refer to CLR documentation for details on how to access .NET assemblies from X++
b. Create a new job "LiveSearchTest" and discover the .NET generated proxy class classes with IntelliSense
c. Instantiate the (.NET) proxy just as with any other class:
e.g. “ClassLibrary1.LiveSearch.MSNSearchService service = new ClassLibrary1.LiveSearch.MSNSearchService();”
d. See attachment for a sample job for consuming the LiveSearch web service from X++. Note that you will need an application ID that you can obtain at http://dev.live.com/search.