10.6. Accessing Data for the Web Service

A production version of the ZipService would probably use a database like SQL Server or Oracle to provide data for the service. To keep the example self-contained, an XML file (shown in Example 10-7) containing zip code information is used. The file contains only partial data for two cities, but can easily be extended if desired.

Example 10-7. Partial zip code data for Houston and Austin
<?xml version="1.0" ?>
    <city name="Houston">
    <city name="Austin">

10.6.1. Typed DataSet

The implementation does not use the XML directly. Instead, a typed DataSet is created to handle data access. A DataSet provides a consistent relational programming model that is independent of a data source. This means that, once a DataSet is populated, where the data came from is irrelevant. By coding against a DataSet, the data source can be changed at a later time without negatively impacting the web service

The XML Schema Definition Tool that ships with the .NET Framework SDK (xsd.exe) does most of the work. This tool can generate an XSD schema that describes the XML in Example 10-7. In turn, that schema can build a derived DataSet class that allows the XML to be manipulated programmatically.

Building a DataSet with this tool is a three-phase process. The ...

Get Object-Oriented Programming with Visual Basic .NET now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.