This documentation is archived and is not being maintained.

DataSetConsumer Sample (Consumes Multiple Table Datasets) 

Visual Studio 2005

Download sample

This sample demonstrates how to consume multiple table datasets from an unmanaged Visual C++ client using an XML Web service proxy.

The DataSetConsumer sample illustrates how to consume multiple table datasets from an unmanaged Visual C++ application. DataSetConsumer is an ATL Server application that consumes a multiple table dataset exposed through an XML Web service created using ASP.NET.

DataSetConsumer also shows how to use Web references to support the consumption of multiple table datasets. Web references convert single table datasets into C++ structures, but treat multiple table datasets as XML streams. Therefore, the corresponding XML Web services method in the proxy class returns the full XML serialization of the dataset as string data. It must then be parsed to be useful in most applications.

The DataSetConsumer application accesses multiple tables in a dataset, while the walkthrough accesses a single table.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.


  • IIS must be installed and running.

  • At least one SQL Server database must be installed.

Building and Running the Sample

To use this sample, follow the steps in this section. You will create an XML Web service project WebService1 that defines a Web services method to access data from a dataset. You then add a Web reference, which creates a proxy class for the XML Web service. DataSetConsumer uses an instance of this proxy to call the XML Web services method in WebService1. WebService1 returns the dataset as type BSTR, and DataSetConsumer loads it as XML, using the DOM and the MSXML parser to parse the string and print the data as HTML.

To open the sample file in Solution Explorer

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory that the files will be extracted to, and then click Next again.

    Make sure that the Show extracted files check box is selected, and click Finish.

  4. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.

To create an ASP.NET Web service project to access a dataset

  1. Create a new XML Web service using ASP.NET.

    From the File menu, click New, then Project. The New Project dialog box appears. In the Visual J# Projects folder, select ASP.NET Web Service. Name the project WebService1. The location should be the default (http://localhost/WebService1).

    Click OK. When the project has been created, you will see Service1.asmx.jsl in the Design pane.

  2. Create a data connection.

    In Server Explorer, right-click Data Connection and click Add Connection. The Data Link Properties dialog box appears. Fill in the details to create a data connection to a database, for example, the Northwind database. Select the Allow Saving Password checkbox.

  3. Add tables and data adapters.

    Open the Tables node of your new data connection and drag two tables from Server Explorer to the Design pane. Two DataAdapters and one data connection will appear in the Design pane.

  4. Generate a dataset.

    From the Data menu, click Generate Dataset. In the Generate Dataset dialog box, choose a New Dataset named DataSet1 (the default), and choose to add both tables to the dataset. Also select the Add this dataset to the designer box (optional but recommended). Click OK to create the dataset (named dataSet11 by default).

  5. Implement a Web services method.

    From the View menu, click Code. The code for Service1.asmx.jsl appears in the Edit pane. Scroll to the bottom of the file to the HelloWorld example Web services method:

    // /** @attribute WebMethod() */
    //    public System.String HelloWorld()
    //    {
    //        return "Hello World";
    //    }

    In place of the HelloWorld example code, implement a new Web services method named GetDataSet as follows:

        /** @attribute WebMethod() */
        public DataSet1 GetDataSet()
            this.sqlDataAdapter1.Fill (this.dataSet11);
            return dataSet11;

    This code assumes that you use a SQL Server database.

  6. Build the WebService1 project. From the Build menu, click Build Solution.

To consume data from DataSetConsumer

  1. Open the DataSetConsumer project.

  2. Open the solution file, DataSetConsumer.sln, in the Visual Studio development environment.

  3. Make sure that DataSetConsumer.h contains this line:

    #include "WebService.h"
  4. Add a Web reference to the project.

    Adding a Web reference will generate a proxy class for the XML Web service. An XML Web service client can call a method on the proxy, which in turn does the necessary work to remotely invoke the call over the network to call the corresponding XML Web services method. By default, the proxy class uses SOAP to access the corresponding method. SOAP supports the richest set of data types of the three supported protocols (SOAP, HTTP-GET, and HTTP-POST). Adding a Web reference can generate proxy classes for the latter two protocols as well. In Solution Explorer, right-click the DataSetConsumer project node and select Add Web Reference from the shortcut menu.

    The Add Web Reference dialog box appears.

  5. In the Address bar, type the URL for WebService1 as follows and press ENTER.


    The Web service description is an XML document written in an XML grammar called Web Service Description Language (WSDL) that defines the format of messages for the XML Web service.

  6. Click Add Reference. This adds the proxy class Service1 to the DataSetConsumer project. The header file WebService.h appears in Solution Explorer.


    In the header file generated for your web service, the CService1T constructor is hard-coded to use the URL specified when you added the Web reference. If you want to use DataSetConsumer with another XML Web service, change the URL to match the location of that XML Web service .asmx file.

  7. From the Build menu, click Build Solution to build the DataSetConsumer project.

  8. To run the client application, from the Debug menu, click Start Without Debugging.

    You are prompted for a URL.

  9. Enter the following:

  10. Click OK.

    The Web browser appears, displaying the data accessed through the XML Web service.

Classes, Technologies, and Concepts in the Sample

See Also