Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I'm handling an E-commerce based site for this i need to use currency converter. For this please dont suggest normal webservice, I have gone through it. My site is a travel guide helping tourists, for that i'm showing images of homestay,hotel and all with per night rate, its in USD. As user click it needed to convert in there needed currency. For example user click INR then priceList should display in INR.

thanks......
Posted
Comments
Sergey Alexandrovich Kryukov 17-Aug-12 22:48pm    
What is "normal Web service", why "don't suggest it"? What do you need for a source of exchange rates? This is not even a question...
--SA
Aurora9229 18-Aug-12 0:13am    
coz i got the webservices such as http://fx-rate.net ( http://fx-rate.net/converter.php?) and it was not as i need. My need is specified well in my query.ie price list in mysite should be in default USD and by users click as there neede currency.
Aurora9229 18-Aug-12 0:14am    
what ever webservice i have search out for currency converter was similar to refered above.
Sergey Alexandrovich Kryukov 18-Aug-12 0:33am    
What's the logic! You faces some, let's trust you, inadequate services and made a conclusion that Web services is not good for you. Your specified need is gibberish. Don't you think a Web service is something which would present the data in exact form you keep in mind?
--SA
Aurora9229 18-Aug-12 1:42am    
ok then can you guide me to get complete my work using webservice. My application is similar to airbnb.

Google's[^] seems like it would work - you'll have to parse the output




Quote:
You can change value of input currency, for example you want to know the value for $100 in India Rupees
http://www.google.com/ig/calculator?hl=en&q=100USD=?INR[^]
 
Share this answer
 
v2
Comments
Aurora9229 18-Aug-12 1:59am    
pardon i need to check it in server side itself. Ie While the user select currecy from the dropdownlist, the result should appearin dropdownlist selected index changed
Sergey Alexandrovich Kryukov 18-Aug-12 2:01am    
Why do you always mix the service which works purely with data with presentation/control using the UI? The approach is different: informational part is on the service, UI is on you. You need loose coupling of them.
--SA
Sergey Alexandrovich Kryukov 18-Aug-12 1:59am    
Seems to be a workable solution, my 5.
--SA
It's good that you agree that the way to go is to use appropriate Web services. Please read about consuming the Web services (consuming is all you need) here:
http://msdn.microsoft.com/en-us/library/ms972326.aspx[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 18-Aug-12 12:40pm    
5'ed!
Sergey Alexandrovich Kryukov 18-Aug-12 12:44pm    
Thank you, Espen.
--SA
Created a web service its code:

C++
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;


this was called to my web page.keeping USD as default and to currency selecting from a dropdownlist. And the result displayed in a label, its c# code is

C++
localhost.WebService ws = new localhost.WebService();
        decimal amount = Convert.ToDecimal(LabelFromCurrency .Text );
        string fm = "USD";
        string tt = DropDownList1.SelectedValue.ToString();
        decimal result;
        result = amount * ws.Convert(1, fm, tt);
        LabelToCurrency.Text = "Result is: " + result.ToString();
 
Share this answer
 
Comments
ythisbug 22-Aug-12 3:06am    
see my solution
hi Arora
this will help you

create two text box ,a lable and one button
XML
<asp:Label ID="Label1" runat="server" Text=""></asp:Label><br /><br />
               <tr>
               <td>
                           Enter Purchase Currency Code:
               </td>
               <td>
               <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

               </td>
               </tr>
               <tr>
               <td>
                Enter Reciever Currency Code
               </td>
               <td>
                <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
               </td>
               </tr>


       </table>



use this name space
C#
using System.IO;
using System.Net;
using System.Xml;



in search button click add this code

protected void btnSearch_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            string xmlResult = null;
            string url;
            url = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=" + TextBox1.Text + "&ToCurrency=" + TextBox2.Text + "";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            StreamReader resStream = new StreamReader(response.GetResponseStream());
            XmlDocument doc = new XmlDocument();
            xmlResult = resStream.ReadToEnd();
            doc.LoadXml(xmlResult);
            Label1.Text = "Current Exchange Rate for " + TextBox1.Text.ToUpper() + " ---> " + TextBox2.Text.ToUpper() + " value " + doc.GetElementsByTagName("double").Item(0).InnerText;
        }
        catch (Exception ex)
        {
            Label1.Text = "Not a valid Currency or Try again later";
        }

    }


this will help u..this is online.so u need internet connection..


If this helpful accept solution.

keep coding..
 
Share this answer
 
Simple Example

HTML
<![CDATA[<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CurrencyNew.aspx.cs" Inherits="CurrencyNew" %>]]>
 
Share this answer
 
XML
Simple Example

<pre lang="HTML">
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CurrencyNew.aspx.cs" Inherits="CurrencyNew" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

&lt;html xmlns="http://www.w3.org/1999/xhtml">
&lt;head runat="server">
    &lt;title>&lt;/title>
&lt;/head>
&lt;body>
    &lt;form id="form1" runat="server">
    <div>

        <br />
        Currency Conveter<br />
        <br />
        FromAmont<br />
&nbsp;&nbsp;&nbsp;
        <br />
&nbsp;&nbsp;&nbsp;
        <asp:Label ID="LabelFromCurrency" runat="server"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
            onselectedindexchanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Value="AED">United Arab Emirates Dirham (AED)</asp:ListItem>
            <asp:ListItem Value="ANG">Netherlands Antillean Guilder (ANG)</asp:ListItem>
            <asp:ListItem Value="ARS">Argentine Peso (ARS)</asp:ListItem >
            <asp:ListItem Value="AUD">Australian Dollar (AUD)</asp:ListItem >
            <asp:ListItem  Value="BDT">Bangladeshi Taka (BDT)</asp:ListItem >
            <asp:ListItem  Value="BGN">Bulgarian Lev (BGN)</asp:ListItem >
            <asp:ListItem  Value="BHD">Bahraini Dinar (BHD)</asp:ListItem >
            <asp:ListItem  Value="BND">Brunei Dollar (BND)</asp:ListItem >
            <asp:ListItem  Value="BOB">Bolivian Boliviano (BOB)</asp:ListItem >
            <asp:ListItem  Value="BRL">Brazilian Real (BRL)</asp:ListItem >
            <asp:ListItem  Value="BWP">Botswanan Pula (BWP)</asp:ListItem >
            <asp:ListItem  Value="CAD">Canadian Dollar (CAD)</asp:ListItem >
            <asp:ListItem  Value="CHF">Swiss Franc (CHF)</asp:ListItem >
            <asp:ListItem  Value="CLP">Chilean Peso (CLP)</asp:ListItem >
            <asp:ListItem  Value="CNY">Chinese Yuan (CNY)</asp:ListItem >
            <asp:ListItem  Value="COP">Colombian Peso (COP)</asp:ListItem >
            <asp:ListItem  Value="CRC">Costa Rican Colón (CRC)</asp:ListItem >
            <asp:ListItem  Value="CZK">Czech Republic Koruna (CZK)</asp:ListItem >
            <asp:ListItem  Value="DKK">Danish Krone (DKK)</asp:ListItem >
            <asp:ListItem  Value="DOP">Dominican Peso (DOP)</asp:ListItem >
            <asp:ListItem  Value="DZD">Algerian Dinar (DZD)</asp:ListItem >
            <asp:ListItem  Value="EEK">Estonian Kroon (EEK)</asp:ListItem >
            <asp:ListItem  Value="EGP">Egyptian Pound (EGP)</asp:ListItem >
            <asp:ListItem  Value="EUR">Euro (EUR)</asp:ListItem >
            <asp:ListItem  Value="FJD">Fijian Dollar (FJD)</asp:ListItem >
            <asp:ListItem  Value="GBP">British Pound Sterling (GBP)</asp:ListItem >
            <asp:ListItem  Value="HKD">Hong Kong Dollar (HKD)</asp:ListItem >
            <asp:ListItem  Value="HNL">Honduran Lempira (HNL)</asp:ListItem >
            <asp:ListItem  Value="HRK">Croatian Kuna (HRK)</asp:ListItem >
            <asp:ListItem  Value="HUF">Hungarian Forint (HUF)</asp:ListItem >
            <asp:ListItem  Value="IDR">Indonesian Rupiah (IDR)</asp:ListItem >
            <asp:ListItem  Value="ILS">Israeli New Sheqel (ILS)</asp:ListItem >
            <asp:ListItem  Value="INR">Indian Rupee (INR)</asp:ListItem >
            <asp:ListItem  Value="JMD">Jamaican Dollar (JMD)</asp:ListItem >
            <asp:ListItem  Value="JOD">Jordanian Dinar (JOD)</asp:ListItem >
            <asp:ListItem  Value="JPY">Japanese Yen (JPY)</asp:ListItem >
            <asp:ListItem  Value="KES">Kenyan Shilling (KES)</asp:ListItem >
            <asp:ListItem  Value="KRW">South Korean Won (KRW)</asp:ListItem >
            <asp:ListItem  Value="KWD">Kuwaiti Dinar (KWD)</asp:ListItem >
            <asp:ListItem  Value="KYD">Cayman Islands Dollar (KYD)</asp:ListItem >
            <asp:ListItem  Value="KZT">Kazakhstani Tenge (KZT)</asp:ListItem >
            <asp:ListItem  Value="LBP">Lebanese Pound (LBP)</asp:ListItem >
            <asp:ListItem  Value="LKR">Sri Lankan Rupee (LKR)</asp:ListItem >
            <asp:ListItem  Value="LTL">Lithuanian Litas (LTL)</asp:ListItem >
            <asp:ListItem  Value="LVL">Latvian Lats (LVL)</asp:ListItem >
            <asp:ListItem  Value="MAD">Moroccan Dirham (MAD)</asp:ListItem >
            <asp:ListItem  Value="MDL">Moldovan Leu (MDL)</asp:ListItem >
            <asp:ListItem  Value="MKD">Macedonian Denar (MKD)</asp:ListItem >
            <asp:ListItem  Value="MUR">Mauritian Rupee (MUR)</asp:ListItem >
            <asp:ListItem  Value="MVR">Maldivian Rufiyaa (MVR)</asp:ListItem >
            <asp:ListItem  Value="MXN">Mexican Peso (MXN)</asp:ListItem >
            <asp:ListItem  Value="MYR">Malaysian Ringgit (MYR)</asp:ListItem >
            <asp:ListItem  Value="NAD">Namibian Dollar (NAD)</asp:ListItem >
            <asp:ListItem  Value="NGN">Nigerian Naira (NGN)</asp:ListItem >
            <asp:ListItem  Value="NIO">Nicaraguan Córdoba (NIO)</asp:ListItem >
            <asp:ListItem  Value="NOK">Norwegian Krone (NOK)</asp:ListItem >
            <asp:ListItem  Value="NPR">Nepalese Rupee (NPR)</asp:ListItem >
            <asp:ListItem  Value="NZD">New Zealand Dollar (NZD)</asp:ListItem >
            <asp:ListItem  Value="OMR">Omani Rial (OMR)</asp:ListItem >
            <asp:ListItem  Value="PEN">Peruvian Nuevo Sol (PEN)</asp:ListItem >
            <asp:ListItem  Value="PGK">Papua New Guinean Kina (PGK)</asp:ListItem >
            <asp:ListItem  Value="PHP">Philippine Peso (PHP)</asp:ListItem >
            <asp:ListItem  Value="PKR">Pakistani Rupee (PKR)</asp:ListItem >
            <asp:ListItem  Value="PLN">Polish Zloty (PLN)</asp:ListItem >
            <asp:ListItem  Value="PYG">Paraguayan Guarani (PYG)</asp:ListItem >
            <asp:ListItem  Value="QAR">Qatari Rial (QAR)</asp:ListItem >
            <asp:ListItem  Value="RON">Romanian Leu (RON)</asp:ListItem >
            <asp:ListItem  Value="RSD">Serbian Dinar (RSD)</asp:ListItem >
            <asp:ListItem  Value="RUB">Russian Ruble (RUB)</asp:ListItem >
            <asp:ListItem  Value="SAR">Saudi Riyal (SAR)</asp:ListItem >
            <asp:ListItem  Value="SCR">Seychellois Rupee (SCR)</asp:ListItem >
            <asp:ListItem  Value="SEK">Swedish Krona (SEK)</asp:ListItem >
            <asp:ListItem  Value="SGD">Singapore Dollar (SGD)</asp:ListItem >
            <asp:ListItem  Value="SKK">Slovak Koruna (SKK)</asp:ListItem >
            <asp:ListItem  Value="SLL">Sierra Leonean Leone (SLL)</asp:ListItem >
            <asp:ListItem  Value="SVC">Salvadoran Colón (SVC)</asp:ListItem >
            <asp:ListItem  Value="THB">Thai Baht (THB)</asp:ListItem >
            <asp:ListItem  Value="TND">Tunisian Dinar (TND)</asp:ListItem >
            <asp:ListItem  Value="TRY">Turkish Lira (TRY)</asp:ListItem >
            <asp:ListItem  Value="TTD">Trinidad and Tobago Dollar (TTD)</asp:ListItem >
            <asp:ListItem  Value="TWD">New Taiwan Dollar (TWD)</asp:ListItem >
            <asp:ListItem  Value="TZS">Tanzanian Shilling (TZS)</asp:ListItem >
            <asp:ListItem  Value="UAH">Ukrainian Hryvnia (UAH)</asp:ListItem >
            <asp:ListItem  Value="UGX">Ugandan Shilling (UGX)</asp:ListItem >
            <asp:ListItem  Value="USD">US Dollar (USD)</asp:ListItem >
            <asp:ListItem  Value="UYU">Uruguayan Peso (UYU)</asp:ListItem >
            <asp:ListItem  Value="UZS">Uzbekistan Som (UZS)</asp:ListItem >
            <asp:ListItem  Value="VEF">Venezuelan Bolívar (VEF)</asp:ListItem >
            <asp:ListItem  Value="VND">Vietnamese Dong (VND)</asp:ListItem >
            <asp:ListItem  Value="XOF">CFA Franc BCEAO (XOF)</asp:ListItem >
            <asp:ListItem  Value="YER">Yemeni Rial (YER)</asp:ListItem >
            <asp:ListItem  Value="ZAR">South African Rand (ZAR)</asp:ListItem >
            <asp:ListItem  Value="ZMK">Zambian Kwacha (ZMK)</asp:ListItem >
        </asp:DropDownList>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="LabelToCurrency" runat="server"></asp:Label>
        <br />
        <br />
&nbsp;&nbsp;&nbsp;
        <br />
        <br />
        <br />

    </div>
    &lt;/form>
&lt;/body>
&lt;/html>
</pre>


<pre lang="c++">
       protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

        localhost.WebService ws = new localhost.WebService();
        decimal amount = Convert.ToDecimal(LabelFromCurrency .Text );
        string fm = "USD";
        string tt = DropDownList1.SelectedValue.ToString();
        decimal result;
        result = amount * ws.Convert(1, fm, tt);
        LabelToCurrency.Text = "Result is: " + result.ToString();
}&gt;&gt;&gt;
</pre>



And Webservice is...

C++
[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;

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900