RPGIV编程问题百解(29)VB SOAP程序转化为*SRVPGM
问题:
I have a VB script provided by an address validation service that I'd like to
replace with an iSockets RPG program.
I have zero experience talking to web services, as mentioned this VB script was
given to me.
What I'm hoping is someone who understands this could look over the script and
give me some pointers as to where to start doing it with iSockets. I'm not lazy,
I have made efforts, I'm getting nowhere fast.
Thanks.
---------------------------------------------------------------------------
Dim ArgObj, arg0,cmd,arg1,arg2,arg3,arg4
Set ArgObj = WScript.Arguments
'Create XmlHttp reference
Const SoapServer = "ws.serviceobjects.com"
Const SoapPath = "/av/AddressValidate.asmx/"
Const SoapAction = "ValidateAddressWithFragments"
'Pointers
dim xmldoc
'Strings
dim result
dim addrResult
dim cityResult
dim stateResult
dim zipResult
dim addr2Result
dim countyResult
'Address to validate
strAddress = ArgObj(0)
strAddress2 = ArgObj(1)
strCity = ArgObj(2)
strState = ArgObj(3)
strZip = ArgObj(4)
' Get a free trial key at
strKey="xxx-xxxx-xxxxx"
'URL to be sent in "Get" request
URL = "http://" & SoapServer & SoapPath & SoapAction &"?"
URL = URL + "Address=" + strAddress
URL = URL + "&Address2=" + strAddress2
URL = URL + "&City=" + strCity
URL = URL + "&State=" + strState
URL = URL + "&PostalCode=" + strZip
URL = URL + "&LicenseKey=" + strKey
'Create XmlHttp object
dim srvXmlHttp : set srvXmlHttp = CreateObject("MSXML2.ServerXMLHTTP.3.0")
'Open URL with "Get"
srvXmlHttp.open "GET", URL, false
'Send request
srvXmlHttp.send()
'If the request was successful, set result to the response text. Otherwise,
display error.
if srvXmlHttp.status = 200 Then
result = srvXmlHttp.responseText
else
result="Error sending XmlHttp request"
end if
'Parse the returned here
set xmldoc = CreateObject("Microsoft.XMLDOM")
xmldoc.async = False
xmldoc.loadXML(result)
If xmldoc.documentElement.selectSingleNode("Error") Is Nothing Then
addrResult = xmldoc.documentElement.selectSingleNode("Address").text
addr2Result = xmldoc.documentElement.selectSingleNode("Address2").text
cityResult = xmldoc.documentElement.selectSingleNode("City").text
countyResult = xmldoc.documentElement.selectSingleNode("CountyName").text
zipResult = xmldoc.documentElement.selectSingleNode("Zip").text
stateResult = xmldoc.documentElement.selectSingleNode("State").text
WScript.Echo ("Address: " & addrResult & vbCrLf & "Address2: " & addr2Result &
vbCrLf & "City: " & cityResult & vbCrLf & "County: " & countyResult & vbCrLf &
"Zip: " & zipResult & vbCrLf & "State: " & stateResult & vbCrLf)
else
WScript.Echo "Err: " &
xmldoc.documentElement.selectSingleNode("Error/Desc").text, vbCritical, "Error"
end if
回答:
Turns out the service allows for http GET, PUT and SOAP. I used http GET.
It dumps an .xml document in the IFS with the results, used the xml parser to
extract the results.
Don't need the CPF9898 status message "Validating address, please wait..." any
longer, it's near instantaneous.
c* build url
c eval url = %trim('http://' +
c 'ws.serviceobjects.com' +
c '/av/AddressValidate.asmx/' +
c 'ValidateAddress' +
c '?' +
c 'Address=' + %trim(adrs) +
c '&City=' + %trim(city) +
c '&State=' + %trim(state) +
c '&PostalCode=' + %trim(zip) +
c '&LicenseKey=WS3-NOX2-LAK4')
c* replace embedded blanks with +
c eval urlLen = %len(%trim(url))
c eval url = %xlate(blank: plus:
c %subst(url: 1: urlLen))
c* get a temp file name in the IFS
c eval tempFile= http_tempfile() + '.xml'
c* validate address
c eval rc = http_url_get(url: tempFile)
c if rc <> 1
c callp unlink(tempFile)
c return
c endif
阅读(1153) | 评论(0) | 转发(0) |