I started a new project a couple weeks ago, ".NET Web Services for PHP". My work frequently requires me to use an existing .NET data access architecture that I and several others wrote months past. We began incorporating parts of our project into online components and so I began writing web services in .NET to use our existing data architecture. While I love writing web services in .NET, I absolutely loath consuming them in PHP. The .NET data access used datatables heavily (almost exclusively) and for the longest time I would have to map the datatables to an object to pass over SOAP for PHP to receive. I longed for a better way.
Enter my SuperDotNET for PHP class. This is the alpha release of my PHP SOAP class to handle SOAP requests (to any web service, not just .NET services). If you use .NET web services in any way with PHP I would love it if you could check out this project - it is very much in the beginning stages but it already has one critical component in place: it can parse .NET datatables into an PHP array of objects (each row becomes an object in the array) and let's you specify a pre-existing class to map the datatable to.
I realize that my documentation is kind of slim - the only included docs are the generated API so I'll include a quickstart tutorial here pending a more comprehensive tutorial for all of the features.
Install by unpacking and dumping the SuperDotNet folder into your PHP project. The filepath to include is /SuperDotNET/SuperDotNet.php. This will give you access to the class and all its functionality. Make sure you include the plugins folder in the same directory as SuperDotNet.php.
Here's how you consume a new web service.
Code: Select all
<?php
//include the class
include("SuperDotNET/SuperDotNet.php");
//start a new instance
$service = new SuperDotNet;
//you can store an array of web service URIs - referenced by a key later addURI("KEY", "URI");
$service->addURI("CalendarService", "http://yoururl.com/path_to_uri.asmx?WSDL");
//name the plugins to fire - plugins operate on each field of data that is returned by the services
//in this case the plugins turn numeric strings into integers, timespans in human readable times, and datetimes into human readable dates
$service->setPlugins("integer, timespan, datetime");
//make our actual call to the web services by referencing the key we specified earlier - this lets you specify all your WSDLs in the same class
$service->soapCall("CalendarService", "retrieveDetails", ParameterBuilder::build("id=5, date=today, password=stayfrosty"));
//"soapCall" automatically assumes you are returning a .NET datatable - to turn this off and receive any kind of results, simply attach an extra parameter after your parameters: "false".
//the actual function definition:
//public function soapCall($uri_key, $function, $parameter_array = "", $is_datatable = true, $options_array = "")
//our datable has now been automatically parsed and dumped into our results - to view it....
var_dump($service->getResults());
//...and you'll see your datatable represented as an array of objects