Freigeben über


PHP with Microsoft’s OGDI via ADO.NET and REST (OData)

My last post, Microsoft, Interoperability at XML-in-Practice 2009 mentioned a project  called Open Government Data Initiative (OGDI) which complements Data.gov by providing an SDK that allows you to easily access publicly available government data. It’s a pretty useful tool toOGDI SDK quickly build applications on top of the datasets. I had a couple of questions on this project and how to interact with the PHP language and I wanted to highlight some simple ways on how you can do so.

The most interesting way you can do so is by using PHP via our Toolkit for PHP with ADO.NET Data Services. This project makes it easier for PHP developer to take advantage of the ADO.NET Data Services, a set of features now available in the .NET framework. It simply exposes data in a RESTful way via proxy classes that are generated by the toolkit at design time by using the metadata that is exposed. Your code at runtime uses these classes to work with the .NET based service over http. You can easily adapt the example given in the toolkit also described by Claudio here, to use the OGDI service. 

You will want to PHP on Windowsinstall the toolkit as per instructions (/docs folder has a good Users Guide, it’s also available here)  by copying all the files and folders into an accessible folder with the proper include_path reference in your php.ini file, as well creating the proper variables and enabling the proper extensions such as php_curl an php_xsl. This stumped quite a few folks as generating proxy classes using the PHPDataSvcUtil.php client will not work otherwise and neither will the proxy, editor or the entity you generate. With that done, you should be able to point to the uri, you want on the OGDI data service (e.g. http://ogdi.cloudapp.net/v1/dc/ ) DC Red Light Camerasand with that you can generate your proxy classes or Entity Container. You can find a working example that has a full browser for the data at http://ogdiphpsample.cloudapp.net/ , with source code available that you can reference. There is also an ADO.NET Data Services Client Library that can be found here in which you can build using Visual Studio 2008, Service Pack 1 or later and create a svc proxy using the above method.

The next option is to use the REST Web Services, that let’s you query using PHP and have a return result  in either ATOM Publishing Protocols, Javascript Object Notation (JSON) and JSON with Padding (JSONP) which is used in quite a few Web2.0 frameworks. There is also the ability to call using straight Javascript from within your PHP apps. You would ideally however want to create a REST client service class, with a pointer to the URL, typically one of the data services on http://ogdi.cloudapp.net/v1. You will then create a query, using a format, using the methods defined here. After grabbing executing with the proper exception handling and managing the responses for display or processing. You can see an example of the PHP code by using the data catalog. This query for example, will return the Domestic Per Diem Rates for 2009 from the General Services Administration entity container. You can also apply filters to narrow down your result as in the examples above.

There is also the ability to return your data in Geospatial form by using the Keyhole Markup Language (KML) which is compatible with popular mapping tools including Bing Maps and services from Google and yahoo. All you need to do is to append format=kml to your query just like the filters and you will be able to visualize the data that is returned. You will find some good examples of usage in the data catalog mentined earlier. That should add some interesting color to your application along with the other methods mentioned above if the data lends itself to the solution you create.

Jas Sandhu
Senior Technical Evangelist, Interop Vendor Alliance Manager, Interoperability Strategy Team
Twitter@jassand, FriendFeed@jassand