Mohammad M. Ramezanpour It's all about my life...

A brief overview of OData and WCF data services

7. February 2011 08:37 by Mohammad Mahdi Ramezanpour in LINQ, WCF

People all around the world want to share data. They want to share their interests with others. Companies want to share data too. For example, EBay wants to distribute data of latest products and interests to the web and enable other companies to use that data in their own websites. There were ways to do that:

  • RSS/ATOM feeds.
  • XML Web services.

But each of the items above has their own problems and both of them have lots of limitations. In fact, there is no way to query the source’s database. In the EBay example, it’s impossible to select some data with specific parameters except the EBay has been developed some methods in order to that but it’s not enough in some cases, as you know.

But there’s a new way to distribute data and that’s OData!

OData is the short form of “Open Data Protocol” which is a new standard way for distributing data. The result of OData is standard XML so you can access to it using any programming language/tools. Here’s the OData definition from its official website:

The Open Data Protocol (OData) is a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today. OData does this by applying and building upon Web technologies such as HTTP, Atom Publishing Protocol (AtomPub) and JSON to provide access to information from a variety of applications, services, and stores. The protocol emerged from experiences implementing AtomPub clients and servers in a variety of products over the past several years.  OData is being used to expose and access information from a variety of sources including, but not limited to, relational databases, file systems, content management systems and traditional Web sites.

Companies have started to use OData too; for example you can access Netflix’s latest movies and use them in your application using OData! In order to do so, visit http://odata.netflix.com.

The table below shows the libraries which currently support OData:

OData Currently supported programming languages' library

 

You can download any library you want depend on what programming language you’re working with. As you can see in the table above, .NET Framework 3.5 SP1 and 4 is supported. In order to use OData in .NET 3.5 SP1, you have to download and install Data Service Support for .NET Framework 3.5 SP1 and then start working with but if you’re developing your application based on .NET Framework 4, you don’t need anything at all because Data Services is supported built-in.

In order to get more information about OData standards and documentations, you can checkout: http://odata.org.

WCF Data Services

WCF Data Services is the implementation of OData in .NET Framework. Hopefully, Microsoft has done a great job on this and it’s very easy to use. Data Services is not dedicated to databases; in fact it’s all about entities. You can build any entities and access it via Data Services. For example you can create an Entity Framework 4 entity and the access it via a Data Service. It’s the same story for LINQ to SQL, XML, etc.

As an example, I decided to create a Data Service for my EF 4 database model. Here are steps you can create a Data Service:

  1. As I mentioned, I preferred to use LINQ to Entity in my project so first you need to do is to create a database model by creating an ADO.NET Entity Data Model.
  2. After creating the database model, it’s time to create the data service. There’s nothing else to do! If you want to create a data service, you can add new WCF Data Service file to the project.
    Adding a WCF Data Service
  3. After a WCF Data Service file to your project, Visual Studio will create a .NET class which is inherited to DataService class. The DataService class in a generic class so you have to assign a data source to it. If you’re using EF, all you need is to type the name of your entity. For example “NorthwindEntities”.
    wcf-data-service-class-view
  4. Then you need to set permissions for the data service. The WCF data service that is created by Visual Studio contains a static InitializeService method that has an input parameter as a DataServiceConfiguration class which includes some methods in order to set permissions for the data service. The most important method for setting permissions is SetEntitySetAccessRule that you can set access rule for your entity. Here’s an example:
  5. As you can see, SetEntitySetAccessRule accepts two parameters. The first parameter is the name of the entity as string and the second parameter is the entity set rights. In the example above, the entity set rights is set to AllRead which means that users can only read from this entity. If you want to allow users to read and also write data using your service, you can set the entity rights to “All”.

Now your service is ready to use! It’s that easy! You can add your service to another application as same as adding a WCF service and use it. But the difference is that the service is using OData to publish the data. Also you can use LINQ expressions to access whatever you want!

Unfortunately, some of the lambda expressions are not supported by WCF Data Services. For instance, you can’t use Single method like this:

var x = myService.Table.Single(p=>p.Id == 1);

You have to use Single like this:

var x = (from i in myService.Table where i.Id == 1 select i).Single();

I hope Microsoft fix this problem as soon as possible.

I’ll post about WCF Data Service in my future posts but for now if you want to know more about it, you can check out WCF Data Service Client Library in MSDN

Oxite, An open source CMS based on ASP.NET MVC by Microsoft

 Oxite Logo - Photo taken from http://www.codeplex.com/oxite I know it’s a little old but in this post I want to talk about Oxite.

Oxite is a new open source blogging system based on ASP.NET MVC which built by Erik Porter, Nathan Heskew, Mike Sampson and Duncan Mackenzie.

This is a simple blog engine written using ASP.NET MVC, and is designed with two main goals:

· To provide a sample of 'core blog functionality' in a reusable fashion. Blogs are simple and well understood by many developers, but the set of basic functions that a blog needs to implement (trackbacks, RSS, comments, etc.) are fairly complex. Hopefully this code helps.

· To provide a real-world sample written using ASP.NET MVC.

As they said, this blog engine built not only for developers and as sample and this has been used in MIX Online too.

Here is some other information from http://visitmix.com/lab/oxite:

Oxite was developed carefully and painstakingly to be a great blogging platform, or a starting point for your own web site project with CMS needs. Its line-up of sexy attributes includes: provider-based architecture allowing you to swap out database and search providers (SQL Server DB, local and Live search providers included), built for testability and hence most likely to be voted "hottest in class" by TDD fans (repositories, everything has an interface, etc.), database file and string resource storage so that files get stored in database and strings stored for localization, built to take full advantage of ASP.NET MVC but broken into assemblies so that even ASP.NET WebForm developers can use the data backend and utility code, supports use of Visual Studio Team Suite (DB Pro, Test, etc.), and Background Services Architecture (sending trackbacks, emails, etc. all done as a background process to prevent delays on the web site itself).

Download it now and get some other information by click here

Visual Basic 2010 new features

19. November 2008 21:39 by Mohammad Mahdi Ramezanpour in .NET General, LINQ, XML

Channel 9 Logo - Photo taken from: http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.pngWorking with new technology is always interesting. Since Visual Studio 2010 and .NET Framework 4 have been announced, most of developers who are developing with Visual Basic start searching about Visual Basic 10 new features.

About a month ago, Lucian Wischik and Lisa Feigenbaum described about new features in Visual Basic 2010. The show is available for download at MSDN Channel 9 website.

You can check it out by click here.

This is my recommendation: View it!