2013-05-21 64 views
0

現在我正在使用VB6中的SOAP,並且遇到了一些麻煩。 我需要的是將SOAP發送到Web服務器並將結果保存到XML文件中。如何通過VB6中的HttpRequest發送SOAP

這裏是HttpRequest示例從網站上刮取的。

有關更多詳細信息,請參閱URL。 https://www.ftq360.net/Collect/ExportSvc_JRJC.asmx?op=ExportJRJC

我安裝了SOAP Toolkit3.0,並在VB參考對話框中添加了Microsoft SOAP3.0 Library。 谷歌搜索後,我寫了一些代碼如下,並沒有錯誤。

我的麻煩是,我必須做的! 我擅長VB,但對Web服務一無所知。 我希望你的快速幫助。 謝謝大家。

+0

您沒有提供一個例子,但這個基本上可以歸結爲「我怎麼使用SOAP」。因此,它是[如何在VB6中使用SOAP Web服務?](http://stackoverflow.com/questions/5104143/how-to-consume-a-soap-web-service-in-vb6 ) – Deanna

回答

1

只要你是客戶端,你就可以使用MSXML-API來處理到SOAP-Server的HTTP通信。

這裏HTTP-處理的示例類:

Option Explicit 
Private HTTPHandler As MSXML2.ServerXMLHTTP 

Public Event OnReadyStateChange() 

Public Sub SendSoapRequest() 
Dim SoapDocument As MSXML2.DOMDocument 

    'set the document 
    'eigther as string 
    SoapDocument.loadXML "<xml......" 
    'or from file 
    SoapDocument.Load "C:\Foo\SoapDoc.xml" 
    'or by assembling it in code (see MSXML-documentation) 
    SoapDocument.appendChild SoapDocument.createNode(NODE_ELEMENT, "SoapDocRootNode", "NamespaceURI") 
    SoapDocument.documentElement SoapDocument.createNode(NODE_ELEMENT, "SoapDoc1stChild", "") 
    '... 

    SendRequest SoapDocument, "http://soapserver:8080/someresurce/" 
End Sub 

Private Sub SendRequest(XmlDoc As MSXML2.DOMDocument, URL) 

On Error GoTo ErrReq 
    'setting the URL and the request type (in this case POST to transmit the XML-Document) 
    HTTPHandler.open "POST", URL, True 
    'setting the request-header 
    'optional but some servers require it 
    HTTPHandler.setRequestHeader "Content-Type", "text/xml" 
    HTTPHandler.setRequestHeader "Accept", "text/xml" 
    HTTPHandler.setRequestHeader "Accept-Charset", "iso-8859-1" 'adapt to the server-settings 


    HTTPHandler.send XmlDoc 

    DoEvents 

    Exit Sub 
ErrReq: 
    MsgBox "SendRequest: Error while sending the request" + vbCrLf + Err.Description 
End Sub 

Private Sub OnReadyStateChange() 
'important: Procedure has to be set as default in the procedure attribites dialog 
'otherwise you can only poll for readyState to become the value of 4 
Dim ReceivedDoc As MSXML2.DOMDocument 
Dim Start As Single 

On Error GoTo ErrNewData 

    'while the readyState is below 4 there is no result available yet 
    If HTTPHandler.readyState <> 4 Then Exit Sub 

    'check for server-result 200 (OK) 
    If HTTPHandler.Status <> 200 Then 'OK 
     'something went wrong at server site 
     MsgBox "OnReadyStateChange: server responded with error message" + vbCrLf + _ 
       HTTPHandler.Status + vbCrLf + _ 
       HTTPHandler.statusText 
     Exit Sub 
    End If 

    'wait for the returned document to be parsed 
    Start = Timer 
    Do Until ReceivedDoc.parsed 
     DoEvents 
     'if running over midnight 
     If Start > Timer Then Start = Start - 86400 

     'timeout of 5 seconds 
     If Timer - Start > 5 Then 
      MsgBox "OnReadyStateChange: Timeout while paring the returned document" 
      Exit Sub 
     End If 
    Loop 

    If ReceivedDoc.parseError <> 0 Then 
     MsgBox "OnReadyStateChange Error while parsing the returned document" + vbCrLf + _ 
       ReceivedDoc.parseError.reason + vbCrLf + _ 
       "Position: Line" + CStr(ReceivedDoc.parseError.Line) + " row" + CStr(ReceivedDoc.parseError.linepos) 
     Exit Sub 
    End If 

    ResponseHandler 

    Exit Sub 
ErrNewData: 

    MsgBox "OnReadyStateChange: Error while processing the server response" + vbCrLf + Err.Description 

End Sub 

Private Sub ResponseHandler(XmlDoc As MSXML2.DOMDocument) 
    'Handle the Response 
End Sub 
相關問題