15

I need to consume an external web service from my VB6 program. I want to be able to deploy my program without the SOAP toolkit, if possible, but that's not a requirement. I do not have the web service source and I didn't create it. It is a vendor-provided service.

So outside of the SOAP toolkit, what is the best way to consume a web service from VB6?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Robert S.
  • 25,266
  • 14
  • 84
  • 116

6 Answers6

11

I use this function to get data from a web service.

Private Function HttpGetRequest(url As String) As DOMDocument
    Dim req As XMLHTTP60
    Set req = New XMLHTTP60
    req.Open "GET", url, False
    req.send ""

    Dim resp As DOMDocument
    If req.responseText <> vbNullString Then
        Set resp = New DOMDocument60
        resp.loadXML req.responseText
    Else
        Set resp = req.responseXML
    End If
    Set HttpGetRequest = resp
End Function
genesis
  • 50,477
  • 20
  • 96
  • 125
Darrel Miller
  • 139,164
  • 32
  • 194
  • 243
  • Not terribly useful unless the web service uses HTTP. – John Saunders Nov 28 '12 at 01:38
  • 3
    @JohnSaunders Sure, feel free to use a different approach for those parts of the web that don't use HTTP. – Darrel Miller Nov 28 '12 at 02:49
  • 1
    Perhaps you don't call something a web service if it uses binary over TCP/IP, but not HTTP? If that's the case, then I agree with you. I don't think that using SMTP or TCP/IP as a transport keeps a service from being a "web service", though I would agree that it's not an "Internet service". – John Saunders Nov 28 '12 at 03:19
  • I also just realized that the "data" you get back from the service is just XML. That won't help you much if the data are encrypted, or include attachments. Your example does no SOAP processing at all, leaving that all up to the caller. I do recognize that if you had wanted to, you could have used "POST" in your example. OTOH, your example works very well for REST services. – John Saunders Nov 28 '12 at 03:24
  • Hi, am new to VB 6. For the above piece of code do we need to add any reference or component? Please advice. – Rajdeep Mar 06 '13 at 13:24
4

.NET has a good support for Web Services since day one, so you can develop your Web Service client logic in .NET as a .dll library/assembly and use it in VB6 app via COM Interop.

huseyint
  • 14,953
  • 15
  • 56
  • 78
3

Assuming that you're running on Windows XP Professional or above, one interesting method is to use the SOAP moniker. Here's an example, lifted from some MSDN page. I don't know if this particular service works, but you get the idea...

   set SoapObj = GetObject
       ("soap:wsdl=http://www.xmethods.net/sd/TemperatureService.wsdl")
   WScript.Echo "Fairbanks Temperature = " & SoapObj.getTemp("99707")

This mechanism also works from VBScript. Which is nice.

Martin
  • 5,392
  • 30
  • 39
2

Pocketsoap works very well. To generate your objects use the WSDL generator. Using this you don't have to parse anything yourself, plus everything is nice and strongly typed.

Kris Erickson
  • 33,454
  • 26
  • 120
  • 175
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Jimbo Jun 19 '14 at 10:39
  • @Jimbo, if you note when this was posted (3 years before you joined StackOverflow) the etiquite regarding links and posts had not been formalized yet. That said there is no other part of the answer, the suggestion was to use the PocketSoap library. But, as 6 years has passed since posting this I would heavily argue that PocketSoap is no longer the best solution and to use @ hyseyint's answer to use .Net with Interop is the best solution unless you can't use Interop. – Kris Erickson Jun 20 '14 at 15:43
  • Hi Kris, I didn't actually type that above. On 'REVIEW' in the top right, this came up and one of the options was 'Link-only answer', which I stand by. The text above is auto-posted when reviewing other's posts, try it :-) – Jimbo Jun 20 '14 at 15:48
1

I've had some measure of success so far using PocketSOAP to connect to the Salesforce API. I could not use the WSDL Wizard because it generates wrapper class filenames using the first 23 characters of the call names, and this results in duplicates. Nevertheless, PocketSOAP has been working well enough for me without the wizard, and it's much more straightforward than using XMLHTTP with DOMDocument.

I also looked into making a wrapper in .NET or using one of the "MS Office {MSO version} Web Services Toolkit" libraries, but there were significant deployment hassles with those options. PocketSOAP is a simple COM DLL, not dependent on some particular version of MS Office, and is licensed under MPL.

0

The SOAP toolkit is arguably the best you could get. Trying to do the same thing without it would require considerable extra effort. You need to have quite serious reasons to do that.

The format of the SOAP messages is not really easy to read or write manually and a third-party library is highly advised.

Ilya Kochetov
  • 17,988
  • 6
  • 44
  • 60