Home arrow Visual Basic arrow Page 4 - Developing an XML Web Service Using Visual Studio 2005

Developing an XML Web Service Using Visual Studio 2005

This article guides you in developing a practical “Number to Words” web service using the latest Microsoft Visual Studio 2005 as the development tool.

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 79
December 13, 2005
  1. · Developing an XML Web Service Using Visual Studio 2005
  2. · Brief explanation of the “Number to Words” XML Web Service
  3. · Creating XML Web Service using Visual Studio 2005
  4. · Developing the XML Web Service
  5. · Developing the XML Web Service continued
  6. · Executing and testing the XML Web Service

print this article

Developing an XML Web Service Using Visual Studio 2005 - Developing the XML Web Service
(Page 4 of 6 )

Before proceeding further, you need to remove (or comment) all the statements related to the “HelloWorld” method (as it is intended only for demonstration). 

Start with a new method “NumberToWords” as following:

[WebMethod(Description = "Returns the given number in words.")]
    public string NumberToWords(long Number)
        string sRetVal = "";
            sRetVal = ConvertToWords(Number);
        catch (Exception ex)
            return String.Format("Error: {0}", ex.Message);
        return sRetVal;

You should observe that the “NumberToWords” method does not process anything at the moment (apart from accepting a “long” number as parameter).  The processing starts with the “ConvertToWords” method.  Now, let us proceed with the “ConvertToWords” method as following:

private string ConvertToWords(long lValue)
        //If the give number excides 999 trillion then raise an exception.
        if (lValue.ToString().Length > 15)
            throw new Exception("Excides maximum limit. This Service can translate up to 999 trillion.");
        string sInWords = "";
        string sSource = lValue.ToString();
        string sStirngToProcess = "", sProcessedString = "";
        string[] arrPalce = { "", " Thousand ", " Million ", " Billion ", " Trillion " };
        int nCount = 0;
        while (sSource.Trim().Length > 0)
            //Take last 3 digits from the given number
            if (sSource.Length > 3)
                sStirngToProcess = sSource.Substring(sSource.Length - 3);
                sSource = sSource.Substring(0, sSource.Length - 3);
                sStirngToProcess = sSource;
                sSource = "";
            //Process last 3 digits
            sProcessedString = Process3DigitNumber(sStirngToProcess);
            if (sProcessedString.Trim().Length > 0)
                sInWords = sProcessedString + arrPalce[nCount] +
        if (sInWords.Trim().Length <= 0)
            sInWords = "Zero";
        return sInWords;

You could observe from the above code that the number gets divided into several chunks which are later processed by the “Process3DigitNumber” method.  Now, let us go through the implementation details of “Process3DigitNumber”, “Process2DigitNumber” and “ProcessSingleDigitNumber” in the next section.

blog comments powered by Disqus

- Developing an XML Web Service Using Visual S...
- Creating an HTML File List with VB
- Fun with Email: VB6, CDO, MAPI, and a Remote...
- Extranet/Intranet Dictionary Cracker in VB
- Finding Default App Icons With Visual Basic
- Registry Fever With Visual Basic
- Implementing An ADO Data Control With VB6
- Printing With Visual Basic
- MSMQ Part 1/2: Architecture and Simple Imple...
- Magnifying The Desktop With Visual Basic
- Sending Email With MAPI Components in Visual...
- Two Person Chat With The Winsock Control And...
- A Real-Time ActiveX News Control
- Accessing the Windows API in Visual Basic

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials