www.openlinksw.com
docs.openlinksw.com

Book Home

Contents
Preface

Installation Guide

Virtuoso on All platforms Commmon Specifics
Virtuoso for Windows
Virtuoso for Linux (Enterprise Edition)
Virtuoso for Unix (Enterprise Edition)
Virtuoso for Unix (Personal Edition)
Virtuoso for Mac OS X
OpenLink License Management
Virtuoso ADO.Net Data Grid Form Application
Using Visual Studio 2008 to Build an Entity Frameworks based Windows Form Application
Using Visual Studio 2008 to Build an ADO.NET Data Services based Application
Introduction Getting Started: Creating Data Services Creating a Data Service using the ADO.NET Entity Framework
Windows Form Application for accessing Virtuoso RDF data via SPASQL using the Virtuoso ADO.Net Provider
Creating a Web Browser Application to Access RDF Data Using The Virtuoso ADO.Net Provider
Creating a Silverlight Application to consume the service
Creating A Simple .NET RIA Services Application To Display Data From Virtuoso
Creating a .Net RIA Services Application That Will Update Virtuoso Data
Cluster Installation and Config

2.10. Using Visual Studio 2008 to Build an ADO.NET Data Services based Application

Using Microsoft ADO.Net Data Services with Virtuoso

2.10.1. Introduction

The goal of Microsoft ADO.NET Data Services is to enable applications to expose data as a data service that can be consumed by web clients within corporate networks and across the internet. A data service is reachable via regular HTTP requests, using standard HTTP verbs such as GET, POST, PUT and DELETE to perform CRUD operations against the service. The payload format used by the service is controllable by the application, but all options are simple, open formats such as JSON and Atom/APP.

The use of web-friendly technologies make ADO.NET Data Services ideal as a data back-end for AJAX-style applications, Rich Interactive Applications and other applications that need to operate against data that is stored across the web.


2.10.2. Getting Started: Creating Data Services

Pre-requisites

In order to create a data service using ADO.NET Data Services in your own environment you will need Microsoft Visual Studio 2008 SP1. The ADO.NET Entity Framework runtime and associated tools are included in Visual Studio 2008 SP1.

Selecting a Data Source

The ADO.NET Data Service server framework is comprised of two halves. The top-half is the runtime itself; this part is "fixed", and it implements URI translation, the Atom/JSON wire formats, the interaction protocol, etc. This is what makes an ADO.NET Data Service look like an ADO.NET Data Service. The bottom half is the data-access layer and is pluggable. Communication between layers happens in terms of the IQueryable interface plus a set of conventions to map CLR graphs into the URI/payload patterns of ADO.NET Data Services.

The first step in creating an ADO.NET Data Service is to determine the data source that is to be exposed as a set of REST-based endpoints (ie. select or create a data access layer). For relational data stored in Microsoft SQL Server or other 3rd Party databases, ADO.NET Data Services currently enables easily exposing a conceptual model created using the ADO.NET Entity Framework (EF). For all other data sources (XML section, web service, application logic layer, etc) or to use additional database access technologies (ex. LINQ to SQL), a mechanism is provided which enables any data source, as per the plug-in model described above, to be exposed as an ADO.NET Data Service.

To create a data service which exposes a relational database through an Entity Framework conceptual model see "Creating a Data Service using the ADO.NET Entity Framework". To create a data service which exposes another data source see "Creating a Data Service from any Data Source".


2.10.3. Creating a Data Service using the ADO.NET Entity Framework

ADO.NET Data Services are a specialized form of Windows Communication Foundation services, and thus can be hosted in various environments. The below example will create an ADO.NET Data Service which is hosted inside an ASP.NET site. In order to create a data service, you must first create a web project; you will then need to establish a connection with the database that will be exposed by the service, and then create the data service itself within the web application. Below is a step-by-step description of this process.

The following steps can be used for creating a Data Service using the Virtuoso ADO.Net Provider for accessing the sample Northwind Demo database:

  1. Launch the Visual Studio 2008 SP1 IDE.
    Visual Studio 2008 SP1 IDE.
    Figure: 2.10.3.1. Visual Studio 2008 SP1 IDE.
  2. Create a Web Application project by going to the File menu in Visual Studio and choosing New Project.
  3. When the New Project window appears, choose either Visual Basic or Visual C# as the programming language.
  4. Within the language category click on Web, and select ASP.NET Web Application from the right-hand panel.
  5. Choose a name for the project, for example VirtuosoDataService, and click OK.
    Name project
    Figure: 2.10.3.1. Name project
  6. This will create a new project called VirtuosoDataService.
    Create project
    Figure: 2.10.3.1. Create project
  7. Right click on the VirtuosoDataService project name of the Solution Explorer pane, then select the Add -> New Item menu options.
    New Item
    Figure: 2.10.3.1. New Item
  8. The Add New Item dialog will appear, choose the ADO.NET Entity Data Model template, give it the name Virtuoso.edmx and click Add to start the creation of the ADO.Net Entity Data Model.
    Entity Model
    Figure: 2.10.3.1. Entity Model
  9. In the Entity Data Model Wizard dialog Choose Model Contents page select the Generate from Database model type and click Next.
    Model Contents
    Figure: 2.10.3.1. Model Contents
  10. In the Entity Data Model Wizard dialog Choose your Data Connection page select the New Connection button
    Data Connection
    Figure: 2.10.3.1. Data Connection
  11. In the Choose Data Source dialog, select the OpenLink Virtuoso Data Source from the list displayed and click Continue.
    Data Source
    Figure: 2.10.3.1. Data Source
  12. In the Add Connection dialog, specify the hostname, portno, username and password for the target Virtuoso Server and check the Save Password check box.
    Connection Properties
    Figure: 2.10.3.1. Connection Properties
  13. Select the Select Database From List radio button and choose Demo from the drop down list, assuming the Virtuoso Demo Database is installed.
    Advanced Properties
    Figure: 2.10.3.1. Advanced Properties
  14. Click the Test Connection button to verify the connection is successful and then click OK to add the connection.
    Test Connection
    Figure: 2.10.3.1. Test Connection
  15. Set the entity connect string name to VirtuosoDemoEntities (note this name as it is required in step 17 below) and click Next.
    entity connect string
    Figure: 2.10.3.1. entity connect string
  16. In the Choose your Database Objects page select the Tables check box to select all tables in the Demo database for addition to the Entity Data Model, set the Model Namespace to VirtuosoDemoModel and click Finish.
    Database Objects
    Figure: 2.10.3.1. Database Objects
  17. The Virtuoso.edmx EDM will be created with the tables and relationships displayed in the Visual Studio IDE
    Virtuoso.edmx
    Figure: 2.10.3.1. Virtuoso.edmx
  18. Right click on the VirtuosoDataService project name of the Solution Explorer pane, then select the Add -> New Item menu options.
    New Item
    Figure: 2.10.3.1. New Item
  19. The Add New Item dialog will appear, choose the ADO.NET Data Service template, give it the name Virtuoso.svc and click Add to create the ADO.Net Data Service.
    ADO.NET Data Service
    Figure: 2.10.3.1. ADO.NET Data Service
  20. In the Virtuoso.svc.cs Data Service file created add the data source class name of VirtuosoDemoEntities (note this is the name set in step 12) as the DataService name and enable the access to the Data Service by adding the entry config.SetEntitySetAccessRule("*", EntitySetRights.All); in the InitializeService method.
    // C#
    
    using System;
    using System.Web;
    using System.Collections.Generic;
    using System.ServiceModel.Web;
    using System.Linq;
    using System.Data.Services;
    
    namespace SimpleDataService
    {
        public class Northwind : DataService<VirtuosoDemoEntities>
        {
            public static void InitializeService(IDataServiceConfiguration  config)
            {
                config.SetEntitySetAccessRule("*", EntitySetRights.All);
            }
        }
    }
    
    Data Service
    Figure: 2.10.3.1. Data Service
  21. To test the Data Service, simply hit Ctrl+F5 within Visual Studio, which will start the development web server, run the Data Services server inside and load a Web browser page displaying the list of available tables/entities of the Demo database.
    test the Data Service
    Figure: 2.10.3.1. test the Data Service
  22. To access a specific entity instance like the Customers table ALFKI record, this would be specified as http://host/vdir/Virtuoso.svc/Customers('ALFKI') .
    Access a specific entity instance
    Figure: 2.10.3.1. Access a specific entity instance

NOTES

  1. Important - To view Atom (the default format returned by an ADO.NET Data Service) in Internet Explorer, you must first ensure that Feed Reading View is turned off. This can be done on the Content tab of Tools in Internet Options.
  2. If a Data Services entity instance URI page fails to load you can turn Verbose errors on by adding config.UseVerboseErrors = true; in 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);
    
    }