如何更新现有汇率

时间:2013-12-16 22:36:45

标签: c# axapta dynamics-ax-2012

每当我尝试使用ExchangeRateServiceClient货币代码对时使用client.create,我都会遇到异常

  

无法在汇率货币对(ExchangeRateCurrencyPair)中创建记录。从货币:美元,欧元。记录已存在。
  System.Exception {System.ServiceModel.FaultException}

我是AX API的新手......我正在使用C#

AXDev09.ExchangeRateServiceCreateRequest request = 
new AXDev09.ExchangeRateServiceCreateRequest();
AXDev09.ExchangeRateServiceClient client = new AXDev09.ExchangeRateServiceClient();

request.CallContext = new AXDev09.CallContext();
request.CallContext.Language = "en-us";
request.CallContext.Company = "T51";
request.CallContext.MessageId = Guid.NewGuid().ToString();

AXDev09.AxdEntity_CurrencyPair[] myPair = new AXDev09.AxdEntity_CurrencyPair[1];
myPair[0] = new AXDev09.AxdEntity_CurrencyPair();
myPair[0].ToCurrencyCode = "EUR";  
myPair[0].FromCurrencyCode = "USD";

AXDev09.AxdEntity_ExchangeRate[] myExchange = new AXDev09.AxdEntity_ExchangeRate[1];
myExchange[0] = new AXDev09.AxdEntity_ExchangeRate();
myExchange[0].ExchangeRate = Convert.ToDecimal("0.708");
myExchange[0].ExchangeRateSpecified = true;

myPair[0].ExchangeRate = myExchange;
myPair[0].ExchangeRateDisplayFactor = AXDev09.AxdEnum_ExchangeRateDisplayFactor.One;
myPair[0].ExchangeRateType = "Average";

AxdType_DateTime myFromDate = new AxdType_DateTime();
myFromDate.localDateTime = DateTime.Now.ToUniversalTime();
myFromDate.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;
myFromDate.Value = myFromDate.localDateTime;

AxdType_DateTime myToDate = new AxdType_DateTime();
myToDate.localDateTime = DateTime.Now.ToUniversalTime();
myToDate.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;
myToDate.Value = myToDate.localDateTime;

request.LedgerExchangeRate = new AXDev09.AxdLedgerExchangeRate();
request.LedgerExchangeRate.CurrencyPair = myPair;
request.LedgerExchangeRate.ValidFromDateTime = myFromDate;
request.LedgerExchangeRate.ValidToDateTime = myToDate;

client.Open();

client.create(request.CallContext, request.LedgerExchangeRate);
client.Close();

2 个答案:

答案 0 :(得分:0)

ExchangeRateServiceClient似乎确实是标准API。

标准Web服务称为LedgerExchangeRateService

如果您提供两种货币,请尝试撤消它们。

答案 1 :(得分:0)

如果要相信错误消息,似乎问题是它何时尝试创建ExchangeRateCurrencyPair

有一个无重复索引:

  • fromCurrency
  • toCurrency
  • ExchangeRateType

"我正在尝试添加一个新的货币汇率...来自from-to的新集合但我一直在"记录已经存在"因为我设置了新的FROM-TO日期,所以会出现错误。"

它似乎反对ExchangeRateCurrencyPair(而不是日期有效位)可能尝试选择该对而不是每次都尝试创建它 - 或者尝试通过成功的新对调试以查看是否需要调整在标准服务中