This article guides you in developing a practical “Number to Words” web service using the latest Microsoft Visual Studio 2005 as the development tool.
There are two downloadable files available for this article. You can find them here and here.
The sample downloadable solution (Number2Words2K5) is entirely developed using Visual Studio.NET 2005 Professional Edition on Windows Server 2003 Standard Edition. I also added another downloadable solution (Number2Words) which is especially for the developers who are currently using Visual Studio.NET 2003 Enterprise Architect.
Is it the “Web Services” era now?
Before going a bit deep into that question, we need to understand what a "web service" really is. An XML Web service is a component that implements program logic and provides functionality for disparate applications. These applications use standard protocols, such as HTTP, XML, and SOAP, to access the functionality.
XML Web services (or ASP.NET Web Services) use XML-based messaging to send and receive data, which enables heterogeneous applications (applications deployed on several platforms) to interoperate with each other. You can use XML Web services to integrate applications that are written in different programming languages and deployed on different platforms. In addition, you can deploy XML Web services within an intranet as well as on the Internet.
One of the important features of the XML Web services based computing model is that both clients and XML Web services are unaware of the implementation details of each other. While the Internet brings users closer to organizations, XML Web services allow organizations to integrate their applications!
Now I think you can already find the answer to my question. Is it the “Web Services” era now? Several organizations have already begun implementing web services to integrate their applications easily. Not only did they start integrating their applications, they also started implementing their “services” to/for the “web” (or Internet) as well (ex: Google, Amazon etc). This evolution started with the simple phrase “Web Service” and expanded to the world of “Service Oriented Architecture” (also called SOA). You can achieve a better understanding of SOA at http://www.devshed.com/c/a/Web-Services/Introduction-to-Service-Oriented-Architecture-SOA/
The rest of the sections in this article will help you to develop your own web service using the latest tool, “Microsoft Visual Studio।NET 2005.”
The XML web service, which we are going to develop now, simply accepts a number (of type “long”) and converts it to words. Putting it into plain language, if we send “345,” the XML web-service returns the result as “Three hundred forty five.” Once we host this XML Web Service, we can access it in any application of any platform using any language, even remotely!
Let us come to the discussion of the inner workings of the “Number to Words” Web service. Even though the main method is “NumberToWords,” the heart (or processing) of the entire XML web service is divided into four “private” methods as follows:
ConvertToWords
Process3DigitNumber
Process2DigitNumber
ProcessSingleDigitNumber
“ConvertToWords” checks number of places (or digits) in the number and chunks the number based on hundreds, thousands, and so forth. The chunked parts of the number are forwarded to “Process3DigitNumber” (for processing only three digit numbers). The “Process3DigitNumber” may forward further to “Process2DigitNumber” (for processing only two digit numbers) or “ProcessSingleDigitNumber” based on the argument it received.
At the moment, “ConvertToWords” can chunk the number to a maximum of hundreds of trillions. The maximum number could be 999,999,999,999,999 (or 999 trillions). But, there always exists a chance of extensibility (say quadrillion, quintillion, and so on). To extend further, you can simply modify and rearrange the “arrays” I declared within “ConvertToWords.”
Now, let us start developing it.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment