views:

31

answers:

2

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  A: 

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
DMKing
Eeew, I was hoping there would be some sort of built-in SOAP library... I'll test this tomorrow and see if I can get it to work.
Nate Thorn
Like I said it is "a way" maybe not the best but it does work. Mr. Saunders answer is probably a better way to go. Good luck. :)
DMKing
A: 

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.

John Saunders