How to call web services with REST instead of SOAP
The VB/VBA tools and samples from Microsoft demonstrate calling web services through SOAP interfaces. For example, the Office Web Services Toolkit generates proxy classes for web services using SOAP. You then use those proxy classes in your local VBA code to call the remote web service.
That works fine as long as you don't try to modify the proxy classes to, say...call the web service asynchonously. Modifying generated code is often more difficult than writing (and thus understanding) the code yourself.
The Web Services Toolkit also generates proxy classes for every item described by the web service's WSDL -- in the case of the Amazon web service that's dozens of classes. It's hard to figure out which ones you need and cumbersome to use this overly object-oriented approach.
Good news! Some web services, like Amazon, provide an alternate, string-based interface. This interface looks like query strings (heck, that's what it is really) but it also has a formal name: REST.
To see how it works, click on the following web address:
OK, you got a bunch of XML about wombats. That's useful from a programming perspective because the interface is so much simpler than using the Web Services Toolkit and SOAP.
That code just displays the results in the Immediate window, but you can just as easily display those results in a document through an XML Map you set up previously. For instance:
Voila! You've gotten your results in six lines or less.
The other advantage of this interface is that it's easy to use asynchronously. If you set the DOMDocument object's Async property to True, you can then hook into the ondataavailable event as seen here:
So why doesn't Microsoft show REST examples? I don't know, but you should be aware that not all web services have REST interfaces. Google doesn't, and that's a complaint among some web programmers. On the other hand, SQL Server's XML support through IIS looks like REST. So you decide.
Jeff Webb is a SharePoint consultant and trainer who has written about computers and technology for 20 years. Among his published O'Reilly titles are Essential SharePoint, SharePoint Office Pocket Guide, Programming Excel with VBA and .NET, and Excel 2003 Programming: A Developer's Notebook. Jeff was an original member of Microsoft's Visual Basic team.
Comments on this weblog
1 to 2 of 2
1 to 2 of 2
Return to weblogs.oreilly.com.