Getting started with PHP

Printer-friendly version

Introduction

Manipulating DM web-services from PHP is made trivial with stub classes. Those client stub classes can be generated with tools such as wsdl2php. You will need the PEAR libraries too, if you don't already have them. Once you've installed them, you can generate the client code for a WSDL.

I'll assume you've an account set up on the TEST1 platform ("myuser"/"mypassword"), and have set up PHP and PEAR correctly.

I will start by demonstrating how to write PHP code to get the names of all the warehouses the "myuser" user has access to. First, we will produce a file named InformationServiceService.php, containing the stub code for calling the information service:

php5 wsdl2php.php http://www.metapack.com/devcentre/sites/default/files/wsdl/InformationService.wsdl

Note the URL used was a publicly accessible one, and not that of an actual system. That is because the wsdl2php.php script does not allow you to specify the HTTP AUTH user and password.

Now that we have the generated client code, connecting to the correct server (test1.metapack.com, in this case) and getting the list of warehouses is a simple matter:

<?php
include "InformationServiceService.php";

$svc = new InformationServiceService(
		"http://test1.metapack.com/dm/services/InformationService?wsdl",
		array(
			"login" => "myuser",
			"password" => "mypassword" ) );

$warehouses = $svc->findWarehouses();
foreach( $warehouses as $warehouse ) {
	echo "code=" . $warehouse->code . " name=" . $warehouse->name . "\n";
}
?>

Executing the script will result in all the warehouses being reported, showing the unique warehouse code and the warehouse's name. In a real application, you should consider error handling, as well as refactoring URL configuration, user ID and password to a common area.

In a nutshell, that's it. Other services require many more parameters, but that's the basic stuff.

 

DM Client

As you are no doubt aware, you will actually need to make use of more than one service in your solution. Simply generating code like that is entirely possible, but you will get multiple classes redefined when you include multiple stubs. For your convenience, we have produced a single file containing everything you need to get going, named dmclient.zip. Inside that ZIP is also the code to list warehouses.

 

 

 

AttachmentSize
InformationServiceService.php_.txt3.53 KB
dmclient.zip4.08 KB