Background
In one of my projects there is one module that requires a currency converter application. I am applying various techniques to convert the currency, such as storing the country name and related currency values in a database and retrieve them according to the related country but that is a very lengthy and complicated process.
Then after trying many options I decided to use a third party API to complete my requirement; I chose the Google API. So my intent is to write this article to help others that might me need to do the same type of task.
So let us start with the walkthrough.
Create the project as in:
- "Start" - "All Programs" - "Microsoft Visual Studio 2010".
- "File" - "New Project" - "C#" - "Empty Project" (to avoid adding a master page).
- Give the Project name (such as LiveCurrencyconverter) or another as you wish and specify the location.
- Then right-click on Solution Explorer - "Add New Item" - "Default.aspx" page.
- Then right-click on Solution Explorer - "Add New Item" - "WebService.asmx" page.
- To see the "Default.aspx" source code please download the sample zip file.
Use the following code in WebService.asmx.cs of the WebService.asmx page:
In the preceding web services I have used one string named URL; on it I have saved a path of the Google API. Now add the service reference of the WebService.asmx web service to the Default.aspx page by right-clicking on the Solution Explorer, now run the application which looks such as in the following:
The above is the sample screen of an application, now provide the Input i9n above fields and click on "Convert" Button; the output will be as follows:
In the preceding Screen we can clearly seen that, I have converted 1 USD into Indian Rupees and the output is exactly the current market price, which is 54.58Rs.
Advantages
- Convert any country's currency using the current live market value.
- You have no need of a database to store the data.
- The free of cost API is provided by Google; there is not even a hidden cost.
Note
- For more code please download the sample zip file.
- Before using this article please read about the basics of Web Services, if you are unfamiliar with it.
Summary
I hope this article is useful for all readers, if you have any suggestion then please contact me, because of your suggestion others can get help from this article by improving it.