Professional Documents
Culture Documents
com/en/blog/archive/2010/06/09/odata-and-wcf-data-
services.aspx
http://www.codeproject.com/KB/database/InstallingNorthwindAndPub.aspx
OData and WCF Data Services
Tags:
This week we started investigating OData and WCF data services as a way to easily expose and query a remote
database.
OData, the Open Data Protocol is a protocol for querying and updating data over using Http and AtomPub
Visual studio 2010 and .NET 4.0 come with rich support to both produce and consume data using the Open Data
Protocol.
This post is a tutorial on how to set up a web service that exposes OData, and how to query it from a client
application.
Prerequisites
• Download and install the Northwind database
http://www.codeproject.com/KB/database/InstallingNorthwindAndPub.aspx
• Visual Studio 2010
• .NET 4.0 Framework or the Data Services update for Microsoft .NET Framework 3.5 Service Pack 1
class Program
{
static void Main(string[] args)
{
string url = "http://localhost:40171/NorthwindService.svc/";
var context = new NorthwindEntities(new Uri(url));
ab
Comments
Tom Pester commented on Wednesday, 9-Jun-2010
Some more links to get you started : Open Data Protocol Visualizer http://visualstudiogallery.msdn.microsoft.com/en-
us/f4ac856a-796e-4d78-9a3d-0120d8137722 <Open Data Protocol (OData) with Pablo Castro/>
http://www.hanselminutes.com/default.aspx?ShowID=223 Episode 43: Talking OData and SQL Modeling with
Douglas Purdy http://deepfriedbytes.com/podcast/episode-43-talking-odata-and-sql-modeling-services-with-douglas-
purdy/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+deepfriedbytes+
%28Deep+Fried+Bytes%29&utm_content=Google+Reader Carl and Richard get the word on oData from Brad
Abrams, Bob Dimpsey and Lance Olson. http://www.dotnetrocks.com/default.aspx?ShowNum=519 Using Data
Services over SharePoint 2010 – Part 1 – Getting Started
http://blogs.msdn.com/b/astoriateam/archive/2009/10/21/using-data-services-over-sharepoint-2010-part-1-getting-
started.aspx The Open Data Protocol (OData) http://www.stephenforte.net/PermaLink,guid,28df55a8-8811-4c4b-
b319-75c5c58d1444.aspx
Your name *
Email *
Your URL
Comment *
Please enter the text from the image
Submit
ntroduction
The Northwind and Pubs sample databases are staples of other sample code on this and
other development websites. They are used in countless tutorials and walkthroughs
published by Microsoft and others. Being a SQL/SQL Server newbie myself, I figured there
may be others in my boat who might want both databases in an easily-accessible spot, and
an easier, less error-prone way of installing them into SQL Server 2005 Express Edition
than, say, running SQL query scripts.
Background
It's lost on me why one must use *.sql query scripts to install these samples. It's also lost
on me why SQL Server distributions don't come with these databases provided, since they
are used so ubiquitously through documentation, websites, and tutorials. There are probably
several good reasons for this. However, I am focused on usability, and not on making things
harder than they have to be.
There undoubtedly will be readers who will protest and say that I should use *.sql query
files whenever possible; this is good and a perfectly acceptable practice. I see this article as
illustrating just another way to accomplish a similar objective.
It's worth noting, for example, that a default Visual Studio .NET 2005 Standard Edition
installation does not distribute these databases. It goes part-way, creating a Program
Files\Microsoft Visual Studio 8\SDK\Samples\Setup directory containing, e.g., instnwnd.sql,
a query script that ostensibly can be used to install the Northwind sample database.
However, hats off to Microsoft for putting apples with apples. Microsoft provides
the queries for installing, but not the *.mdf and *.ldf files for thedatabases themselves.
This does not support users in installing these important samples into SQL Server. Perhaps
there's an easier way: this article. The download attached to this article contains the SQL
Server 2000 versions of these files.
Personally, I favor using graphical (GUI) tools and methods over typing cryptic commands
and deciphering error messages. So, this article illustrates how to install Northwind and
Pubs using graphical tools and methods.
Fill in the appropriate settings on the Connect to Server window that appears, and then
click Connect.
SQL Server Management Studio Express opens the Object Explorer with the server's
databases displayed.
Step 3: Right-click the Databases folder and then click Attach, as shown in Figure 2.
Figure 2. The Object Explorer window
Step 5: Locate and click on the NORTHWND.MDF file, and then click OK.
The right pane of the Attach Databases window will look as shown in Figure 4.
Figure 4. The right pane of the Attach Databases window after adding the Northwind database
History
In this section, I will keep a running history of the changes and updates I've made to this
article:
• 29 Sept. 2009, 11:25 PM Central: Article download link to reflect the official
Microsoft release location
highlighted:http://www.codeproject.com/Messages/2901428/Northwind-and-Pubs-
for-SQL-2000-and-up-from-Micros.aspx.
• 16 Oct. 2007, 2:13 PM Pacific: Article written.
License
This article, along with any associated source code and files, is licensed under The Code
Project Open License (CPOL)
Silverlight
Other
Urban Science
United States
Member