0

我正在建立一个网站,我需要在其中显示某些商品的价格。价格需要每天根据汇率更新。我该如何在 asp.net 中执行此操作?

4

1 回答 1

0

If question is about how to get currency rates in ASP.NET, than you can use something like this:

    private static string GetCurrencyRate(string fromCurrency, string toCurrency)
    {
        WebRequest webrequest = WebRequest.Create(string.Format("http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency={0}&ToCurrency={1}", fromCurrency, toCurrency));
        using (WebResponse response = webrequest.GetResponse())
        {
            using (Stream dataStream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(dataStream))
                {
                    string responseFromServer = reader.ReadToEnd();
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(responseFromServer);
                    return doc.InnerText;                     
                }
            }
        }
    }

Using:

Console.WriteLine(GetCurrencyRate("GBP", "USD"));

If thereis a problem with displaying this data in web page, than you can tell us more precise about your site, because thereis a few different methods.

于 2013-02-21T06:05:21.653 回答