Share via


WCF Data Services Overview

WCF Data Services enables creation and consumption of data services for the Web or an intranet by using the Open Data Protocol (OData). OData enables you to expose your data as resources that are addressable by URIs. This enables you to access and change data by using the semantics of representational state transfer (REST), specifically the standard HTTP verbs of GET, PUT, POST, and DELETE. This topic provides an overview of both the patterns and practices defined by OData and also the facilities provided by WCF Data Services to take advantage of OData in .NET Framework-based applications.

Address Data as Resources

OData exposes data as resources that are addressable by URIs. The resource paths are constructed based on the entity-relationship conventions of the Entity Data Model. In this model, entities represent operational units of data in an application domain, such as customers, orders, items, and products. For more information, see Entity Data Model.

In OData, you address entity resources as an entity set that contains instances of entity types. For example, the URI http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/Orders returns all of the orders from the Northwind data service that are related to the customer with a CustomerID value of ALFKI.

Query expressions enable you to perform traditional query operations against resources, such as filtering, sorting, and paging. For example, the URI http://services.odata.org/Northwind/Northwind.svc/Customers('ALFKI')/Orders?$filter=Freight gt 50 filters the resources to return only the orders with a freight cost of more than $50. For more information, see Accessing an OData Service (WCF Data Services).

Interoperable Data Access

OData builds on standard Internet protocols to make data services interoperable with applications that do not use the .NET Framework. Because you can use standard URIs to address data, your application can access and change data by using the semantics of representational state transfer (REST), specifically the standard HTTP verbs of GET, PUT, POST, and DELETE. This enables you to access these services from any client that can parse and access data that is transmitted over standard HTTP protocols. 

OData defines a set of extensions to the Atom Publishing Protocol (AtomPub). It supports HTTP requests and responses in more than one data format to accommodate various client applications and platforms. An OData feed can represent data in Atom, JavaScript Object Notation (JSON), and as plain XML. While Atom is the default format, the format of the feed is specified in the header of the HTTP request. For more information, see OData: Atom Format and OData: JSON Format.

When publishing data as an OData feed, WCF Data Services relies on other existing Internet facilities for such operations as caching and authentication. To accomplish this, WCF Data Services integrates with existing hosting applications and services, such as ASP.NET, Windows Communication Foundation (WCF), and Internet Information Services (IIS).  Serializing and deserializing of OData messages is performed by the OData Library. If your Web-based application or service already provides HTTP messaging facilities, consider using the OData Library directly to simply serialize and deserialize OData-compliant messages. For more information, see OData Library.

Storage Independence

Although resources are addressed based on an entity-relationship model, WCF Data Services expose OData feeds regardless of the underlying data source. After WCF Data Services accepts an HTTP request for a resource that a URI identifies, the request is deserialized and a representation of that request is passed to an WCF Data Services provider. This provider translates the request into a data source-specific format and executes the request on the underlying data source. WCF Data Services achieves storage independence by separating the conceptual model that addresses resources prescribed by OData from the specific schema of the underlying data source.

WCF Data Services integrates with the ADO.NET Entity Framework to enable you to create data services that expose relational data. You can use the Entity Data Model tools to create a data model that contains addressable resources as entities and at the same time define the mapping between this model and the tables in the underlying database. For more information, see Entity Framework Provider (WCF Data Services)

WCF Data Services also enables you to create data services that expose any data structures that return an implementation of the IQueryable<T> interface. This enables you to create data services that expose data from .NET Framework types. Create, update, and delete operations are supported when you also implement the IUpdatable interface. For more information, see Reflection Provider (WCF Data Services). By implementing a set of custom data service provider interfaces, you can use WCF Data Services to publish data from any source, even when the data model is only known at runtime. For more information, see Custom Data Service Providers (WCF Data Services).

For an illustration of how WCF Data Services integrates with these data providers, see the architectural diagram later in this topic.

Custom Business Logic

WCF Data Services makes it easy to add custom business logic to a data service through service operations and interceptors. Service operations are methods defined on the server that are addressable by URIs in the same form as data resources. Service operations can also use query expression syntax to filter, order, and page data returned by an operation. For example, the URI https://localhost:12345/Northwind.svc/GetOrdersByCity?city='London'&$orderby=OrderDate&$top=10&$skip=10 represents a call to a service operation named GetOrdersByCity on the Northwind data service that returns orders for customers from London, with paged results sorted by OrderDate. For more information, see Service Operations (WCF Data Services).

Service actions are a special kind of operation that can be bound to data service resources and have an effect on the system. For more information, see Using OData Actions to implement server-side behavior.

Interceptors enable custom application logic to be integrated in the processing of request or response messages by a data service. Interceptors are called when a query, insert, update, or delete action occurs on the specified entity set. An interceptor then may alter the data, enforce authorization policy, or even terminate the operation. Interceptor methods must be explicitly registered for a given entity set that is exposed by a data service. For more information, see Interceptors (WCF Data Services).

Client Libraries

OData defines a set of uniform patterns for interacting with data services. This provides an opportunity to create reusable components that are based on these services, such as client-side libraries that make it easier to consume data services.

WCF Data Services includes client libraries for both .NET Framework-based and Silverlight-based client applications. These client libraries enable you to interact with data services by using .NET Framework objects. They also support object-based queries and LINQ queries, loading related objects, change tracking, and identity resolution. For more information, see Data Client (WCF Data Services).

In addition to the OData client libraries included with the .NET Framework and with Silverlight, there are other client libraries that enable you to consume an OData feed in client applications, such as PHP, Java, and iOS applications.  Javascript application developers may be interested in the datajs library for consuming OData.

Architecture Overview

The following diagram illustrates the WCF Data Services architecture for exposing OData feeds and using these feeds in OData-enabled client libraries:

WCF Data Services architecture diagram

See Also

Other Resources

WCF Data Services

Getting Started with WCF Data Services

Data Service (WCF Data Services)

Accessing a Data Service (WCF Data Services)

Data Client (WCF Data Services)

Representational State Transfer (REST)