|
4.5. Use Web ServicesFrom 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). 4.5.1. Queries versus servicesWeb 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. 4.5.2. How it worksWhen 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:
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. 4.5.3. Where to get itBefore you continue, however, you should download the following toolkits:
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. |
|