Making a SOAP request from Access 2007

扶醉桌前 提交于 2021-02-19 04:44:26

问题


I am currently working on a system in Microsoft Access 2007, and I need to make a SOAP request to an outside webserver in order to retrieve some data. I'm new to both SOAP and Visual Basic, and I've been having trouble figuring out exactly what I need to do to make this SOAP request happen.

From some Googling about, it seems that previous versions of Access may have needed Microsoft's SOAP Toolkit in order to make a SOAP request. So far as I can tell, however, the SOAP Toolkit was deprecated several years ago, so I'm pretty sure that's not what I want. Do I need to download an outside library to make a SOAP call? If so, which? If not, what is the VB syntax used for making a SOAP call from an Access 2007 file?


回答1:


I don't know if there is a better way than doing it through VBA using a low-level Http POST to pass the SOAP message to the server. You will have to craft the XML SOAP message by whatever method you choose. Here is a sample function to do an Http POST in VBA.

Function doHttpPost(request As String) As String

    Dim response As String
    Dim http As WinHttp.WinHttpRequest
    Set http = New WinHttp.WinHttpRequest

    On Error GoTo doPostError

    http.setTimeouts 30000, 30000, 30000, 300000

    http.Open "POST", "http://someserver.com/soapListener", False
    http.setRequestHeader "name", "value" 'set any headers you want'

    http.send request

    If http.Status <> 200 Then
        MsgBox "An error has occurred with your request. " & vbCrLf & "The error message is: " & http.responseText & vbCrLf & http.Status & " " & http.statusText
        Exit Function
    End If

    doHttpPost = http.responseText
    Exit Function

doPostError:
    'process error messages here'

End Function



回答2:


You should use your favorite .NET language to create a COM component that Access can call. That component should use standard .NET mechanisms ("Add Service Reference") to make calls to the web service.

Under no circumstances should you use the SOAP Toolkit, which is very obsolete.



来源:https://stackoverflow.com/questions/3764123/making-a-soap-request-from-access-2007

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!