Skip to Content
Programming WCF Services, 2nd Edition
book

Programming WCF Services, 2nd Edition

by Juval Lowy
November 2008
Intermediate to advanced
784 pages
23h 28m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services, 2nd Edition

Data Sets and Tables

One of the most common types of data contract exchanged between clients and services involves data that originates in or is destined for a database. In .NET, a common way of interacting with databases is via ADO.NET's data set and data table types. Applications can use the raw DataSet and DataTable types, or use the data access management tools in Visual Studio 2008 to generate type-safe derivatives.

The raw DataSet and DataTable types are serializable (i.e., marked with the Serializable attribute):

[Serializable]
public class DataSet : ...
{...}

[Serializable]
public class DataTable : ...
{...}

This means that you can define valid service contracts that accept or return data tables or data sets:

[DataContract]
struct Contact
{...}

[ServiceContract]
interface IContactManager
{
   [OperationContract]
   void AddContact(Contact contact);

   [OperationContract]
   void AddContacts(DataTable contacts);

   [OperationContract]
   DataTable GetContacts(  );
}

You can also use the type-safe subclasses of DataSet and DataTable in your contracts. For example, suppose in your database you have a table called Contacts that contains your contacts, with columns such as FirstName and LastName. You can use Visual Studio 2008 to generate a type-safe data set called MyDataSet that has a nested class called ContactsDataTable, as well as a type-safe row and type-safe data adapter, as shown in Example 3-10.

Example 3-10. Type-safe data set and data table

[Serializable] public partial class MyDataSet : DataSet ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming WCF Services

Programming WCF Services

Juval Lowy

Publisher Resources

ISBN: 9780596157210Supplemental ContentErrata