Thursday, December 18, 2008

Consuming a Web Service in Dynamics AX 4

This will tell you how to use Common Language Runtime Interoperability feature in Dynamics AX 4 to reference a web service.  There is a pretty good discussion about this on Microsoft MBS community by Dilip and Mike Frank. 

To continue, at least you need to have Dot Net Framework SDK 2.0.  (Not Visual Studio .Net) We will use the language translation service on www.stanski.com as the referenced web service. 

Procedure:
Download and Install .NET Framework Version 2.0 Software Development Kit. 

Open a Microsoft .NET Framework command prompt. Click Start, point to All Programs, point to Microsoft .NET Framework SDK 2.0, and then click SDK Command Prompt. 

At the command prompt, run the following command:
Wsdl /l:cs /protocol:soap http://www.stanski.com/services/translate/translate.asmx
This will generate a C# source code file of proxy classe, which in this situation is TranslationService.cs 

Then we need to edit TranslationService.cs file to add namespace for it. 
Use NotePad to edit TranslationService.cs, the edited codes should look like
//------------------------------------------------------------------------------
//
namespace DemoAXWebService //Add namespace declaration 
{
    using System;
    …
    …
}//End namespace declaration 

Compile the cs file to dll file. Type this in the command prompt
csc /t:library TranslationService.cs 

This will generate the TranslationService.dll. 
Copy the TranslationService.dll to \Program Files\Microsoft Dynamics AX\40\client\Bin. 

Start Microsoft Dynamics AX 4.0
Open Application Object Tree, and locate the Reference node. Right click, select Add Reference and register the TranslationService.dll in Dynamics AX. 

Create a new job named TestWebService
static void TestWebService(Args _args)
{
    DemoAXWebService.TranslationService translateService
     = new DemoAXWebService.TranslationService();
    str strLanguage, strMessage;
    str translateResult;
    ; 

    strLanguage = 'en_de';
    strMessage  = 'Test Web Service';
    translateResult = translateService.Translate(strLanguage, strMessage);
    Info(translateResult);

Run the job, you will get the result “Test-Netz-Service”. 

No comments:

How to identify the user that was used to change an object from AOT in AX2012

Get the object name for which we need to track these (user and date&time) information's. Login to SQL Server Management Studio an...