65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 SOAP 与经典 ASP / VBScript

starIconstarIconstarIconstarIconemptyStarIcon

4.00/5 (5投票s)

2007年8月21日

CPOL
viewsIcon

90629

如何在经典 ASP / VBScript 中使用 SOAP。

引言

这是一个在经典 ASP / VBScript 中使用 SOAP 与 Web Service 通信的示例。 本文面向那些仍然需要在工作中处理遗留技术的人员(比如我自己)。 该脚本检查查询字符串中的用户 ID,如果存在用户 ID 则更新现有记录,否则创建新记录。

使用代码

这很简单。

  1. 从文本输入框中获取值并将其分配给变量。
  2. 连接你的 SOAP 参数,并在必要时使用类型转换。
  3. 将你的 SOAP 参数放入 SOAP 信封中。
  4. 然后,发送。
<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>"
        '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>
© . All rights reserved.