2013-05-21 3 views
0

이제 VB6에서 SOAP로 작업하고 있는데 약간의 문제가 있습니다. 내가 필요한 것은 SOAP를 웹 서버에 보내고 그 결과를 XML 파일에 저장하는 것입니다.VB6에서 HttpRequest를 통해 SOAP을 보내는 방법

다음은 사이트에서 긁힌 HttpRequest 샘플입니다.

자세한 내용은 URL을 참조하십시오. https://www.ftq360.net/Collect/ExportSvc_JRJC.asmx?op=ExportJRJC

SOAP Toolkit3.0을 설치하고 Microsoft SOAP 3.0 라이브러리를 VB 참조 대화 상자에 추가했습니다. 인터넷 검색 결과, 아래 코드를 작성했는데 오류가 없습니다.

내 문제는 그 후에해야 할 일입니다. 나는 VB에서 잘하고 있지만 웹 서비스에 대해서는 모른다. 빠른 도움을 바랍니다. 감사합니다.

+0

당신은 예를 제공하지 않은 그러나 이것은 기본적으로 "어떻게 SOAP을 사용합니까"로 요약된다 : 여기

HTTP-처리를위한 예를 들어 클래스

. 따라서 [VB6에서 SOAP 웹 서비스를 사용하는 방법]은 가능한 복제본입니다 (http://stackoverflow.com/questions/5104143/how-to-consume-a-soap-web-service-in-vb6) – Deanna

답변

1

클라이언트 인 경우에만 SOAP 서버에 대한 HTTP 통신을 처리하기 위해 MSXML-API를 사용할 수 있습니다.

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 
관련 문제