When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Monday, July 03, 2000

SOAP: Platform-Independent Server Communication, Part 2

By Erick Stover

  • Read Part 1

  • In Part 1 we looked at building a simple SOAP client. In this part we'll look at building a SOAP server that responds to client requests.

    - continued -

    The first line of our server is very important. It keeps the program from sending the header back before you had the chance to customize it.


    You then need to specify that the returning information is XML. (This needs to be your next line. Your code won't work without it.)

    Response.ContentType = "text/xml"

    Next, open up your XML DOM objects.

    set xmldom = server.CreateObject("Microsoft.XMLDOM")
    set xmlhttp = server.CreateObject("Microsoft.XMLHTTP")

    Now we need to load the XML that the client sent over. This is rather easy

    xmldom.load(Request) 'whoo-hoo

    Now lets build the returning code. This code is responsible for sending a SOAP response back to the client. You could pull this stuff from a database, but for the purpose of this tutorial, I'm just keeping it SIMPLE.

    returnXML = returnXML & "<SOAP:Envelope  " & _
    returnXML = returnXML & "<SOAP:Body>"
    returnXML = returnXML & "<message>"
    returnXML = returnXML & "<theword>XML Shall Set You Free!</theword>"
    returnXML = returnXML & "</message>"
    returnXML = returnXML & "</SOAP:Body>"
    returnXML = returnXML & "</SOAP:Envelope>"
    	'Notice that I still need to use the SOAP naming scheme.

    Now we need to cycle through the client code and find the password and information request. To do this, we use the XMLDOM object and the childnode properties. In order to save typing later on, I like to set these to a variable.

    set res = xmldom.documentElement.childNodes.item(0).childNodes.item(0)

    Now, we check the data that the client sent and see if they qualify.

    if res.childNodes.item(0).text = "HotGnibGnabs" and _
    res.childNodes.item(0).text = "What's the word?" then

    Now for the "hard part". We have to take the XML code we built earlier, and send it back to the client. It took me forever to figure out that all you need to do is:


    That's it! Three hours searching through MSDN and that all it took. Arrgh! Finally, close your IF/Then and clean up your objects.

    end if

    set xmldom = nothing
    set xmlhttp = nothing %>

    Wow, that's it. If it works correctly, and you're using IE5, you will see the words "XML Shall Set You Free!". From here, you could populate the XML code with data from a database depending on what the client requested. Then you could use the XMLDOM object on the client side to merge the data with a XSL style sheet, which would make it visible on any browser. The possibilities are endless!

    p.s. I had a little trouble getting the XMLDOM and XMLHTTP object to show up in Visual Interdev. If you are having these problems, Microsoft (with all their glory) has already solved the problem. Check out: http://support.microsoft.com/support/kb/articles/Q262/1/28.ASP?LN=EN-US&SD=gn&FR=0

    Happy Programming!


  • Run the live demo!
  • Download client.asp in text format
  • Download server.asp in text format
  • Learn More About SOAP!

    Erick Stover

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article