Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 74,280 times

Contents

Related Categories

XML SOAP - The Server

The Server

Our server needs to be configured to accept the HTTP post sent by the client. It will be noted that we direct the client’s post to a URL on our local server – http://localhost/soap.asp. So our first job is to create this page, to listen for, and process, SOAP calls to our server. We know that our ASP will receive an XML document, in the form of an HTTP post, with a method name (GetSalesTax), and a parameter (SalesTotal). So, to write our basic listener service, all we need do is deconstruct the body of the request (the SOAP envelope) and pull out the value of the SalesTotal parameter.

The SOAP envelope posted by the client is contained in the body of the request, or in ASP terms the Request object; and because it is XML, we can load it into an instance of Microsoft’s XMLDOM in our ASP. Soap.asp begins like this:

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

objReq.Load Request

Thus objReq contains the SOAP envelope we created on the client, and we can extract the value of the SalesTotal parameter by running an XSL pattern query, using the SelectSingleNode method of the XML DOM object :

strQuery = "SOAP:Envelope/SOAP:Body/m:GetSalesTax/SalesTotal" varSalesTotal = objReq.SelectSingleNode(strQuery).Text

With the parameter extracted, we can make our calculation to get the sales-tax:

varSalesTax = varSalesTotal * 0.04

Now we have the return value for sales-tax – the response - ready to pass back to the client, but as with the request, we need to format this response correctly, in order to comply with the SOAP standard. The SOAP response envelope conforms to a format-type identical to the request. The only difference is that the “IN” parameter (SalesTotal, in our case) is replaced by an “OUT” parameter – SalesTax, and the method name indicates that the document is a response:

<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>4</SalesTax>
      </m:GetSalesTaxResponse>
   </SOAP:Body>
</SOAP:Envelope>

We can build up this document, either by string-concatenation, or by creating a new instance of a DOM, and appending the appropriate nodes.

Back on the client, the response is received, and can be decoded by extracting the appropriate node from the Envelope document:

Dim objReturn As New MSXML.DomDocument
objReturn.LoadXML strReturn
strQuery = _
  "SOAP:Envelope/SOAP:Body/m:GetSalesTaxResponse/SalesTax"
dblTax = objReturn.SelectSingleNode(strQuery).Text

And that’s it! A functional, compliant SOAP service in a few easy steps. Of course, the service that we have provided is far from sophisticated, but that is to miss the point. In the not-too-distant future, Visual Studio 7 will completely mask the implementation of SOAP; but I believe that there is value in understanding the way the engine turns beneath the hood. SOAP itself is a very simple protocol; and I hope you leave this article with a better understanding the infrastructure that lies behind SOAP, and the methodology through which SOAP-based component services are going to be provided in the future.

Comments

  • Posted by kpma_l on 19 May 2004

    [quote][1]Posted by [b]kpma_l[/b] on 19 May 2004 04:05 PM[/1]
    I tried to copy the the code and add references to VB project and run the VB app. but get runtime error at the DOMDocument object accesin...

  • getting Runtime error 91 - object or with block va

    Posted by kpma_l on 19 May 2004

    I tried to copy the the code and add references to VB project and run the VB app. but get runtime error at the DOMDocument object accesing a single node.

    Run time error 91.

    MSXML2 and MTS Admin ...

  • WebServices

    Posted by shirikok on 01 Apr 2004

    In .NET web services; How to monitor from where (mostly his/her web site URL but not his/her machine IP) requester is consuming the web service? Techies, [b]'HTTP_REFERER' [/b] and [b]'URLReferrer'[/b...

  • XML SOAP - ASP

    Posted by shirikok on 01 Apr 2004

    Great work by ComponentSource and they have very well explained VB 6.0 client and access to web service. I have a question here. How to monitor from where (mostly his/her web site URL not his/her mac...

  • got the same ???????+???...

    Posted by synapticdata on 20 Nov 2003

    if anyone knows the meaning of this, i could use the feedback. my hunch is, that the SOAP server is not configured to handle the request properly. but i dunno... =)