Click here to Skip to main content
Licence CPOL
First Posted 21 Aug 2007
Views 36,882
Bookmarked 18 times

Using SOAP With Classic ASP / VBScript

By | 28 Sep 2007 | Article
How to use SOAP with Classic ASP / VBScript.

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

I am a .NET Developer for company that builds custom web applications. It's an interesting job because each site is different. We build anything that the mind can imagine, and the client can afford.
 
Fun stuff... Smile | :)
 
CP is my favorite site for code samples, news, and articles. I like the community here and I like the fact that it mainly caters to developers using the .NET platform.
 
I also write a blog on .NET Development
adam-thompson.com

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

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWhy not use Soap Toolkit 3 PinmemberCelare9:21 2 Oct '07  
AnswerRe: Why not use Soap Toolkit 3 PinmemberAdamNThompson16:07 2 Oct '07  
QuestionRe: Why not use Soap Toolkit 3 PinmemberCelare5:52 4 Oct '07  
But the last ever version of the SOAP Toolkit (version 3) was first released mid 2003 (it was officially retired in 2005). The reason I'm asking is that I use SOAP Toolkit 3 on a production server and I thought maybe you knew of a problem that caused you to choose not to use it. Is that not the case?
AnswerRe: Why not use Soap Toolkit 3 PinmemberAdamNThompson8:08 4 Oct '07  
AnswerRe: Why not use Soap Toolkit 3 PinmemberAdamNThompson7:31 7 Oct '07  
AnswerRe: Why not use Soap Toolkit 3 PinmemberCelare10:41 8 Oct '07  
AnswerRe: Why not use Soap Toolkit 3 PinmemberCelare22:30 8 Oct '07  
GeneralRe: Why not use Soap Toolkit 3 PinmemberAdamNThompson10:24 9 Oct '07  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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