Tutorials » Creating a Web Service using ActiveX Components

ASP User Interface

We will use math.asp to provide the user with an interface to enter in a number and get either

(a) The square root .
(b) The factorial of that number.

Math.asp will call our SOAP Client passing the method call and entered number. Our Soap Client will call our Soap Server. Our Soap Server will process request and respond with the answer.

Code for ASP Application - math.asp


dim action, answer

' Get Action

action = request.Querystring("get")

Select Case action
    Case "CalcSquareRoot"
        answer = "The Square Root of " & Request.Form("txNumber") & " is: " & _
        SendSOAP(Request.QueryString("get"), Request.Form("txNumber"))

    Case "CalcFactorial"
        answer = "The Factorial of " & Request.Form("txNumber") & " is: " & _
        SendSOAP(Request.QueryString("get"), Request.Form("txNumber"))
End Select

' Call SOAP Client, passing method call and user entered number

Function SendSOAP(methodCall, num)
     dim SOAPClient

     Set SOAPClient = Server.CreateObject("SOAPClient.CreateSOAP")
     SendSOAP = SOAPClient.GenerateSOAP(methodCall, num)
End Function

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

' Submit form

<script language="javascript">

function GetAnswer(action)
     if(document.MathForm.txNumber.value != "")
         document.MathForm.action = "math.asp?get=" + action;

<body bgcolor="#FFFFFF" text="#000000">
<form name="MathForm" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td width="16%">&nbsp;</td>
<td colspan="2">&nbsp;</td>
<td width="16%">Enter Number</td>
<td width="24%">
<input type="text" name="txNumber">
<td width="60%"><%=answer%></td>
<td width="16%">&nbsp;</td>
<td colspan="2">&nbsp;</td>
<td width="16%">&nbsp;</td>
<td colspan="2">
<input type="button" name="btnFact" value="Get Factorial"     onClick="GetAnswer('CalcFactorial')">
<input type="button" name="btnSqr" value="Get Square Root"     onClick="GetAnswer('CalcSquareRoot')">

Previous Start Next
  1 2 3 4 5 6