Introduction
This is an example of how to use SOAP in Classic ASP / VBScript to communicate with a Web Service. This article is intended for those who still have to work with legacy technologies at work (like myself). This script checks the query string for a user ID, updates an existing record if a user ID is present, and creates a new record otherwise.
Using the code
This is pretty straightforward stuff:
- Grab values from text inputs and assign them to variables.
- Concatenate your SOAP parameters and use type conversions where necessary.
- Put your SOAP parameters in your SOAP envelope.
- Then, send.
<script language="VBScript">
Function Return()
Window.Navigate "https://www.realequityhomes.com/" & _
"rehadmin_manageprops.aspx"
End Function
Function AddProperty()
Dim serviceUrl
Dim TableHTML
Dim SOAPRequest
Dim SOAPParameters
Dim SOAPResponse
Dim oXmlHTTP
Dim oXmlDOC
Dim objNodeRecordList
Dim objNodePropertyField
Dim objRoot
Dim bOK
Dim iPointer
Dim iLimit
Dim strPropertyID
Dim strPropertyType
Dim strAgentID
Dim strDescription
Dim strStreet
Dim strCity
Dim strState
Dim strZip
Dim strPrice
Dim strARV
Dim strMV
Dim strSQFT
Dim strBuilt
Dim strBedrooms
Dim strBaths
Dim strRepairs
Dim strThumb
Dim strImage
Dim strEntered
Dim strSold
Dim strFeatured
Dim strUnListed
strThumb = "https://www.realequityhomes.com/" & _
"_images/thumb_images/t_REHNoImage.jpg"
strImage = "https://www.realequityhomes.com/" &_
"_images/large_images/REHNoImage.jpg"
strPropertyType = "2"
strAgentID = "4"
strDescription = ""
strStreet = ""
strCity = ""
strState = ""
strZip = ""
strPrice = "0"
strARV = "0"
strMV = "0"
strSQFT = "0"
strBedrooms = ""
strBaths = ""
strBuilt = "0"
strRepairs = ""
strEntered = ""
strSold = ""
strFeatured = "0"
strUnListed = "0"
If document.getElementById("chkCommercial").checked Then
strPropertyType = "1"
If document.getElementById("chkFeatured").checked Then
strFeatured = "1"
If document.getElementById("chkUnListed").checked Then
strUnListed = "1"
strPropertyID = document.getElementById("txtPropertyID").value
strDescription = document.getElementById("txtDescription").value
strStreet = document.getElementById("txtStreet").value
strCity = document.getElementById("txtCity").value
strState = document.getElementById("txtState").value
strZip = document.getElementById("txtZip").value
strBedrooms = document.getElementById("txtBedrooms").value
strBaths = document.getElementById("txtBaths").value
strRepairs = document.getElementById("txtRepairs").value
If document.getElementById("txtPrice").value <> "" Then
strPrice = document.getElementById("txtPrice").value
If document.getElementById("txtARV").value <> "" Then
strARV = document.getElementById("txtARV").value
If document.getElementById("txtMV").value <> "" Then
strMV = document.getElementById("txtMV").value
If document.getElementById("txtSQFT").value <> "" Then
strSQFT = document.getElementById("txtSQFT").value
If document.getElementById("txtBuilt").value <> "" Then
strBuilt = document.getElementById("txtBuilt").value
If document.getElementById("txtThumb").value <> "" Then
strThumb = document.getElementById("txtThumb").value
If document.getElementById("txtImage").value <> "" Then
strImage = document.getElementById("txtImage").value
iPointer = InStr(1, strRepairs, "&", 0)
Do While iPointer > 0 And iLimit < 100
strRepairs = Left(strRepairs, iPointer - 1) & _
"&" & Mid(strRepairs, iPointer + 1)
iPointer = InStr(iPointer + 5, strRepairs, "&", 0)
iLimit = iLimit + 1
Loop
strEntered = document.getElementById("txtEntered").value
strSold = document.getElementById("txtSold").value
SOAPParameters = " <lPropertyType>" & _
CLng(strPropertyType) & "</lPropertyType>"
SOAPParameters = SOAPParameters & " <lAgentID>" & _
CLng(strAgentID) & "</lAgentID>"
SOAPParameters = SOAPParameters & " <sPropertyDateEntered>" & _
strEntered & "</sPropertyDateEntered>"
SOAPParameters = SOAPParameters & " <sPropertyDateSold>" & _
strSold & "</sPropertyDateSold>"
SOAPParameters = SOAPParameters & " <sPropertyDescription>" & _
strDescription & "</sPropertyDescription>"
SOAPParameters = SOAPParameters & " <sPropertyRepairs>" & _
strRepairs & "</sPropertyRepairs>"
SOAPParameters = SOAPParameters & " <sPropertyBedrooms>" & _
strBedrooms & "</sPropertyBedrooms>"
SOAPParameters = SOAPParameters & " <sPropertyBaths>" & _
strBaths & "</sPropertyBaths>"
SOAPParameters = SOAPParameters & " <lPropertySQFT>" & _
CLng(strSQFT) & "</lPropertySQFT>"
SOAPParameters = SOAPParameters & " <iPropertyBuilt>" & _
CInt(strBuilt) & "</iPropertyBuilt>"
SOAPParameters = SOAPParameters & " <lPropertyPrice>" & _
CLng(strPrice) & "</lPropertyPrice>"
SOAPParameters = SOAPParameters & " <lPropertyARV>" & _
CLng(strARV) & "</lPropertyARV>"
SOAPParameters = SOAPParameters & " <lPropertyMV>" & _
CLng(strMV) & "</lPropertyMV>"
SOAPParameters = SOAPParameters & " <sPropertyAddressStreet>" & _
strStreet & "</sPropertyAddressStreet>"
SOAPParameters = SOAPParameters & " <sPropertyAddressCity>" & _
strCity & "</sPropertyAddressCity>"
SOAPParameters = SOAPParameters & " <sPropertyAddressState>" & _
strState & "</sPropertyAddressState>"
SOAPParameters = SOAPParameters & " <sPropertyAddressZip>" & _
strZip & "</sPropertyAddressZip>"
SOAPParameters = SOAPParameters & " <sPropertyThumbURL>" & _
strThumb & "</sPropertyThumbURL>"
SOAPParameters = SOAPParameters & " <sPropertyImageURL>" & _
strImage & "</sPropertyImageURL>"
SOAPParameters = SOAPParameters & " <iPropertyFeatured>" & _
CInt(strFeatured) & "</iPropertyFeatured>"
SOAPParameters = SOAPParameters & " <iPropertyUnListed>" & _
CInt(strUnListed) & "</iPropertyUnListed>"
serviceUrl = "https://www.realequityhomes.com/ECTWebServices" & _
"/REHPropertyServices.asmx"
Set oXmlHTTP = CreateObject("Microsoft.XMLHTTP")
oXmlHTTP.Open "POST", serviceUrl, False
If strPropertyID = "" Then
oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", _
"http://tempuri.org/ECTWebServices/" & _
"REHPropertyServices/AddProperty"
SOAPRequest = "<?xml version='1.0' encoding='utf-8'?> <soap:Envelope"
SOAPRequest = SOAPRequest & " xmlns:xsi=""http://" & _
"www.w3.org/2001/XMLSchema-instance"""
SOAPRequest = SOAPRequest & " xmlns:xsd=""http://www." & _
"w3.org/2001/XMLSchema"""
SOAPRequest = SOAPRequest & " xmlns:soap=""http://schemas" & _
".xmlsoap.org/soap/envelope/"">"
SOAPRequest = SOAPRequest & " <soap:Body>"
SOAPRequest = SOAPRequest & " <AddProperty xmlns=""http:" & _
"//tempuri.org/ECTWebServices/REHPropertyServices"">"
SOAPRequest = SOAPRequest & SOAPParameters
SOAPRequest = SOAPRequest & " </AddProperty>"
SOAPRequest = SOAPRequest & " </soap:Body>"
SOAPRequest = SOAPRequest & " </soap:Envelope>"
Else
oXmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
oXmlHTTP.setRequestHeader "SOAPAction", _
"http://tempuri.org/ECTWebServices/" & _
"REHPropertyServices/UpdateProperty"
SOAPRequest = "<?xml version='1.0' encoding='utf-8'?> <soap:Envelope"
SOAPRequest = SOAPRequest & _
" xmlns:xsi=""http://www.w3." & _
"org/2001/XMLSchema-instance"""
SOAPRequest = SOAPRequest & " xmlns:xsd=""http://" & _
"www.w3.org/2001/XMLSchema"""
SOAPRequest = SOAPRequest & " xmlns:soap=""http:" & _
"//schemas.xmlsoap.org/soap/envelope/"">"
SOAPRequest = SOAPRequest & " <soap:Body>"
SOAPRequest = SOAPRequest & " <UpdateProperty " & _
"xmlns=""http://tempuri.org/ECTWebServices/" & _
"REHPropertyServices"">"
SOAPRequest = SOAPRequest & " <lPropertyID>" & _
CLng(strPropertyID) & "</lPropertyID>"
SOAPRequest = SOAPRequest & SOAPParameters
SOAPRequest = SOAPRequest & " </UpdateProperty>"
SOAPRequest = SOAPRequest & " </soap:Body>"
SOAPRequest = SOAPRequest & " </soap:Envelope>"
End If
oXmlHTTP.send SOAPRequest
SOAPResponse = oXmlHTTP.responseXML.xml
Document.URL = "https://www.realequityhomes.com/" & _
"rehadmin_manageprops.aspx"
End Function
</script>