Consume an external web service (exchange rates) in AX 2009

Hi,

During my career I have never had the opportunity to write X++ code that consumes an external web services…

I am trying to get exchange rates from the Swedish Riksbank (the central bank of Sweden) through their web service API (swea.riksbank.se/…/index.htm ).

I add a service reference in AX and enters the URL to the wsdl location (swea.riksbank.se/…/sweaWS.wsdl ). Then I create a class with a method which looks something like this:

public static server Exchrate getRate()
{
netCurrencyService.SweaWebServicePortTypeClient soapClient;
ExchRate conversionrate;
str rates[2];

;

try
{
new InteropPermission(InteropKind::ClrInterop).assert();

soapClient = new netCurrencyService.SweaWebServicePortTypeClient();

rates[1] = “SEKUSDPMI”;
rates[2] = “SEKGBPPMI”;

conversionrate = soapClient.getLatestInterestAndExchangeRates(“en”, rates);
CodeAccessPermission::revertAssert();

return conversionrate;

}
catch(Exception::CLRError)
{
throw error(AifUtil::getClrErrorMessage());
}

}

My problem is that the code does not compile. The call “soapClient.getLatestInterestAndExchangeRates(“en”, rates)” indicates that argument 2 (“rates”) is incorrect. If I enter a string instead the compiler says that the class netCurrencyService.SweaWebServicePortTypeClient doesn’t include this function (“getLatestInterestAndExchangeRates”?).

Any suggestions?

In my case, getLatestInterestAndExchangeRates() accepts LanguageType and String[]. If I use fully qualified names, expected parameters are:

  1. netCurrencyService.LanguageType
  2. System.String[]

Therefore, declare rates as System.String[]:

System.String[] rates = new System.String[2]();

Add values to the array:

rates.SetValue("SEKUSDPMI", 0);
rates.SetValue("SEKUSDPMI", 1);

And call the method:

soapClient.getLatestInterestAndExchangeRates(
    netCurrencyService.LanguageType::en,
    rates);

Then you’ll also find that it returns netCurrencyService.Result, not ExchRate.

Excellent - thank you!

/Johan

Johan, did you extract the rates from the response…result?
Didn’t you get the “Clr Interop Marshal: Unsupported type.” (I’m stuck)
//Toni