Knowledge Essentials - 3Essentials Hosting

SOAP - A simple Example

Article ID: 230

 Back to Search

Below is a simple example that demonstrates how SOAP works.  *3Essentials is not responsible for whether this code works or whether it is suitable for your purposes.

1.  Create a file called client.asp.  Place the below content in the file.  Change the sURL variable to match your website.  Enter as www.domain.com for example.  Do not use HTTP or  leading/trailing back slashes (/\)

<%

Dim objHTTP
   Dim strEnvelope
   Dim strReturn
   Dim objReturn
   Dim dblTax
   Dim strQuery
  
   sURL = "soap.ntforl.com"
  
   set objHTTP = server.CreateObject("Microsoft.XMLHTTP")
 set objReturn = server.CreateObject("Microsoft.XMLDOM")
   'Create the SOAP Envelope
   strEnvelope = _
      "<SOAP:Envelope xmlns:SOAP=""urn:schemas-xmlsoap-org:soap.v1"">" & _
      "<SOAP:Header></SOAP:Header>" & _
      "<SOAP:Body>" & _
      "<m:GetSalesTax xmlns:m=""urn:myserver/soap:TaxCalculator"">" & _
      "<SalesTotal>100</SalesTotal>" & _
      "</m:GetSalesTax>" & _
      "</SOAP:Body>" & _
      "</SOAP:Envelope>"
 
      response.write "SOAP Envelope is:<br><br>" & strEnvelope & "<br><br>"
     
   'Set up to post to our local server
   objHTTP.open "post", "http://" & sURL & "/soap.asp", False

   'Set a standard SOAP/ XML header for the content-type
   objHTTP.setRequestHeader "Content-Type", "text/xml"

   'Set a header for the method to be called
   objHTTP.setRequestHeader "SOAPMethodName", _
      "urn:myserver/soap:TaxCalculator#GetSalesTax"

   'Make the SOAP call
   objHTTP.send strEnvelope

   'Get the return envelope
   strReturn = objHTTP.responseText

   'Load the return envelope into a DOM
   objReturn.loadXML strReturn

   'Query the return envelope
   strQuery = _
      "SOAP:Envelope/SOAP:Body/m:GetSalesTaxResponse/SalesTax"
   dblTax = objReturn.selectSingleNode(strQuery).Text

   response.write "SOAP Return Value is:  <br><br>" & dblTax

%>

 

 

2.  Create another file called soap.asp.  Place the below content in the file.

<%

Set objReq = Server.CreateObject("Microsoft.XMLDOM")

'Load the request into XML DOM
objReq.Load Request

'Query the DOM for the input parameter
strQuery = "SOAP:Envelope/SOAP:Body/m:GetSalesTax/SalesTotal"
varSalesTotal = objReq.SelectSingleNode(strQuery).Text

'Calculate the sales tax
varSalesTax = varSalesTotal * 0.04

'Prepare the return envelope
strTmp = _
"<SOAP:Envelope xmlns:SOAP=""urn:schemas-xmlsoap-org:soap.v1"">" & _
"<SOAP:Header></SOAP:Header>" & _
"<SOAP:Body>" & _
"<m:GetSalesTaxResponse xmlns:m=""urn:myserver/soap:TaxCalc"">" & _
"<SalesTax>" & varSalesTax & "</SalesTax>" & _
"</m:GetSalesTaxResponse>" & _
"</SOAP:Body>" & _
"</SOAP:Envelope>"

'Write the return envelope
Response.Write strTmp

%>

3.  Upload both files to your website

4.  launch a browser and point to the client.asp file.  You will see the SOAP Envelope post to the soap.asp page and display a return value.

 
Downloads Associated With This Article
No downloads are currently associated with this article.