The simplest service consists of a single feed hosting a basic Entity-Attribute-Value model tuple represented in Atom or JSON. Typically a service will provide a number of feeds, listed in the top-level service document. The model is published at the top level as a service-specific metadata document.
The Open Data Protocol (OData) is a protocol for sharing data. Producers expose data as an OData service at an HTTP location (i.e., a URL) which is then available to OData consumers. As the OData protocol is based on the AtomPub standard, the simplest consumer can take the form of any HTTP user agent (e.g., a Web Browser), which is then able to browse entity-attribute-value model data stored within the Atom feeds. Likewise, Rich Internet Application clients, launched from within browsers or as stand-alone applications, such as the Silverlight OData Explorer, may be used to browse this data. Either way, data from a range of disparate sources can be exposed as HTTP-accessible structured hypermedia resources (delivered by the Atom Feed).
By cleanly separating client and server roles, OData can serve as an HTTP analog of the platform-specific ODBC (version 2.0, as of this writing). As with ODBC, data consuming applications can be developed independently from data sources, and a single application can consume data from a range of disparate sources. The OData service endpoint can be specified at runtime just as an ODBC Data Source Name (DSN) would be.
Virtuoso is a hybrid data server with native data management and integration capabilities covering RDF via SPARQL, ODBC or JDBC accessible Relational Data Sources; XML via XQuery/XPath; Web Services; and other HTTP-accessible Hypermedia and non-Hypermedia resources. Virtuoso includes a high-performance native ADO.NET data provider that provides access to its Relational-, RDF Graph-, and Document-model based storage engines, and thereby also makes data from these engines accessible to OData-based data consumers.
There are two ways to produce OData from Virtuoso: one approach uses Virtuoso's built-in support of the lightweight and platform-agnostic OData protocol; the other uses Virtuoso's ADO.NET provider. This guide covers use of the ADO.NET provider.
To create an OData service endpoint using Virtuoso and its ADO.NET provider, you will need the following in place:
At the start of your Visual Studio project creation, you must establish a connection with the database(s) hosting the data to be exposed by the service. Once a connection has been established, you can generate a data model which lays the foundation for publishing an OData service.
The following steps show how to expose the Northwind Demo database in Virtuoso as an OData Service using the Virtuoso ADO.NET Provider:
ODataWebApplication
, and click OK.
DemoModel.edmx
, and click Add to start the creation of the ADO.NET Entity Data Model.
VirtuosoDemoEntities
(remember the name you set here, as it is required in step 20 below) and click Next.
VirtuosoOData.svc
, and click Add to create the OData Service.
VirtuosoOData.svc.cs
Data Service file created by the steps above, add the data source class name of VirtuosoDemoEntities
(note: this is the name set in step 15, above) as the DataService name, and enable access to the Data Service by adding the entry config.SetEntitySetAccessRule("*", EntitySetRights.All);
in the InitializeService method.
public static void InitializeService(DataServiceConfiguration config) { // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc. // Examples: // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead); // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All); config.SetEntitySetAccessRule("*", EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; }
Ctrl+F5
within Visual Studio, which will start the development web server, run the OData Services server therein, and load a Web browser page displaying the list of available tables/entities of the Demo database.
The simplest way to consume the service is to use a web browser to browse the Atom feed.
This is what is done when testing the service in Visual Studio.
As well as the top-level list of feeds provided by the service, it is straightforward to access a specific entity instance.
For example, to access the ALFKI
record of the Customers
table, simply append /Customers('ALFKI')
to the service root URI.
Similarly, the metatdata document can examined by appending /$metadata
to the service instance URI.
The metadata document is useful for finding information about the entities provided on the service.
Alternatively, the service can be consumed by a more sophisticated application like the Silverlight OData Explorer.
The Silverlight OData Explorer also allows you to update data via the service. For example:
Customers
entities.
config.UseVerboseErrors = true;
to the virtuoso.svc.cs
InitializeService method to obtain more detailed information from the server as to why the page failed to load:
public static void InitializeService(IDataServiceConfiguration config) { config.UseVerboseErrors = true; config.SetEntitySetAccessRule("*", EntitySetRights.All); }