Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

Creating the Four Function Calculator in ASP

Those of you who are building ASP applications in the .NET framework but who are not always using the Visual Studio.NET tools can still create XML Web services. Type the code in Listing 7.6 into Notepad and save it as SmallCalc.asmx. This file must be saved to a directory that IIS can run code from. Now, run it in Internet Explorer to see the results. You should get a service with an Add method that is identical to the service created earlier with Visual Studio.NET.

Listing 7.6 ASP Code for Creating the SmallCalc XML Web Service

1:  <%@ Web Service Language="VB" Class="SmallCalc" %>
3:  Imports System
4:  Imports System.Web.Services
6:  Public Class SmallCalc:
8:   	 <WebMethod()> Public Function Add(iNum1 as Integer, _
9:             iNum2 as Integer) As Double
10:     		 Return (iNum1 + iNum2)
11:	 End Function
13:  End Class

The first item that you should notice is the header of the ASP file (line 1 in Listing 7.6). The addition of the Web Service tag lets the ASP compiler know that you are building a service.

Line 4 of the code is where you import the System.Web.Services namespace. This namespace contains the Web Service class that our class, SmallCalc, is built upon. This is done when SmallCalc is declared, in line 6, as inheriting from Web Service.

Last, note that the function declaration for Add(), line 8 of Listing 7.6, is identical to the declaration used in your Visual Basic code, line 2 of Listing 7.4.

You should be able to add the other three functions to this code and create the WSDL contract file for this service. Doing so should help get you used to working with XML Web services.


In ASP.NET, asax and asmx files are compiled on their initial use. This means that, even if you use Notepad to create your files, you create robust applications built on native code.

  • + Share This
  • 🔖 Save To Your Account