Accessing More Complex Web Services

While one return value for a method or function is a fairly normal approach in programming languages, SOAP is capable of returning values that are more complex. To demonstrate, the next example will test a service that returns information about a given US Zip Code, including the city, state, area code, and time zone.

Information about the service, including an HTML testing form that lets you see what results the service will produce, is available at http://webservicex.net/uszip.asmx?op=GetInfoByZIP. Its WSDL file is at http://webservicex.net/uszip.asmx?WSDL. If you test it with the Zip Code 13053, it will report back:

<?xml version="1.0" encoding="utf-8" ?> 
<NewDataSet>
 <Table>
  <CITY>Dryden</CITY> 
  <STATE>NY</STATE> 
  <ZIP>13053</ZIP> 
  <AREA_CODE>607</AREA_CODE> 
  <TIME_ZONE>E</TIME_ZONE> 
 </Table>
</NewDataSet>

The test reports back without a SOAP envelope. As the Web Services Toolkit will handle all the processing of the SOAP envelope and just hands your code the message inside, that won’t be a problem for you. The Table here (and the <any /> in the schema in the WSDL file where these would appear) will lead the Web Services Toolkit to generate code that returns an IXMLDOMNodeList, as shown in Figure 9-9.

Generated code returning XML rather than a value

Figure 9-9. Generated code returning XML rather than a value

To work with this more complex data, the spreadsheet will have one source cell (for the Zip ...

Get Office 2003 XML 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.