Browse All Articles > Sending and receiving XML or HTML data, communicating with web services using VB6
I’ve seen a number of people looking for examples of how to access web services from VB6. I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web services on my own network, so I thought I’d share this with a few examples as starting points. This is not intended to be a fully working model for communicating with any given web service, but simply a foundation for you to do your own testing within VB6 to communicate with servers that provide web service functionality. There are three starting examples included based on questions I found here on EE:
- Dial a Cisco phone (This is the only example that fully works.)
- Twitter oAuth token request
- eBay service comm
The core of this test harness is the “Microsoft WinHTTP Services” Reference. The main form (frmPostGet), shown below, has the key components in the UI for communicating with a web service:
- …and Results returned from the web service.
The way to use this test harness is to populate the URL, Headers, and Data with service-specific strings, then Send the data and review the results in the “Results” area. Once you have a working process, you can begin to code your own client. The working examples combo box will help fill in some of this information for the included examples.
The [Send] button is where the action takes place. See the attached project for the specific code. It has this sequence of steps:
Depending on the web service, you will look in the Results field to find what defines success or failure. In the example shown in the screenshot above, the Cisco phone responded with XML data with one of the elements showing the text “Success” (plus I saw the phone actually dial!)
There are two modules in addition to the main form (basBase64Utils and basURLHelper) that are not essential to the WinHTTP services, but are used to simply aid in the use of the test harness.
basBase64Utils - Web services usually require the authentication user/password to be encoded in Base64 format, so these routines do this coding/decoding. There is also a routine to get a complete file as a Base64 string, for instance to upload to a web service or include as an email attachment. Most of this module is from the author at http://www.nonhostile.com/howto-encode-decode-base64-vb6.asp.
This test harness works with XML and HTML data, since it is using the generic WinHTTP Services to communicate with the web services server. It is up to you to parse the results depending on your specific needs, but there are many tools available online to make this easier.