Web service integration using PHP
From KnowledgeTree Document Management Made Simple
Contents |
[edit]
requirements
In order to interface with KnowledgeTree using the SOAP interface via PHP, you need access to a SOAP library.
There are a number that you can use. This guide will demonstrate how to use PHP PEAR::SOAP.
[edit]
sample
define('KT_PEAR_DIR', '/path_to_pear/pear');
define('KT_SOAP_URL', 'http://your_kt_domain/ktwebservice/webservice.php');
define('KT_WSDL', KT_SOAP_URL . '?wsdl');
define('KT_USERNAME','admin');
define('KT_PASSWORD','admin');
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . KT_PEAR_DIR);
require_once('SOAP/Client.php');
$wsdl = new SOAP_WSDL(KT_WSDL);
$soapclient = $wsdl->getProxy();
$soapclient->setOpt('timeout', 60);
$login_response = $soapclient->login(KT_USERNAME, KT_PASSWORD, '127.0.0.1');
if ($login_response->status_message != 0 )
{
die('Cannot authenticate with knowledgetree: ' . $login_response->message);
}
$session = $login_response->message;
[edit]
optimisation
You can optimise the code above by downloading the WSDL and creating a local file. The WSDL should remain static unless new functionality is added.
[edit]
using https
It may help to disable some of the strict validation that SSL provides. add the following before the
// kt.wsdl is a file locally accessible
$wsdl = new SOAP_WSDL('kt.wsdl');
$soapclient = $wsdl->getProxy();
$soapclient->_endpoint = KT_SOAP_URL;
$soapclient->setOpt('timeout', 60);
$soapclient->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0);
$soapclient->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0);
[edit]
alternative calling convention
- TODO: TEST THIS
define('KT_PEAR_DIR', '/path_to_pear/pear');
define('KT_SOAP_URL', 'http://your_kt_domain/ktwebservice/webservice.php');
define('KT_WSDL', KT_SOAP_URL . '?wsdl');
define('KT_USERNAME','admin');
define('KT_PASSWORD','admin');
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . KT_PEAR_DIR);
require_once('SOAP/Client.php');
$soapclient = new SOAP_Client(KT_SOAP_URL, false);
$soapclient->setOpt('timeout', 60);
$login_params = array('username'=>'admin', 'password'=>'admin', 'ip'=>'127.0.0.1');
$response = $soapclient->call('login', $login_params);
$login_response = $soapclient->login(KT_USERNAME, KT_PASSWORD, '127.0.0.1');
if (PEAR::isError($login_response)
{
die('Cannot authenticate: ' . $login_response->message);
}
print_r($login_response)
del.icio.us
reddit

