Click here to Skip to main content
Click here to Skip to main content

Using SOAP With Classic ASP / VBScript

By , 28 Sep 2007
 

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:

  1. Grab values from text inputs and assign them to variables.
  2. Concatenate your SOAP parameters and use type conversions where necessary.
  3. Put your SOAP parameters in your SOAP envelope.
  4. 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) & _
                     "&amp;" & 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>"
        'MsgBox("new")
        'MsgBox(SOAPParameters)
    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>"
        'MsgBox("upload")
        'MsgBox(SOAPParameters)
    End If

    oXmlHTTP.send SOAPRequest 
    SOAPResponse = oXmlHTTP.responseXML.xml
    'MsgBox(SOAPResponse)
                
    Document.URL = "https://www.realequityhomes.com/" & _ 
                   "rehadmin_manageprops.aspx"
                
End Function    
</script>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

AdamNThompson
Web Developer
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionWhy not use Soap Toolkit 3memberCelare2 Oct '07 - 9:21 
AnswerRe: Why not use Soap Toolkit 3memberAdamNThompson2 Oct '07 - 16:07 
QuestionRe: Why not use Soap Toolkit 3memberCelare4 Oct '07 - 5:52 
AnswerRe: Why not use Soap Toolkit 3memberAdamNThompson4 Oct '07 - 8:08 
AnswerRe: Why not use Soap Toolkit 3memberAdamNThompson7 Oct '07 - 7:31 
AnswerRe: Why not use Soap Toolkit 3memberCelare8 Oct '07 - 10:41 
AnswerRe: Why not use Soap Toolkit 3memberCelare8 Oct '07 - 22:30 
GeneralRe: Why not use Soap Toolkit 3memberAdamNThompson9 Oct '07 - 10:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 28 Sep 2007
Article Copyright 2007 by AdamNThompson
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid