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" ?>
<cities>
    <city name="Houston">
        <zip>77002</zip>
        <zip>77003</zip>
        <zip>77004</zip>
        <zip>77005</zip>
        <zip>77006</zip>
    </city>
    <city name="Austin">
      <zip>78742</zip>
      <zip>78744</zip>
      <zip>78746</zip>
      <zip>78748</zip>
      <zip>78750</zip>
    </city>
</cities>

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 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.