Saturday, June 15, 2024

Web Services – server to server with soap

We just recently opted to make’s content library available via a web service. This would allow other web sites to include our links and potentially generate more traffic to the site. So, we needed an efficient way to allow others to access our data with the least amount of strain on our servers. Naturally, the topic of using a SOAP web service came up and turned out to be the most logical choice.

As part of the development process, we chose to output our content into separate XML files on the server based on content category. Our server side portion of the web service would not access the database directly but would instead reference the XML files. This would enable us to minimize database load averages without having to write something special to restrict the number of times the web service could be called. For security purposes, we’ve not included that portion of the code today. Below is the complete server side portion of the web service.

All of our SOAP messages were validated against Microsoft’s SOAP validation kit. We’ve also made this available to you as an added convenience by clicking on SOAP Validator in the left side navigation pane. The client side (your server) portion of the code can be found at:

SOAP Client Side Code Sample

Sub SendContent()

dim oXMLDoc
dim sTypeID
dim sEmail
dim sXML

on error resume next


Set oXMLDoc = Server.CreateObject(“Microsoft.XMLDOM”)

oXMLDoc.load Request ‘ Load the incoming SOAP message.

‘ Retrieve input variables from the incoming SOAP message.

sTypeID = Trim(oXMLDoc.SelectSingleNode(“SOAP-ENV:Envelope
sEmail = Trim(oXMLDoc.SelectSingleNode(“SOAP-ENV:Envelope

Set oXMLDoc = nothing

if ValidateAccount(sEmail,sTypeID) = 0 then
Call WriteSOAPError(“Client”,sEmail & ” is an invalid account”)
Exit Sub
end if

Set oXMLDoc = Server.CreateObject(“MSXML2.DOMDocument.3.0”)

oXMLDoc.load(“C:TEMPYOURXML_ & ” lTypeID & “.xml”))
sXML = Replace(oXMLDoc.xml,””,””) ‘ Remove XML Versioning.
Set oXMLDoc = nothing

With Response

.write “<?xml version=””1.0″”?>”
.write “<SOAP-ENV:Envelope”
.write “xmlns:SOAP= ‘<BR>soap/envelope/'”
.write “SOAP-ENV:encodingStyle= ‘<BR>soap/encoding/’

.write “xmlns:v= ‘<BR>webservices/’> ”
.write “<SOAP-ENV:Body>”
.write “<m:GetContentRespxmlns:m= “”< BR>
.write sXML
.write “</m:GetContentResp>”
.write “</SOAP-ENV:Body>”
.write “</SOAP-ENV:Envelope>”

End with

end sub

Function ValidateAccount(sEmail,stypeID)
‘ Our validation code has been taken out for security reasons.
‘ Insert your own here.
ValidateAccount = 1
End Function

Sub WriteSOAPError(sErrCode,sErrMsg)

With Response

.write “<?xml version=””1.0″”?>” & vbcrlf
.write “<SOAP-ENV:Envelope” & vbcrlf
.write “xmlns:SOAP-ENV= ‘<BR>soap/envelope/'”
& vbcrlf
.write “SOAP-ENV:encodingStyle= ‘<BR>soap/encoding/’
” & vbcrlf
.write “xmlns:v= ‘<BR>webservices/’> ” &
.write “<SOAP-ENV:Body>” & vbcrlf
.write ” <SOAP-ENV:Fault>” & vbcrlf
.write ” <faultcode>SOAP-ENV:Client.AppError</faultcode>” & vbcrlf

.write ” <faultstring>Application Error</faultstring>” & vbcrlf

.write ” <detail>” & vbCRlf
.write ” <message>” & sErrMsg & “</message>” & vbCrLf

.write ” <errorcode>” & sErrCode & “</errorcode>” & vbCrLf

.write “</detail>” & vbCRLF
.write “</SOAP-ENV:Fault>” & vbcrlf
.write “</SOAP-ENV:Body>” & vbcrlf
.write “</SOAP-ENV:Envelope>” & vbcrlf

End with

End Sub

Call SendContent()


Feel free to take both code samples and use them as guide for developing your own SOAP Web Services. If you have any questions or comments, feel free to contact me via the information below.

Robbe D. Morris

Related Articles


Please enter your comment!
Please enter your name here

Latest Articles

New ryan garcia.