
Microsoft Interoperability team announced the release of a new project, which is a bridge between PHP and .NET and even more erases the brink of technology. This project allows PHP developers to more easily access and use the full power of .NET services based on ADO.NET Data Services.
From the point of view of development, the scheme looks quite a classic image. During the development process, you must use the PHPDataSvcUtil utility, which is included in the PHP Toolkit for ADO.NET Data Services. This utility generates PHP proxy classes based on metadata that are available for the service based on ADO.NET Data Services. After that, the PHP project will also need to include the PHP Toolkit for ADO.NET Data Services libraries. Further, after all these simple steps, you can use the full power of the ADO.NET Data Services platform within PHP applications in a more convenient way.
Let's see how the code on the PHP platform will look like for querying ADO.NET Data Services. First of all, you need to connect the file with proxy classes that are generated using the PHPDataSvcUtil utility:
')
<?PHP
require_once 'NorthwindClient.php';
define("SERVICE_URI", "http://localhost:8080/Northwind.svc");
?>
After that, you can create class objects that implement the logic of the client and make requests to the remote service. Unfortunately, here we will not be able to use the LINQ syntax for building queries to the service. Therefore, the request in the form of a URI will have to write manually.
<?PHP
$client = new NorthwindEntities(SERVICE_URI);
$query = $client->ExecuteQuery("Customers?\$filter=Country eq 'UK'");
?>
Now, after successfully constructing a query, you can ask for data and display the result to the user:
<?PHP
foreach($query as $customer)
{
echo "";
echo $customer->CustomerID;
echo "<br/>";
echo $customer->CompanyName;
echo "";
}
?>
It is clearly seen here that we refer to strongly typed objects, and we get the result in the form of object collections. This method is very similar to how we work with ADO.NET Data Services services within a .NET client. These entity classes were also generated by the PHPDataSvcUtil utility.
Pablo Castro (program manager, ADO.NET Data Services) and Claudio Caldato (program manager, interoperability, techincal strategy team) made a small overview of this library on Channel 9 (en), in which they tell a little more detail.
Finally, it’s very interesting that the project is an open source project and is available on CodePlex. In addition, the project is being developed by Persistent Systems, but paid by Microsoft.
References: