A new bridge for PHP developers to .NET through REST: Toolkit for PHP with ADO.NET Data Services

[Update - March 16, 2010: the toolkit is now called "OData SDK for PHP", and "ADO.NET Data Services" is now called "WCF Data Services". Check related posts on OData ]  

Today, I’m excited to announce that we are releasing a new project that bridges PHP and.NET.
More precisely, we are releasing today the Toolkit for PHP with ADO.NET Data Services which makes it easier for PHP developers to take advantage of ADO.NET Data Services, a set of features recently added to the .NET Framework. ADO.NET Data Services offer a simple way to expose any sort of data in a RESTful way. The Toolkit for PHP with ADO.NET Data Services is an open source project funded by Microsoft and developed by Persistent Systems Ltd. and is available today on Codeplex: phpdataservices.codeplex.com

You can see an overview and quick demo of the toolkit in the following Channel9 video with Pablo Castro (software architect of ADO.NET Data Services) and me:

Get Microsoft Silverlight

A little bit more about ADO.NET Data Services

ADO.NET Data Services (formerly known as Project “Astoria”) is a technology used to expose a wide range of data sources through a RESTful service interface. Data sources can be relational databases, XML files, and so on. ADO.NET Data Services defines a flexible addressing and query interface using a URL convention, as well as the usual resource manipulation methods on data sources (it supports the full range of Create/Read/Update/Delete operations).

There is full support for ADO.NET Data Services in Visual Studio 2008 SP1 as well as in the upcoming Visual Studio 2010; this includes direct support for both creating and consuming data services directly from the development environment. You can find more information about ADO.NET Data Services here, (I recommend the “How do I… ” videos).

Architecture of the Toolkit for PHP with ADO.NET Data Services

You should consider two aspects of the PHP Toolkit:

  • At design time: the PHP Toolkit generates proxy classes based on the metadata exposed by the ADO.NET Data Services (built with Visual Studio, including Express editions).
  • At run time: you call from your code the PHP proxy classes, so that you can easily program against the ADO.NET Data Service using a set of local PHP classes that represent the structure of the remote data. Using RESTful services over HTTP, the communication between the PHP application and ADO.NET Data Services is taken care of by the PHP proxy classes and the Toolkit libraries, but of course you can look at (or edit) this code.

PHP_ADO_DATA_SERVICEArchitecture

Running the Toolkit for PHP with ADO.NET Data Services step by step

In the following steps we assume that you have already created the ADO.NET Data Services on top of the Northwind sample SQL Server database (check this “How do I…” video). The service I created exposes data like this, through a simple URL:

PHP_ADO_DATA_SERVICE_Schema

The next step is to use the PHPDataSvcUtil.php utility that is part of the toolkit, and point it to the URL of the Data Service. It will read the Data Service metadata and create the PHP proxy classes (called northwinddb.php in our example):

PHP_ADO_DATA_SERVICE_Commandline

The code generated (northwinddb.php) looks like this:

PHP_ADO_DATA_SERVICE_CodeGen

At runtime, you simply include in your code the northwinddb.php files and the URL of the data service:

PHP_ADO_DATA_SERVICE_Codehead

And then you can start writing your PHP code to access the data collections. Note the first highlighted line: it defines the query over the data service. Many options are available, the full description of the query format can be found here.

PHP_ADO_DATA_SERVICE_CodeCore

And here is the result:

PHP_ADO_DATA_SERVICE_Result

I hope you enjoy reading this quick introduction to the Toolkit for PHP with ADO.NET Data Services.
Feel free to check the project site on Codeplex phpadodataservices.codeplex.com. As always your feedback is welcomed!

Claudio Caldato, Senior Program Manager,
Interoperability Technical Strategy team.

Comments

  • Anonymous
    August 21, 2009
    The comment has been removed

  • Anonymous
    August 24, 2009
    The comment has been removed

  • Anonymous
    August 24, 2009
    The comment has been removed

  • Anonymous
    August 24, 2009
    The comment has been removed

  • Anonymous
    August 24, 2009
    The comment has been removed

  • Anonymous
    August 25, 2009
    claudioc - I ran the PHPDataSvcUtil from my local machine and it was a complete success.  The remaining steps of the tutorial went smoothly and I'm now able to extract the data I need with this great utility.  Thank you!

  • Anonymous
    September 07, 2009
    pretty nice and good move from microsoft to enable developers to keep UI on php and DAL on .net this is a good way to start from and new ways to allow two technologies to talk and work

  • Anonymous
    September 08, 2009
    The comment has been removed

  • Anonymous
    September 09, 2009
    @Tim Brookins: maybe you could explain a little bit what's  not working. They we could try to help :) my 2 cents. JC

  • Anonymous
    November 30, 2009
    I'm interested on this, but I'm having problem with creating the ADO.NET Data Services. I had installed the .Net Framework 3.5 Sp1 but the ADO.Net Data Entity Model doesn't show up. What do you think I'm missing? Thanks...

  • Anonymous
    December 01, 2009
    The comment has been removed