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:
- URL
- Headers
- Data
- …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:
Add headers one row at a time. Each row is separated by CR-LF, then each header name-value pair is separated by a colon. I used an array and the Split() function to easily handle these separations.
arrHeaders = Split(Headers_String, vbCrLf)For i = 0 To UBound(arrHeaders) HttpReq.SetRequestHeader Split(arrHeaders(i), ":")(0), Split(arrHeaders(i), ":")(1)Next i
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.
Thank you XiMaker. I see I uploaded the wrong file entirely. That was part of a different test project. I will upload the correct one now.
The SendFax example referenced in that (incorrectly uploaded) project is part of another project where I am using a MultiTech fax server for incoming and outgoing faxes on the network. It's only relevant if someone had a MultiTech Fax server.
Again, thanks for pointing this out, and if you have a chance, please take a look at the corrected VB6 project that will be uploaded as "TestWebService_r1.zip" and let me know if you have any feedback.
Comments (3)
Commented:
Author
Commented:The SendFax example referenced in that (incorrectly uploaded) project is part of another project where I am using a MultiTech fax server for incoming and outgoing faxes on the network. It's only relevant if someone had a MultiTech Fax server.
Again, thanks for pointing this out, and if you have a chance, please take a look at the corrected VB6 project that will be uploaded as "TestWebService_r1.zip" and let me know if you have any feedback.
Author
Commented: