Hello.
I've just coded a VBScript SOAP Client to send requests to a web
service in our intranet. It's working and we'll use it in a DTS cuz we
have not implemented SQL Server 2005 yet. Anyway. I need some more
functionality. For example with the script below I'm able to get the
Session ID Token from our web service and save the full SOAP xml
Envelope to a file. But What if for example I want to save certain
nodes I receive in the response?? I set it up so that I can use DOM,
been trying to do that but I'm getting errors.
If you have any tips they will be much appreciated.
Regards.
Martin
monsalvo@gmail. com
Option Explicit
'Variables for the SOAP Call
Dim xmlhttp
Set xmlhttp = CreateObject("M sxml2.XMLHTTP")
Dim xmldoc
Set xmldoc = CreateObject("M sxml2.DOMDocume nt.4.0")
Dim strUrl, strRequest
strUrl = "http://nn.nn.com/nn"
'Variables for saving the Session ID
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strDirectory = "C:\Sample"
strFile = "\LoginSessionI D.txt"
strRequest = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<soapenv:Envel ope xmlns:xsi=""htt p://www.w3.org/2001/
XMLSchema-instance"" xmlns:xsd=""htt p://www.w3.org/2001/XMLSchema""
xmlns:soapenv=" "http://schemas.xmlsoap .org/soap/envelope/""
xmlns:ser=""htt p://nn.nn.nn.com""> " & _
"<soapenv:Heade r/>" & _
"<soapenv:Body> " & _
"<ser:login soapenv:encodin gStyle=""http://
schemas.xmlsoap .org/soap/encoding/"">" & _
"<version xsi:type=""xsd: string"">63</version>" & _
"<user xsi:type=""xsd: string"">nn_tes t</user>" & _
"<password xsi:type=""xsd: string"">nn_Pwd </password>" & _
"</ser:login>" & _
"</soapenv:Body>" & _
"</soapenv:Envelop e>"
With xmlhttp
.Open "post", strUrl, False
.setRequestHead er "content-type", "text/xml; charset=utf-8"
.setRequestHead er "SOAPAction ", "http://nn.nn.nn.com/login"
.send strRequest
'Here I echo out the response for testing porpuses - it's
working ok
wscript.echo .responseXML.xm l
'Here I place the reponse in the variable strText - it's
working ok - But what if I want to place just one element of the SOAP
envelope in the variable, for example the session ID number with
getting rid of all xml tags?
strText = .responseXML.xm l
End With
'The rest of the script is working ok. I mean it saves the Web Service
XML response to a file.
' Create the File System Object
Set objFSO = CreateObject("S cripting.FileSy stemObject")
' Check that the strDirectory folder exists
If objFSO.FolderEx ists(strDirecto ry) Then
Set objFolder = objFSO.GetFolde r(strDirectory)
Else
Set objFolder = objFSO.CreateFo lder(strDirecto ry)
WScript.Echo "Just created " & strDirectory
End If
If objFSO.FileExis ts(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolde r(strDirectory)
Else
Set objFile = objFSO.CreateTe xtFile(strDirec tory & strFile)
Wscript.Echo "Just created " & strDirectory & strFile
End If
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenText File _
(strDirectory & strFile, ForAppending, True)
' Writes strText
objTextFile.Wri teLine(strText)
objTextFile.Clo se
' I'll remove this part after we finish prototyping
If err.number = vbEmpty then
Set objShell = CreateObject("W Script.Shell")
objShell.run ("Explorer" &" " & strDirectory & "\" )
Else WScript.echo "VBScript Error: " & err.number
End If
WScript.Quit
' End of VBScript
I've just coded a VBScript SOAP Client to send requests to a web
service in our intranet. It's working and we'll use it in a DTS cuz we
have not implemented SQL Server 2005 yet. Anyway. I need some more
functionality. For example with the script below I'm able to get the
Session ID Token from our web service and save the full SOAP xml
Envelope to a file. But What if for example I want to save certain
nodes I receive in the response?? I set it up so that I can use DOM,
been trying to do that but I'm getting errors.
If you have any tips they will be much appreciated.
Regards.
Martin
monsalvo@gmail. com
Option Explicit
'Variables for the SOAP Call
Dim xmlhttp
Set xmlhttp = CreateObject("M sxml2.XMLHTTP")
Dim xmldoc
Set xmldoc = CreateObject("M sxml2.DOMDocume nt.4.0")
Dim strUrl, strRequest
strUrl = "http://nn.nn.com/nn"
'Variables for saving the Session ID
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strDirectory = "C:\Sample"
strFile = "\LoginSessionI D.txt"
strRequest = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<soapenv:Envel ope xmlns:xsi=""htt p://www.w3.org/2001/
XMLSchema-instance"" xmlns:xsd=""htt p://www.w3.org/2001/XMLSchema""
xmlns:soapenv=" "http://schemas.xmlsoap .org/soap/envelope/""
xmlns:ser=""htt p://nn.nn.nn.com""> " & _
"<soapenv:Heade r/>" & _
"<soapenv:Body> " & _
"<ser:login soapenv:encodin gStyle=""http://
schemas.xmlsoap .org/soap/encoding/"">" & _
"<version xsi:type=""xsd: string"">63</version>" & _
"<user xsi:type=""xsd: string"">nn_tes t</user>" & _
"<password xsi:type=""xsd: string"">nn_Pwd </password>" & _
"</ser:login>" & _
"</soapenv:Body>" & _
"</soapenv:Envelop e>"
With xmlhttp
.Open "post", strUrl, False
.setRequestHead er "content-type", "text/xml; charset=utf-8"
.setRequestHead er "SOAPAction ", "http://nn.nn.nn.com/login"
.send strRequest
'Here I echo out the response for testing porpuses - it's
working ok
wscript.echo .responseXML.xm l
'Here I place the reponse in the variable strText - it's
working ok - But what if I want to place just one element of the SOAP
envelope in the variable, for example the session ID number with
getting rid of all xml tags?
strText = .responseXML.xm l
End With
'The rest of the script is working ok. I mean it saves the Web Service
XML response to a file.
' Create the File System Object
Set objFSO = CreateObject("S cripting.FileSy stemObject")
' Check that the strDirectory folder exists
If objFSO.FolderEx ists(strDirecto ry) Then
Set objFolder = objFSO.GetFolde r(strDirectory)
Else
Set objFolder = objFSO.CreateFo lder(strDirecto ry)
WScript.Echo "Just created " & strDirectory
End If
If objFSO.FileExis ts(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolde r(strDirectory)
Else
Set objFile = objFSO.CreateTe xtFile(strDirec tory & strFile)
Wscript.Echo "Just created " & strDirectory & strFile
End If
set objFile = nothing
set objFolder = nothing
' OpenTextFile Method needs a Const value
' ForAppending = 8 ForReading = 1, ForWriting = 2
Const ForAppending = 8
Set objTextFile = objFSO.OpenText File _
(strDirectory & strFile, ForAppending, True)
' Writes strText
objTextFile.Wri teLine(strText)
objTextFile.Clo se
' I'll remove this part after we finish prototyping
If err.number = vbEmpty then
Set objShell = CreateObject("W Script.Shell")
objShell.run ("Explorer" &" " & strDirectory & "\" )
Else WScript.echo "VBScript Error: " & err.number
End If
WScript.Quit
' End of VBScript
Comment