SOAP Client working but need some more functionality

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monsalvo@gmail.com

    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
    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
  • Joe Fawcett

    #2
    Re: SOAP Client working but need some more functionality



    <monsalvo@gmail .comwrote in message
    news:6595b4b6-861b-4dd4-92ca-1cc80b0b64a3@m7 3g2000hsh.googl egroups.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
    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
    You can either use selectSingleNod e from the responseXML directly or load
    into a fresh DOM
    Dim oDom
    Dim bLoaded
    Set oDom = CreateObject("m sxml.domdocumen t.6.0")
    bLoaded = oDom.load(xmlht tp.responseXML)
    oDom.setPropert y "SelectionNames paces",
    "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:envelop e/soapenv:Body

    --

    Joe Fawcett (MVP - XML)


    Comment

    Working...