NuSOAP - Web Services Toolkit for PHP is used to be able to connect to TP Web Services. Several changes were made in NuSOAP sources, so use for your development version which comes with the examples (NuSOAP library and required TargetProcess PHP library are in [lib] directory).
Retrieving Entities (Projects)
<?php
require_once('lib/nusoap.php');
require_once('tp.php');
//Initialize security header
$securityHeader = new SecurityHeader;
//Initialize Soap Client
$client = new soapclient('http://localhost/TargetProcess/Services/ProjectService.asmx?wsdl','wsdl');
$client->soap_defencoding = "UTF-8";
$err = $client->getError();
if ($err)
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
//Append Tp Policy (must be applied before every soap call)
$securityHeader->AppendTpPolicy($client, 'RetrieveAll', 'admin', 'admin');
$result = $client->call('RetrieveAll');
//Output results or error
if ($client->fault)
{
echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2><pre>';
print_r($result);
echo '</pre>';
}
else
{
$err = $client->getError();
if ($err)
{
echo '<h2>Error</h2><pre>' . $err . '</pre>';
}
else
{
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
//Show Debug Information
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
?>
Creating/Updating Entity (Project)
<?php
require_once('lib/nusoap.php');
require_once('lib/tp.php');
//Initialize security header
$securityHeader = new SecurityHeader;
//Initialize Soap Client
$client = new soapclient('http://localhost/TargetProcess/Services/ProjectService.asmx?wsdl','wsdl');
$client->soap_defencoding = "UTF-8";
$err = $client->getError();
if ($err)
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
//Append Tp Policy (must be applied before every soap call)
$securityHeader->AppendTpPolicy($client, 'Create', 'admin', 'admin');
$projectName = 'My Prj : '.$securityHeader->getGuid();
//Fill out project DTO. Create the project with unique name.
$params = array(
//Please note the parameters names should be the same as declared in wsdl
'entity' => array
(
"Name"=>$projectName
));
$result = $client->call('Create', $params);
//Output results or error
if ($client->fault)
{
echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2><pre>';
print_r($result);
echo '</pre>';
}
else
{
$err = $client->getError();
if ($err)
echo '<h2>Error</h2><pre>' . $err . '</pre>';
else
echo '<h2>Result</h2><pre>'; print_r($result); echo '</pre>';
}
//Show Debug Information
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
?>