This section will guide you through creating first a Web Service that exposes RDF data from Virtuoso and then a simple web browser application that consumes the Web Service and allowing you to access and explore the RDF data by clicking on dereferenceable IRIs.
Step 1 - Create a view of the RDF data
To create a view of the customers in the Northwind first open the Virtuoso Conductor and log in as dba. Then open iSQL from the menu on the left and execute the following statement.
create view Demo.demo.sparqlview as sparql select distinct ?s from <http://localhost:8890/Northwind> where {?s a <http://demo.openlinksw.com/schemas/northwind#Customer>}
Note:
grant execute on DB.DBA.RDF_MAKE_LONG_OF_SQLVAL to "demo"
![]() |
Figure: 2.12.2.1. create a view |
Step 2 - Create the Visual Studio Project and Add the Model
![]() |
Figure: 2.12.2.1. create new application |
![]() |
Figure: 2.12.2.1. Model Namespace |
Step 3 - Add the Web Service
public class WebDataService1 : DataService<DemoEntities>
config.SetEntitySetAccessRule("*", EntitySetRights.All);
The method should look like this:
public static void InitializeService(IDataServiceConfiguration 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); }
Step 4 - Compile and Run
Hit F5 to compile and run the service. Select OK when prompted to enable debugging. The default browser will be launched showing a page like:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?> - <service xml:base="http://localhost:1241/WebDataService1.svc/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app"> - <workspace> <atom:title>Default</atom:title> - <collection href="sparqlview"> <atom:title>sparqlview</atom:title> </collection> </workspace> </service>
The service is now running.
Note the address on which the service is made available. You will need to know this when creating the app to consume the service. Look in the Address Bar of the browser. It will be something like: http://localhost:1492/WebDataService1.svc/
Step 1 - Create the Visual Studio Project.
![]() |
Figure: 2.12.3.1. New Web Application |
datasvcutil.exe /uri:http://localhost:1492/WebDataService1.svc /out:DemoEntities.cs
Note the address of the service - you may need to change the port number to match the one seen in the address at the end of Step 4 in Creating the Web Service.
Step 2 - Display the contents of sparqlview as a table on the page
To display the RDF data on the web page we create a table with a row for each item in sparqlview. We then use each IRI from sparqlview to create a hyperlink. The hyperlinks are displayed in the table cells. To do this add the following block of code to the page_load method in Default.aspx.cs.
DemoModel.DemoEntities svc = new DemoModel.DemoEntities(new Uri("http://localhost:1492/WebDataService1.svc")); var query = svc.sparqlview; Table iriTable = new Table(); this.Controls.Add(iriTable); foreach (DemoModel.sparqlview sv in query) { TableRow tRow = new TableRow(); iriTable.Rows.Add(tRow); TableCell tCell = new TableCell(); tRow.Cells.Add(tCell); HyperLink h = new HyperLink(); h.Text = sv.s; h.NavigateUrl = sv.s; tCell.Controls.Add(h); }
Note the address of the service in the first line - you may need to change the port number to match the one seen in the address at the end of Step 4 in Creating the Web Service.
Compile and run RDFWebApp (ensuring that the service created above is still running). This will launch a browser and display the IRIs from sparqlview as a list of hyperlinks.
![]() |
Figure: 2.12.3.1. list of hyperlinks |
With the RDF Mappers VAD package installed in Virtuoso, clicking on these links will take you to a description page of the referenced resource. The description page is created using description.vsp.
![]() |
Figure: 2.12.3.2. Description page |
To create and test this simple Web Service we have used the Visual Studio Development Server. This section describes how to deploy the service using IIS.
To deploy the service using IIS:
The start page that you see when you test the service will look the same as before but the address in the browser bar will be something like http://localhost/RDFWebDemo1/WebDataService1.svc/. You can now access your service remotely using the hostname or IP address of your server.
If at this point you get an Access is denied error, 401.3, then you will need to add the Internet Guest Account (IUSR_XXX where XXX is your computer name) to the users allowed to access the folder containing the RDFWebDemo project.
You will now need to modify RDFWebApp to access the service at the new address. At the same time we will also change RDFWebApp so that it too is deployed using IIS
DemoModel.DemoEntities svc = new DemoModel.DemoEntities(new Uri("http://localhost:1492/WebDataService1.svc"));
to
DemoModel.DemoEntities svc = new DemoModel.DemoEntities(new Uri("http://localhost/RDFWebDemo/WebDataService1.svc/"));
The web application is accessible on http://localhost/RDFWebApp/Default.aspx and can also be accessed using the hostname or IP address of you server e.g. http://192.168.7.129/RDFWebApp/Default.aspx
![]() |
Figure: 2.12.4.2.1. Default.aspx |
Next Steps
The next example shows you how to quickly create an ADO.Net Data Service that exposes RDF data in Virtuoso and how to create a basic Web application to consume that service. The next step is to create a Silverlight Application to consume the same service.
Previous
Windows Form Application for accessing Virtuoso RDF data via SPASQL using the Virtuoso ADO.Net Provider |
Chapter Contents |
Next
Creating a Silverlight Application to consume the service |