To read the article online, visit http://www.4GuysFromRolla.com/webtech/070300-2.2.shtml

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.

    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.

    <%
    Response.Buffer=true

    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  " & _
           "xmlns:SOAP=""urn:schemas-xmlsoap-org:soap.v1"">"
    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:

    Response.Write(returnXML)

    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!


    Attachments

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

    Erick Stover
    lorddragon@dragonden.net
    http://www.dragonden.net/


  • Article Information
    Article Title: SOAP: Platform-Independent Server Communication, Part 2
    Article Author: Erick Stover
    Published Date: Monday, July 03, 2000
    Article URL: http://www.4GuysFromRolla.com/webtech/070300-2.2.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers