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

SOAP: Platform-Independent Server Communication

By Erick Stover


You know the scenario, you need to somehow get data from your server to your customer's server and this needs to be implemented tomorrow. No problem, let's write a VB Com object that will create a constant link to the customer's server through Port 1452 and anytime our database is updated it will transmit the data across! No, wait. There's no way I can implement that by tomorrow. Plus, opening that port on our firewall will completely invalidate our network security guidelines. Ok, We can just send them weekly backups! Yeah, right.

Well, what do I have left? The answer was like a shining ray of light from the heaven's above: SOAP! SOAP, the Simple Object Access Protocol, is the newest toy to come from the World Wide Web Consortium and Microsoft. Based on XML, it allows the transfer of data through the HTTP headers. This means you can conduct all you transfers on port 80, therefore preventing the opening of any security holes on your server.

How is it done? Simple. In its basic form, SOAP consists of two files: Client and Server, and its dependant on the XMLDOM and XMLHTTP objects. Lets build a client, shall we?

You want to start off by setting up your objects.

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

(I think it should be noted that the objects will only exists on your server if IE5 has been installed. Talk to your sysadmin if you're not sure.)

I use a constant to tell it where the SOAP server is located.

const SoapServer = "http://www.yourserver.com/SOAP/server.asp"

I then create a function that will build the request XML. You can pretty much put this anyway you like. In this case, I have a "password" and a question.

function SoapTest()
  SoapTest = SoapTest & "<SOAP:Envelope  " & _
         "xmlns:SOAP=""urn:schemas-xmlsoap-org:soap.v1"">"
  SoapTest = SoapTest & "<SOAP:Body>"
  SoapTest = SoapTest & "<TestRequest>"
  SoapTest = SoapTest & "<auth>HotGnibGnabs</auth>"
  SoapTest = SoapTest & "<message>What's the word?</message>"
  SoapTest = SoapTest & "</TestRequest>"
  SoapTest = SoapTest & "</SOAP:Body>"
  SoapTest = SoapTest & "</SOAP:Envelope>"	
end function	

Keep in mind that when making your SOAP XML, there are some required fields. Without the <SOAP:Envelope> and the <SOAP:Body>, this might work, but it just isn't SOAP. Keep that in mind. It should also be noted that the regular XML rules apply here. The tags are case sensitive and attributes have to be surrounded in quotes. (To learn more about XML be sure to check out the XML Section on 4Guys!)

In order to make use of the SOAP, you also need to have certain lines in your header. I use the XMLHTTP object to set those up.

xmlhttp.open "POST", SoapServer, false
xmlhttp.setRequestHeader "Man", POST & " " & SoapServer & " HTTP/1.1"
xmlhttp.setRequestHeader "MessageType", "CALL"
xmlhttp.setRequestHeader "Content-Type", "text/xml"
xmlhttp.send(SoapTest)

The first line tells the object that you want to open a POST connection to the SOAP server mentioned above and that I don't want it to return immediately (the default value for this is true). On the second line. I am just setting up a basic POST header. The third line lets the server know that this page is expecting info to be returned. The forth line is obvious and very required. Finally, we tell it to send the request XML.

The SOAP server (specified by the SoapServer constant) returns an XML-formatted response when it is called. Therefore, our client must have code ready to handle this response. Start with an if then statement.

'Anything other than 200 means error.
if xmlhttp.Status = 200 then
  'collects the data returned.
  Set xmldom = xmlhttp.responseXML
  
  'writes it to the screen.
  Response.write(xmldom.xml)

'Just some error checking. I use this to see why its messing up. 
Else
  Response.Write("Didn't Work
") 'Writes the error code returned by the server. Response.Write("status="&xmlhttp.status) 'Writes the accompanying text. Response.write("
"&xmlhttp.statusText) Response.Write("
"&Request.ServerVariables("ALL_HTTP")) End if

Finally, do a little cleaning.

set xmlhttp = nothing
set xmldom = nothing
%>

You now have a basic SOAP client! Now the fun part: The Server (insert scary music here...)! In Part 2 we'll look at building the server. This server will be responsible for responding to requests from SOAP clients.

  • Read Part 2


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


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