VB中呼叫WebService上的函式的方法

ljm0211發表於2012-06-26
    Dim XMLDOM          As MSXML2.DOMDocument
    Dim XMLDOMBack      As MSXML2.DOMDocument
    Dim soapClient      As MSSOAPLib.soapClient
    Dim xmlNodeList     As MSXML2.IXMLDOMNodeList
   
    Dim strSendXML      As String
    Dim strWSURL        As String
    Dim strWSDLURL      As String
     Dim ErrDesc         As String
    Dim strSuccessFlag As String
   
    Set soapClient = New MSSOAPLib.soapClient
    Set XMLDOM = New MSXML2.DOMDocument
    Set XMLDOMBack = New MSXML2.DOMDocument

    strWSURL = FlowERURL
    strWSDLURL = strWSURL & "?WSDL"

    ''' create input xml stream for GetApproverLevelInfo
    strSendXML = ""
    strSendXML = strSendXML & ""
    While Not rsCCCopies.EOF
        strSendXML = strSendXML & "" & Trim$(rsCCCopies.Fields("usrname").Value) & ""
        rsCCCopies.MoveNext
    Wend
    strSendXML = strSendXML & "
"

    XMLDOM.loadXML (strSendXML)
    soapClient.mssoapinit strWSDLURL, "FlowERAPI", "FlowERAPISoap"
    soapClient.ConnectorProperty("Timeout") = 1000000000
   
    ''' Call WebService Api GetEmployeeInfo
    XMLDOMBack.loadXML (soapClient.GetApproverLevelInfo(XMLDOM.xml))
    strSuccessFlag = Trim$(XMLDOMBack.selectSingleNode("FlowER/SuccessFlag").Text)
    ErrDesc = Trim$(XMLDOMBack.selectSingleNode("FlowER/ReturnInfo").Text)

    If LCase(strSuccessFlag) = "true" Then
   
        ''' success, get leader list of all user
        Set xmlNodeList = XMLDOMBack.selectNodes("FlowER/ReturnInfo/ApproverList")
               
        For intI = 1 To xmlNodeList.length
           
            ''' create input xml stream for GetEmployeeInfo
            strSendXML = ""
            strSendXML = strSendXML & ""
            strSendXML = strSendXML & "" & Trim(xmlNodeList.nextNode.selectSingleNode("Approver/Emp_No").Text) & ""
            strSendXML = strSendXML & "
"
                       
            ''' Call WebService Api GetEmployeeInfo
            XMLDOM.loadXML (strSendXML)
            XMLDOMBack.loadXML (soapClient.GetEmployeeInfo(XMLDOM.xml))
           
            strSuccessFlag = Trim$(XMLDOMBack.selectSingleNode("FlowER/SuccessFlag").Text)
            ErrDesc = Trim$(XMLDOMBack.selectSingleNode("FlowER/ReturnInfo").Text)
           
            If LCase(strSuccessFlag) = "true" Then
                strCCCopies = strCCCopies & Trim$(XMLDOMBack.selectSingleNode("FlowER/ReturnInfo/Mail_Account").Text) & ";"
            Else
           
                ''' error
                MsgBox "GetEmployeeInfo error!" & vbCrLf & "Error Desc: " & ErrDesc & " !", _
                    vbInformation, "Information Message :"
                Exit Function
            End If
        Next intI
    Else
   
        ''' error
        MsgBox "GetApproverLevelInfo error!" & vbCrLf & "Error Desc: " & ErrDesc & " !", _
            vbInformation, "Information Message :"
        Exit Function
    End If

    ''''release object area
    Set XMLDOM = Nothing
    Set soapClient = Nothing
    Set XMLDOMBack = Nothing

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11411056/viewspace-733852/,如需轉載,請註明出處,否則將追究法律責任。

相關文章