web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

how to consume external web service in d365fo

(0) ShareShare
ReportReport
Posted on by 30

Hi All,

I followed below link to consume external web services on my VM ( D365FO)

https://subscription.packtpub.com/book/application_development/9781786468864/9/09lvl1sec93/consuming-external-web-services

I have done almost but stuck in to declare namespace in D365FO.

They mentioned 

  1. Now add a runnable class in your Operation Project, name it ConsumeServiceInDAX, and add a namespace of:
Copy
        using ExternalWebServices; 
  1. Add the following code in the main method:
Copy
        ExternalWebServices.currencyConverter currencyCoverter =
          new ExternalWebServices.currencyConverter(); 
        var convRate = str2Num(currencyCoverter.getCurrencyRate("USD",
          "INR")); 

I stuck in point no 11 only.
how to declare the namespace ?? i tried with below code...

class ConsumeServiceInDAX
{

namespace ExternalWebServices;
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
ExternalWebServices.currencyConverter currencyCoverter =
new ExternalWebServices.currencyConverter();
var convRate = str2Num(currencyCoverter.getCurrencyRate("USD","INR"));
info(strFmt("%1", convRate));
}

}
but getting error which build...
6355.error.jpg

Kindly help me

Thanks!
I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    "Using" keyword is used in C# development, not x++.

    I recommend you start by checking the official Microsoft documentation on the topic: https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/consume-external-web-service

  • Verified answer
    Martin Dráb Profile Picture
    238,536 Most Valuable Professional on at

    "using" keyword exists in X++ as well (it was introduced in AX 7), but it doesn't have namespace. Namespaces can be used only in C# and they are outside classes. It's the namespace that contain classes; not that classes contain namespaces.

    According to your X++ code, you should have currencyConverter class inside ExternalWebServices namespace.

  • @rp@n Profile Picture
    30 on at

    thanks Martin

    as you said, i have already created a class "Currency Converter"

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using ExternalWebServices.CurrencyConverterService;

    using System.ServiceModel;

    namespace ExternalWebServices

    {

       public class CurrencyConverter

       {

           public string getCurrencyRate(String cur1, string cur2)

           {

               BasicHttpBinding httpBinding = new BasicHttpBinding();

               EndpointAddress endPoint = new EndpointAddress(

                 @"currencyconverter.kowabunga.net/converter.asmx");

               var soapClient = new ConverterSoapClient(httpBinding, endPoint);

               var usdToinr = soapClient.GetConversionRate(cur1.ToString(), cur2.ToString(), DateTime.Now);

               return usdToinr.ToString();

           }

       }

    }

    Kindly let  me know what code need to be change in below class

    class ConsumeServiceInDAX

    {

     /// <summary>

    /// Runs the class with the specified arguments.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

    ExternalWebServices.currencyConverter currencyCoverter =

    new ExternalWebServices.currencyConverter();

    var convRate = str2Num(currencyCoverter.getCurrencyRate("USD","INR"));

    info(strFmt("%1", convRate));

    }

    }

    if i removed " namespace ExternalWebServices" then getting below error

    6320.error2.jpg

    Thanks!

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Did you already look at the Microsoft documentation that I provided? I'm quite sure you have missed step 6 of the process.

    "Add ExternalServiceLibrary.dll as a reference."

    Before asking more questions, please tell us what steps of the doc you managed to finish succesfully. And if you chose to ignore some steps, please tell that too. But you should really follow the instructions in the doc.

  • @rp@n Profile Picture
    30 on at

    Hi Nikoloas,

    That i have already added. So, i am asking....

    0702.error3.jpg

  • @rp@n Profile Picture
    30 on at

    The process which i followed to add "ExternalWebService" under references

    2543.error4.jpg

    If anything wrong please let me know

  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Is your c# class name currencyConverter or CurrencyConverter? You need to use the correct case.

  • @rp@n Profile Picture
    30 on at

    Thanks Nikoloas,

    I changed to CurrencyConverter. then build. no error

  • @rp@n Profile Picture
    30 on at

    finally i ran the class and getting below error

    ERROR6.jpg

    Kindly let me know how to reslove this

  • Suggested answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    The error says that the web service that you are calling doesn't allow anonymous calls. Perhaps it requires some authentication?

    Please study the documentation of that web service. You can debug it further in your C# code.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 612 Super User 2025 Season 2

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 437 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans