public double?GetExchangerate(double amountInSek, string currency, DateTime date) { var client = new SweaWebServicePortTypeClient(); var rate = client.getMonthlyAverageExchangeRates(date.Year, date.Month, LanguageType.en); var exchangeRate = rate.groups.First().series.Where(v => v.seriesname == currency).First().resultrows.First().average; var amountInCurrency = amountInSek / exchangeRate; return(amountInCurrency); }
public List <CurrencyInfo> GetCurrentCurrencyExchangeRate()//ICurrency FromCurrency, ICurrency ToCurrency) { string[] series = new string[] { SEKTOEURSERIE, SEKTOUSDSERIE }; List <CurrencyInfo> oCurrencyInfo = new List <CurrencyInfo>(); try { string s_RemoteAddress = "https://swea.riksbank.se:443/sweaWS/services/SweaWebServiceHttpSoap12Endpoint"; Uri oRemoteUri; try { oRemoteUri = new Uri(s_RemoteAddress); } catch (System.Exception ex) { throw new System.Exception(string.Format("Remoteaddress is not correct formatted {0} ({1})", s_RemoteAddress, ex.Message)); } BasicHttpSecurityMode oSecuritymode = oRemoteUri.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase) ? BasicHttpSecurityMode.Transport : BasicHttpSecurityMode.None; BasicHttpBinding oBinding = new BasicHttpBinding(oSecuritymode); oBinding.MaxReceivedMessageSize = int.MaxValue; oBinding.MaxBufferSize = int.MaxValue; SweaWebServicePortTypeClient oClient = new SweaWebServicePortTypeClient(oBinding, new EndpointAddress(s_RemoteAddress)); //SweaWebServicePortTypeClient oClient = new SweaWebServicePortTypeClient(System.ServiceModel.BasicHttpsBinding , "https://swea.riksbank.se:443/sweaWS/services/SweaWebServiceHttpSoap12Endpoint"); Result oResult = oClient.getLatestInterestAndExchangeRates(LanguageType.en, series ); foreach (var ResultGroup in oResult.groups) { foreach (var ResultSerie in ResultGroup.series) { oCurrencyInfo.AddRange(ResultSerie.resultrows.Select(s => new CurrencyInfo { Currency = ResultSerie.seriesid.Trim().Equals(SEKTOUSDSERIE) ? ImperaturGlobal.GetMoney(0, "USD").CurrencyCode : ImperaturGlobal.GetMoney(0, "EUR").CurrencyCode, Date = s.date.Value, Price = Convert.ToDecimal(s.value) } ).ToArray()); } } } catch (System.Exception ex) { int gg = 0; } return(oCurrencyInfo); }
private static void SweaService() { SweaWebServicePortTypeClient swea = new SweaWebServicePortTypeClient("SweaWebServiceHttpSoap12Endpoint"); var result = swea.getAllCrossNames(LanguageType.sv); foreach (var item in result) { Console.WriteLine($"ID: {item.seriesid} - Name: {item.seriesname} - Description: {item.seriesdescription}"); } Console.ReadLine(); }
private async Task <getCrossRatesResponse> CallSweaForCrossRate(string fromCurrency, string toCurrency, DateTime conversionDate) { var sweaWsClient = new SweaWebServicePortTypeClient(); var parameters = CrossRateConversionRequestHelper.GetParameters(fromCurrency, toCurrency, conversionDate); using (var scope = new FlowingOperationContextScope(sweaWsClient.InnerChannel)) { var request = new HttpRequestMessageProperty(); request.Headers.Add("Accept-Encoding", "gzip,deflate"); // this is crucial, without action="urn:[methodName]" the call to Swea WS will result in 404 error. request.Headers.Add("Content-Type", @"application/soap+xml;charset=UTF-8;action=""urn:getCrossRates"""); OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = request; return(await sweaWsClient.getCrossRatesAsync(parameters).ContinueOnScope(scope)); } }
public CurrencyService() { soapClient = new SweaWebServicePortTypeClient(); }