Ok, so I have been playing around with the ADO.NET DataServices to get something working for a REST based access to the RDF Store. My goal here was to create a simple REST based way to grab metadata out of the RDF store based on the ADO.NET DataServices model instead of relying on SOAP and SPARQL. I just wanted a simple way to get a specific object and some basic locked down values into a Silverlight application.
To create an ADO.NET DataService for use with IMM you need to follow these steps. Keep in mind that the DataService will need to be locked down to a specific Entity view of objects in the IMM Store, and is mostly meant to be read only for Silverlight applications or public sites.
CREATE VIEW dbo.VideoItems
AS
SELECT SUBSTRING(c1.Value,50,37) AS ID,
c2.Value as Title,
c3.Value as [Description],
c4.Value as [Ref],
FROM dbo.sparql ('
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX imm: <http://schemas.microsoft.com/imm/2.0/core/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX did: <urn:mpeg:mpeg21:2002:02-DIDMODEL-NS#>
PREFIX dii: <urn:mpeg:mpeg21:2002:01-DII-NS#>
SELECT ?item ?title ?description ?ref
FROM <http://schemas.microsoft.com/IMM/data>
WHERE
{
?item rdf:type imm:VideoItem.
?item dc:title ?title.
?item dc:title ?description.
?item did:ResourceCollection ?resource.
?resource imm:ResourceType "Proxy"^^<http://www.w3.org/2001/XMLSchema#string>.
?resource did:Ref ?ref.
}
')
GO
/// <summary>
/// The IMM Data Service for use with ADO.NET
/// </summary>
public class IMMDataService : DataService<IMMMetadataDataContext>
// This method is called only once to initialize service-wide policies.
/// Initializes the service.
/// <param name="config">The config.</param>
public static void InitializeService(IDataServiceConfiguration config)
config.SetEntitySetAccessRule("VideoItems", EntitySetRights.AllRead);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
a.) Select the Top 3 Items http://localhost:29062/SemanticMetadata.svc/VideoItems?$top=3
b.) Order by Title predicate http://localhost:29062/SemanticMetadata.svc/VideoItems?$orderby=Title
c.) Skip ahead by 10 items in the results and limit to 10. Good for paging! http://localhost:33655/IMMDataService.svc/VideoItems?$skip=10&$top=10
d.) Filter by the content of a predicate. http://localhost:33655/IMMDataService.svc/VideoItems?$filter=Title eq 'Volcano'
e.) More query options and examples are here and here
a.) Generate data service classes from the running data service. These classes represent each of the entities that are defined in the data service. This step can be completed by using the Add Service Reference Dialog Box in Visual Studio. Make sure the data service is running, right-click the project, and then select Add Service Reference. Type the base URL of the data service, such as http://localhost:33655/IMMDataService.svc into the address text box and click Go. The output from the command is a C# or Visual Basic file that contains a class for each entity type in the data service. For more information about the client classes, see .NET Client Library (ADO.NET Data Services Framework). The System.Data.Services.Client assembly is added to the project automatically when you generate the client classes by using Add Service Reference. This assembly comes with Silverlight and contains the classes needed by the client application to access ADO.NET Data Services.
b.) The classes that represent data service types can also be generated by using DataSvcUtil.exe. DataSvcUtil.exe is located in the directory \WINDOWS\Microsoft.NET\Framework\v3.5\. The command line takes two arguments: the name and path of an output file and the base URL to the data service for which types are to be generated. c.) In the page.xaml.cs, add the following using directive: using System.Data.Services.Client.
b.) The classes that represent data service types can also be generated by using DataSvcUtil.exe. DataSvcUtil.exe is located in the directory \WINDOWS\Microsoft.NET\Framework\v3.5\. The command line takes two arguments: the name and path of an output file and the base URL to the data service for which types are to be generated.
c.) In the page.xaml.cs, add the following using directive: using System.Data.Services.Client.
CREATE VIEW dbo.Resources
c2.Value as Type,
c3.Value as [Size],
c4.Value as vFormat,
c5.Value as Mime,
c6.Value as Ref,
c7.Value As Lang,
SUBSTRING(c8.Value,50,37) As ParentID
SELECT ?s ?type ?size ?vFormat ?mime ?ref ?lang ?parent
?s rdf:type did:Resource.
?parent did:ResourceCollection ?s.
OPTIONAL{
?s imm:ResourceType ?type.
?s imm:SizeInBytes ?size.
?s imm:VideoFormat ?vFormat.
?s did:MimeType ?mime.
?s did:Ref ?ref.
?s dc:language ?lang.
Have Fun!
John Deutscher Group Program Manager Microsoft johndeu@microsoft.com