469,928 Members | 1,884 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,928 developers. It's quick & easy.

SOAP Client working but need some more functionality

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
mo******@gmail.com

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
Aug 6 '08 #1
1 3994


<mo******@gmail.comwrote in message
news:65**********************************@m73g2000 hsh.googlegroups.com...
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
mo******@gmail.com

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

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

Aug 7 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Glauco | last post: by
2 posts views Thread by Tomislav Lepusic | last post: by
reply views Thread by Grzegorz Smith | last post: by
15 posts views Thread by =?Utf-8?B?ZG91Zw==?= | last post: by
4 posts views Thread by wbsurfver | last post: by
5 posts views Thread by =?Utf-8?B?SmltbWVy?= | last post: by
5 posts views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.