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
//——————————————————————————
// <auto-generated>

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 FilesMicrosoft Dynamics AX40clientBin.

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”.

 

Advertisements
This entry was posted in Axapta Development. Bookmark the permalink.

One Response to Consuming a Web Service in Dynamics AX 4

  1. Søren Regenberg says:

    Hi Fred

    This is just what I needed. Adding the namespace to the CS file did the trick. Many thanks and please drop an email if I can do anything.

    Søren

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s