Created
July 8, 2011 22:12
-
-
Save fraga/1072951 to your computer and use it in GitHub Desktop.
how to connect to microsoft dynamics ax 2012 WCF Currency services using a create request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using CurrencyServiceExample.DAX.Services; | |
namespace CurrencyServiceExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
//This will CREATE a new PAIR OF EXCHANGE rates | |
ExchangeRateServiceCreateRequest request = new ExchangeRateServiceCreateRequest(); | |
ExchangeRateServiceClient client = new ExchangeRateServiceClient(); | |
request.CallContext = new CallContext(); | |
request.CallContext.Language = "en-us"; | |
request.CallContext.Company = "TST"; | |
request.CallContext.MessageId = Guid.NewGuid().ToString(); | |
AxdEntity_CurrencyPair[] pair = new AxdEntity_CurrencyPair[1]; | |
pair[0] = new AxdEntity_CurrencyPair(); | |
pair[0].FromCurrencyCode = "CAD"; | |
pair[0].ToCurrencyCode = "BRL"; | |
AxdEntity_ExchangeRate[] exchRates = new AxdEntity_ExchangeRate[1]; | |
exchRates[0] = new AxdEntity_ExchangeRate(); | |
exchRates[0].ExchangeRate = new Decimal(1.61); | |
exchRates[0].ExchangeRateSpecified = true; | |
pair[0].ExchangeRate = exchRates; | |
pair[0].ExchangeRateDisplayFactor = AxdEnum_ExchangeRateDisplayFactor.Hundred; | |
pair[0].ExchangeRateType = "Average"; | |
AxdType_DateTime dateTimeValidFrom = new AxdType_DateTime(); | |
//here you can specify current timezone and localtime | |
dateTimeValidFrom.localDateTime = DateTime.Now.ToUniversalTime(); | |
//dateTimeValidFrom.localDateTimeSpecified = true; | |
dateTimeValidFrom.timezone = AxdEnum_Timezone.GMTMINUS0500EASTERNTIME; | |
dateTimeValidFrom.Value = dateTimeValidFrom.localDateTime; | |
AxdType_DateTime dateTimeValidTo = new AxdType_DateTime(); | |
dateTimeValidTo.localDateTime = DateTime.Now.AddDays(2).ToUniversalTime(); | |
//dateTimeValidFrom.localDateTimeSpecified = true; | |
dateTimeValidTo.timezone = AxdEnum_Timezone.GMTMINUS0500EASTERNTIME; | |
dateTimeValidTo.Value = dateTimeValidFrom.localDateTime; | |
request.LedgerExchangeRate = new AxdLedgerExchangeRate(); | |
request.LedgerExchangeRate.CurrencyPair = pair; | |
request.LedgerExchangeRate.ValidFromDateTime = dateTimeValidFrom; | |
request.LedgerExchangeRate.ValidToDateTime = dateTimeValidTo; | |
client.Open(); | |
client.create(request.CallContext, request.LedgerExchangeRate); | |
client.Close(); | |
Console.Write("Operation succeeded!"); | |
} | |
catch (Exception exception) | |
{ | |
Console.Write(exception.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment