Use Web Services

From an Excel perspective, web services are primarily useful for retrieving variable data over the Internet, but you can also use them to send data, to manipulate remote data, or to run other code on remote computers. Web services are designed to work just like procedure calls from code, so it is possible to use a web service without even knowing that it is running remote code.

That’s possible, but it’s not likely since web service methods often rely heavily on their underlying foundation: XML. That means Excel programmers must become familiar with the Microsoft XML type library before they can effectively use web services. The good news is that once you’re comfortable working with XML, you can blast web service results directly into spreadsheet lists using Excel XML maps (which is very cool).

Queries versus services

Web queries are great for the ad hoc import of data onto a worksheet, but they rely on the position of elements on the page. If the structure of the source web page changes, the query may break. This means that web queries aren’t well-suited for deployed solutions because you are likely to get a great number of support calls if the source web page changes or moves.

Also, you’ve got to compose complicated site-specific Connection properties (query strings) if you want to perform customized queries. Each web site has its own system of sending and receiving data through query strings, and it can be difficult to reverse-engineer those query strings correctly.

Note

Web services do not have these limitations and generally provide a better interface for getting data from the Web. However, web services are not available for all data on the Internet so there are many, many cases where web queries are still very useful.

How it works

When Excel calls a web service, it sends a request across the Internet to the address of the web service and then waits for a response. The request is usually packaged as XML; the response is XML.

Web services, like many Internet-related things, are part of evolving standards. These standards have broad support by many companies, so web services are not likely to lose support in the future. However, since the standards are still evolving, there are different approaches to implementing, locating, and accessing web services. Of specific interest to Excel developers are the facts that:

  • There are several ways to locate web services on the Internet. One way is through a directory service such as http:// uddi.microsoft.com , but a much more common way is just by browsing the business’s own site or through a cross-listing site such as http:// www.xmethods.net/ .

  • There are several ways to describe web services over the Internet. With Excel, you only really need to worry about one: WSDL.

  • There are several ways to call web services. Some web services only support SOAP, while others, such as Amazon, also support access directly through their URLs.

The samples in this chapter focus on two widely used web services provided by Google and Amazon.com respectively. These services are nearly ideal for a chapter such as this because they are freely available, useful, well-documented, and demonstrate both SOAP and URL access.

Where to get it

Before you continue, however, you should download the following toolkits:

ToolkitLocation

Microsoft Office Web Services Toolkit

Search http:// www.microsoft.com/downloads for “Web Services Toolkit”

Google web Service

http:// www.google.com/apis/

Amazon web Service

Click on Web Services link at http:// www.amazon.com

Both of the preceding web services require you to register to get a developer ID to pass with method calls. I provide my developer ID with the code samples shown here, but you will want your own ID if you use these web services in your own code.

Get Excel 2003 Programming: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.