Create new web site in Visual Studio. In Default.aspx page we need to jQuery library (you can download it from jquery.com), so add:
<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
Add to page body the following html code:
<div style="overflow:hidden; padding:10px; width:700px; margin:10px; background:#EAEAFF; border:solid 1px #ccc;">
<div style="padding: 2px; margin: 2px; float: left;">
Amount:
<input id="a" maxlength="12" size="5" value="1" />
</div>
<div style="padding: 2px; margin: 2px; float: left;">
From:
<select id="from">
<option value="AED">United Arab Emirates Dirham (AED)</option>
<option value="ANG">Netherlands Antillean Guilder (ANG)</option>
<option value="ARS">Argentine Peso (ARS)</option>
<option value="AUD">Australian Dollar (AUD)</option>
<option value="BDT">Bangladeshi Taka (BDT)</option>
<option value="BGN">Bulgarian Lev (BGN)</option>
<option value="BHD">Bahraini Dinar (BHD)</option>
<option value="BND">Brunei Dollar (BND)</option>
<option value="BOB">Bolivian Boliviano (BOB)</option>
<option value="BRL">Brazilian Real (BRL)</option>
<option value="BWP">Botswanan Pula (BWP)</option>
<option value="CAD">Canadian Dollar (CAD)</option>
<option value="CHF">Swiss Franc (CHF)</option>
<option value="CLP">Chilean Peso (CLP)</option>
<option value="CNY">Chinese Yuan (CNY)</option>
<option value="COP">Colombian Peso (COP)</option>
<option value="CRC">Costa Rican Colón (CRC)</option>
<option value="CZK">Czech Republic Koruna (CZK)</option>
<option value="DKK">Danish Krone (DKK)</option>
<option value="DOP">Dominican Peso (DOP)</option>
<option value="DZD">Algerian Dinar (DZD)</option>
<option value="EEK">Estonian Kroon (EEK)</option>
<option value="EGP">Egyptian Pound (EGP)</option>
<option value="EUR">Euro (EUR)</option>
<option value="FJD">Fijian Dollar (FJD)</option>
<option value="GBP">British Pound Sterling (GBP)</option>
<option value="HKD">Hong Kong Dollar (HKD)</option>
<option value="HNL">Honduran Lempira (HNL)</option>
<option value="HRK">Croatian Kuna (HRK)</option>
<option value="HUF">Hungarian Forint (HUF)</option>
<option value="IDR">Indonesian Rupiah (IDR)</option>
<option value="ILS">Israeli New Sheqel (ILS)</option>
<option value="INR">Indian Rupee (INR)</option>
<option value="JMD">Jamaican Dollar (JMD)</option>
<option value="JOD">Jordanian Dinar (JOD)</option>
<option value="JPY">Japanese Yen (JPY)</option>
<option value="KES">Kenyan Shilling (KES)</option>
<option value="KRW">South Korean Won (KRW)</option>
<option value="KWD">Kuwaiti Dinar (KWD)</option>
<option value="KYD">Cayman Islands Dollar (KYD)</option>
<option value="KZT">Kazakhstani Tenge (KZT)</option>
<option value="LBP">Lebanese Pound (LBP)</option>
<option value="LKR">Sri Lankan Rupee (LKR)</option>
<option value="LTL">Lithuanian Litas (LTL)</option>
<option value="LVL">Latvian Lats (LVL)</option>
<option value="MAD">Moroccan Dirham (MAD)</option>
<option value="MDL">Moldovan Leu (MDL)</option>
<option value="MKD">Macedonian Denar (MKD)</option>
<option value="MUR">Mauritian Rupee (MUR)</option>
<option value="MVR">Maldivian Rufiyaa (MVR)</option>
<option value="MXN">Mexican Peso (MXN)</option>
<option value="MYR">Malaysian Ringgit (MYR)</option>
<option value="NAD">Namibian Dollar (NAD)</option>
<option value="NGN">Nigerian Naira (NGN)</option>
<option value="NIO">Nicaraguan Córdoba (NIO)</option>
<option value="NOK">Norwegian Krone (NOK)</option>
<option value="NPR">Nepalese Rupee (NPR)</option>
<option value="NZD">New Zealand Dollar (NZD)</option>
<option value="OMR">Omani Rial (OMR)</option>
<option value="PEN">Peruvian Nuevo Sol (PEN)</option>
<option value="PGK">Papua New Guinean Kina (PGK)</option>
<option value="PHP">Philippine Peso (PHP)</option>
<option value="PKR">Pakistani Rupee (PKR)</option>
<option value="PLN">Polish Zloty (PLN)</option>
<option value="PYG">Paraguayan Guarani (PYG)</option>
<option value="QAR">Qatari Rial (QAR)</option>
<option value="RON">Romanian Leu (RON)</option>
<option value="RSD">Serbian Dinar (RSD)</option>
<option value="RUB">Russian Ruble (RUB)</option>
<option value="SAR">Saudi Riyal (SAR)</option>
<option value="SCR">Seychellois Rupee (SCR)</option>
<option value="SEK">Swedish Krona (SEK)</option>
<option value="SGD">Singapore Dollar (SGD)</option>
<option value="SKK">Slovak Koruna (SKK)</option>
<option value="SLL">Sierra Leonean Leone (SLL)</option>
<option value="SVC">Salvadoran Colón (SVC)</option>
<option value="THB">Thai Baht (THB)</option>
<option value="TND">Tunisian Dinar (TND)</option>
<option value="TRY">Turkish Lira (TRY)</option>
<option value="TTD">Trinidad and Tobago Dollar (TTD)</option>
<option value="TWD">New Taiwan Dollar (TWD)</option>
<option value="TZS">Tanzanian Shilling (TZS)</option>
<option value="UAH">Ukrainian Hryvnia (UAH)</option>
<option value="UGX">Ugandan Shilling (UGX)</option>
<option value="USD">US Dollar (USD)</option>
<option value="UYU">Uruguayan Peso (UYU)</option>
<option value="UZS">Uzbekistan Som (UZS)</option>
<option value="VEF">Venezuelan Bolívar (VEF)</option>
<option value="VND">Vietnamese Dong (VND)</option>
<option value="XOF">CFA Franc BCEAO (XOF)</option>
<option value="YER">Yemeni Rial (YER)</option>
<option value="ZAR">South African Rand (ZAR)</option>
<option value="ZMK">Zambian Kwacha (ZMK)</option>
</select>
</div>
<div style="padding: 2px; margin: 2px;">
to:
<select id="to">
<option value="AED">United Arab Emirates Dirham (AED)</option>
<option value="ANG">Netherlands Antillean Guilder (ANG)</option>
<option value="ARS">Argentine Peso (ARS)</option>
<option value="AUD">Australian Dollar (AUD)</option>
<option value="BDT">Bangladeshi Taka (BDT)</option>
<option value="BGN">Bulgarian Lev (BGN)</option>
<option value="BHD">Bahraini Dinar (BHD)</option>
<option value="BND">Brunei Dollar (BND)</option>
<option value="BOB">Bolivian Boliviano (BOB)</option>
<option value="BRL">Brazilian Real (BRL)</option>
<option value="BWP">Botswanan Pula (BWP)</option>
<option value="CAD">Canadian Dollar (CAD)</option>
<option value="CHF">Swiss Franc (CHF)</option>
<option value="CLP">Chilean Peso (CLP)</option>
<option value="CNY">Chinese Yuan (CNY)</option>
<option value="COP">Colombian Peso (COP)</option>
<option value="CRC">Costa Rican Colón (CRC)</option>
<option value="CZK">Czech Republic Koruna (CZK)</option>
<option value="DKK">Danish Krone (DKK)</option>
<option value="DOP">Dominican Peso (DOP)</option>
<option value="DZD">Algerian Dinar (DZD)</option>
<option value="EEK">Estonian Kroon (EEK)</option>
<option value="EGP">Egyptian Pound (EGP)</option>
<option value="EUR">Euro (EUR)</option>
<option value="FJD">Fijian Dollar (FJD)</option>
<option value="GBP">British Pound Sterling (GBP)</option>
<option value="HKD">Hong Kong Dollar (HKD)</option>
<option value="HNL">Honduran Lempira (HNL)</option>
<option value="HRK">Croatian Kuna (HRK)</option>
<option value="HUF">Hungarian Forint (HUF)</option>
<option value="IDR">Indonesian Rupiah (IDR)</option>
<option value="ILS">Israeli New Sheqel (ILS)</option>
<option value="INR">Indian Rupee (INR)</option>
<option value="JMD">Jamaican Dollar (JMD)</option>
<option value="JOD">Jordanian Dinar (JOD)</option>
<option value="JPY">Japanese Yen (JPY)</option>
<option value="KES">Kenyan Shilling (KES)</option>
<option value="KRW">South Korean Won (KRW)</option>
<option value="KWD">Kuwaiti Dinar (KWD)</option>
<option value="KYD">Cayman Islands Dollar (KYD)</option>
<option value="KZT">Kazakhstani Tenge (KZT)</option>
<option value="LBP">Lebanese Pound (LBP)</option>
<option value="LKR">Sri Lankan Rupee (LKR)</option>
<option value="LTL">Lithuanian Litas (LTL)</option>
<option value="LVL">Latvian Lats (LVL)</option>
<option value="MAD">Moroccan Dirham (MAD)</option>
<option value="MDL">Moldovan Leu (MDL)</option>
<option value="MKD">Macedonian Denar (MKD)</option>
<option value="MUR">Mauritian Rupee (MUR)</option>
<option value="MVR">Maldivian Rufiyaa (MVR)</option>
<option value="MXN">Mexican Peso (MXN)</option>
<option value="MYR">Malaysian Ringgit (MYR)</option>
<option value="NAD">Namibian Dollar (NAD)</option>
<option value="NGN">Nigerian Naira (NGN)</option>
<option value="NIO">Nicaraguan Córdoba (NIO)</option>
<option value="NOK">Norwegian Krone (NOK)</option>
<option value="NPR">Nepalese Rupee (NPR)</option>
<option value="NZD">New Zealand Dollar (NZD)</option>
<option value="OMR">Omani Rial (OMR)</option>
<option value="PEN">Peruvian Nuevo Sol (PEN)</option>
<option value="PGK">Papua New Guinean Kina (PGK)</option>
<option value="PHP">Philippine Peso (PHP)</option>
<option value="PKR">Pakistani Rupee (PKR)</option>
<option value="PLN">Polish Zloty (PLN)</option>
<option value="PYG">Paraguayan Guarani (PYG)</option>
<option value="QAR">Qatari Rial (QAR)</option>
<option value="RON">Romanian Leu (RON)</option>
<option value="RSD">Serbian Dinar (RSD)</option>
<option value="RUB">Russian Ruble (RUB)</option>
<option value="SAR">Saudi Riyal (SAR)</option>
<option value="SCR">Seychellois Rupee (SCR)</option>
<option value="SEK">Swedish Krona (SEK)</option>
<option value="SGD">Singapore Dollar (SGD)</option>
<option value="SKK">Slovak Koruna (SKK)</option>
<option value="SLL">Sierra Leonean Leone (SLL)</option>
<option value="SVC">Salvadoran Colón (SVC)</option>
<option value="THB">Thai Baht (THB)</option>
<option value="TND">Tunisian Dinar (TND)</option>
<option value="TRY">Turkish Lira (TRY)</option>
<option value="TTD">Trinidad and Tobago Dollar (TTD)</option>
<option value="TWD">New Taiwan Dollar (TWD)</option>
<option value="TZS">Tanzanian Shilling (TZS)</option>
<option value="UAH">Ukrainian Hryvnia (UAH)</option>
<option value="UGX">Ugandan Shilling (UGX)</option>
<option value="USD">US Dollar (USD)</option>
<option value="UYU">Uruguayan Peso (UYU)</option>
<option value="UZS">Uzbekistan Som (UZS)</option>
<option value="VEF">Venezuelan Bolívar (VEF)</option>
<option value="VND">Vietnamese Dong (VND)</option>
<option value="XOF">CFA Franc BCEAO (XOF)</option>
<option value="YER">Yemeni Rial (YER)</option>
<option value="ZAR">South African Rand (ZAR)</option>
<option value="ZMK">Zambian Kwacha (ZMK)</option>
</select>
</div>
<br />
<div style="padding: 2px; margin: 2px; float: left;">
<input id="submit" type="button" value="Convert" />
</div>
<div id="results" style="padding: 2px; margin: 5px;">
</div>
</div>
Now, we have input field to type amount and two drop downs with currencies and button to call web service function which calculate the differences of currencies and fill result in div with name “results”.
Now add jQuery code to handle button event to call web service and filling result data vie AJAX:
Add Reference into WebService.cs file:
using System.Web.Script.Services;
[ScriptService]
Then, the last thing to do is create web service and declare function which take three parameter (Amount, From Currency, To Currency) and return the decimal.
using System.Web.Script.Services;
[ScriptService]
Then, the last thing to do is create web service and declare function which take three parameter (Amount, From Currency, To Currency) and return the decimal.
[WebMethod]
public decimal Convert(decimal amount, string fromCurrency, string toCurrency)
{
WebClient web = new WebClient();
string url = string.Format("http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);
string response = web.DownloadString(url);
Regex regex = new Regex("rhs: \\\"(\\d*.\\d*)");
decimal rate = System.Convert.ToDecimal(regex.Match(response).Groups[1].Value);
return rate;
}
Complete WebService.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;
using System.Text.RegularExpressions;
using System.Web.Script.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace
= "http://tempuri.org/")]
[WebServiceBinding(ConformsTo
= WsiProfiles.BasicProfile1_1)]
[ScriptService]
// To allow this Web Service to be
called from script, using ASP.NET AJAX, uncomment the following line.
//
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string
HelloWorld() {
return "Hello
World";
}
[WebMethod]
public decimal
Convert(decimal amount, string fromCurrency, string
toCurrency)
{
WebClient web = new
WebClient();
string url = string.Format("http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}",
fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);
string response = web.DownloadString(url);
Regex regex = new Regex("rhs:
\\\"(\\d*.\\d*)");
decimal rate = System.Convert.ToDecimal(regex.Match(response).Groups[1].Value);
return rate;
}
}
Note:
The getJSON() method is used to get JSON data using an AJAX HTTP GET request.
$(selector).getJSON(url,data,success(data,status,xhr))
url
|
Required. Specifies the url to send
the request to
|
data
|
Optional. Specifies data to be sent
to the server
|
success(data,status,xhr)
|
Optional. Specifies the function to
run if the request succeeds
Additional parameters:
|
Good news is here - Google have a secrete API for Currency Conversion. Its a simple open API you can use for all type of foreign currencies.
How to use it?
If you want currency converter £ to dollars, use it like this -
If you want to calculate currency converter $ to £ -
You can change value of input currency, for example you want to know the value for $100 in India Rupees
Two links:
- https://www.google.com/finance/converter?a=2&from=gbp&to=usd
- http://www.google.com/ig/calculator?hl=en&q=1GBP=?USD
Troubleshoot:
- I did not use the using.system.web.script.services; and [Services] reference and it did not work. After adding the reference it has worked properly.
Great explain about currency conversion in asp.net. This is more helpful for me.
ReplyDeleteVcoruMne_da-1996 Jared Ellenberg https://wakelet.com/wake/GjQynh1gxIc8avN1EiA36
ReplyDeletecoabestlugoo
trudlisdispko Troy Schorfheide https://www.troykickboxingoutfit.com/profile/Herbie-Fully-Loaded-Tamil-Dubbed-Movie-Free-BETTER-Download/profile
ReplyDeletetebanbankca
quimesplac_be Byron Mancuso Microsoft Visio Professional
ReplyDeleteSite
Firefox browser
dragerroca
Mbellaconsgu Sam Taylor Click here
ReplyDeletesoftware
moordmodasam