5,276,801 members and growing! (15,798 online)
Email Password   helpLost your password?
Languages » VBScript » General     Intermediate License: The Code Project Open License (CPOL)

Using SOAP With Classic ASP / VBScript

By AdamNThompson

Using SOAP With Classic ASP / VBScript
VBScript, Windows, Visual Studio, Dev

Posted: 21 Aug 2007
Updated: 28 Sep 2007
Views: 8,005
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
4 votes for this Article.
Popularity: 2.24 Rating: 3.71 out of 5
1 vote, 25.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
2 votes, 50.0%
4
1 vote, 25.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

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 technology 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 straight forward 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


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...

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.
Occupation: Web Developer
Location: United States United States

Other popular VBScript articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 8 of 8 (Total in Forum: 8) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionWhy not use Soap Toolkit 3memberCelare10:21 2 Oct '07  
AnswerRe: Why not use Soap Toolkit 3memberAdamNThompson17:07 2 Oct '07  
QuestionRe: Why not use Soap Toolkit 3memberCelare6:52 4 Oct '07  
AnswerRe: Why not use Soap Toolkit 3memberAdamNThompson9:08 4 Oct '07  
AnswerRe: Why not use Soap Toolkit 3memberAdamNThompson8:31 7 Oct '07  
AnswerRe: Why not use Soap Toolkit 3memberCelare11:41 8 Oct '07  
AnswerRe: Why not use Soap Toolkit 3memberCelare23:30 8 Oct '07  
GeneralRe: Why not use Soap Toolkit 3memberAdamNThompson11:24 9 Oct '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 28 Sep 2007
Editor:
Copyright 2007 by AdamNThompson
Everything else Copyright © CodeProject, 1999-2008
Web07 | Advertise on the Code Project