SOAP Client working but need some more functionality

M

monsalvo

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
(e-mail address removed)

Option Explicit

'Variables for the SOAP Call
Dim xmlhttp
Set xmlhttp = CreateObject("Msxml2.XMLHTTP")
Dim xmldoc
Set xmldoc = CreateObject("Msxml2.DOMDocument.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 = "\LoginSessionID.txt"


strRequest = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<soapenv:Envelope xmlns:xsi=""http://www.w3.org/2001/
XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:ser=""http://nn.nn.nn.com"">" & _
"<soapenv:Header/>" & _
"<soapenv:Body>" & _
"<ser:login soapenv:encodingStyle=""http://
schemas.xmlsoap.org/soap/encoding/"">" & _
"<version xsi:type=""xsd:string"">63</version>" & _
"<user xsi:type=""xsd:string"">nn_test</user>" & _
"<password xsi:type=""xsd:string"">nn_Pwd</password>" & _
"</ser:login>" & _
"</soapenv:Body>" & _
"</soapenv:Envelope>"



With xmlhttp
.Open "post", strUrl, False
.setRequestHeader "content-type", "text/xml; charset=utf-8"
.setRequestHeader "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.xml

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

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("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If

If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & 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.OpenTextFile _
(strDirectory & strFile, ForAppending, True)

' Writes strText
objTextFile.WriteLine(strText)
objTextFile.Close

' I'll remove this part after we finish prototyping
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" &" " & strDirectory & "\" )
Else WScript.echo "VBScript Error: " & err.number
End If

WScript.Quit

' End of VBScript
 
J

Joe Fawcett

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
(e-mail address removed)

Option Explicit

'Variables for the SOAP Call
Dim xmlhttp
Set xmlhttp = CreateObject("Msxml2.XMLHTTP")
Dim xmldoc
Set xmldoc = CreateObject("Msxml2.DOMDocument.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 = "\LoginSessionID.txt"


strRequest = "<?xml version=""1.0"" encoding=""utf-8""?>" & _
"<soapenv:Envelope xmlns:xsi=""http://www.w3.org/2001/
XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:ser=""http://nn.nn.nn.com"">" & _
"<soapenv:Header/>" & _
"<soapenv:Body>" & _
"<ser:login soapenv:encodingStyle=""http://
schemas.xmlsoap.org/soap/encoding/"">" & _
"<version xsi:type=""xsd:string"">63</version>" & _
"<user xsi:type=""xsd:string"">nn_test</user>" & _
"<password xsi:type=""xsd:string"">nn_Pwd</password>" & _
"</ser:login>" & _
"</soapenv:Body>" & _
"</soapenv:Envelope>"



With xmlhttp
.Open "post", strUrl, False
.setRequestHeader "content-type", "text/xml; charset=utf-8"
.setRequestHeader "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.xml

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

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("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If objFSO.FolderExists(strDirectory) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFolder = objFSO.CreateFolder(strDirectory)
WScript.Echo "Just created " & strDirectory
End If

If objFSO.FileExists(strDirectory & strFile) Then
Set objFolder = objFSO.GetFolder(strDirectory)
Else
Set objFile = objFSO.CreateTextFile(strDirectory & 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.OpenTextFile _
(strDirectory & strFile, ForAppending, True)

' Writes strText
objTextFile.WriteLine(strText)
objTextFile.Close

' I'll remove this part after we finish prototyping
If err.number = vbEmpty then
Set objShell = CreateObject("WScript.Shell")
objShell.run ("Explorer" &" " & strDirectory & "\" )
Else WScript.echo "VBScript Error: " & err.number
End If

WScript.Quit

' End of VBScript
You can either use selectSingleNode from the responseXML directly or load
into a fresh DOM
Dim oDom
Dim bLoaded
Set oDom = CreateObject("msxml.domdocument.6.0")
bLoaded = oDom.load(xmlhttp.responseXML)
oDom.setProperty "SelectionNamespaces",
"xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:ser='http://nn.nn.nn.com'"


Then select your node(s) using the prefixes defined to qualify element
names. e.g.
soapenv:envelope/soapenv:Body
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top