123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2016 Ion Agorria <ion@agorria.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/webservices/demo_wsclient_project.php
- * \brief Demo page to make a client call to Dolibarr WebServices "server_project"
- */
- // This is to make Dolibarr working with Plesk
- set_include_path($_SERVER['DOCUMENT_ROOT'].'/htdocs');
- require_once '../master.inc.php';
- require_once NUSOAP_PATH.'/nusoap.php'; // Include SOAP
- $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_project.php';
- //$WS_DOL_URL = 'http://localhost:8080/'; // To test with Soapui mock. If not a page, should end with /
- $WS_METHOD1 = 'createProject';
- $WS_METHOD2 = 'getProject';
- $ns='http://www.dolibarr.org/ns/';
- // Set the WebService URL
- dol_syslog("Create nusoap_client for URL=".$WS_DOL_URL);
- $soapclient = new nusoap_client($WS_DOL_URL);
- if ($soapclient)
- {
- $soapclient->soap_defencoding='UTF-8';
- $soapclient->decodeUTF8(false);
- }
- // Call the WebService method and store its result in $result.
- $authentication=array(
- 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
- 'sourceapplication'=>'DEMO',
- 'login'=>'admin',
- 'password'=>'changeme',
- 'entity'=>'');
- // Test url 1
- if ($WS_METHOD1)
- {
- $parameters = array(
- 'authentication'=>$authentication,
- 'project'=>array(
- 'ref'=>'REF_TEST_WS',
- 'label'=>'LABEL_WS',
- 'thirdparty_id'=>'1234',
- 'public'=>'1',
- 'status'=>'0',
- 'date_start'=>'2016-04-07T21:24:19Z',
- 'date_end'=>'2016-04-08T08:13:42Z',
- 'budget'=>'1234',
- 'description'=>'DESCRIPTION_WS',
- )
- );
- dol_syslog("Call method ".$WS_METHOD1);
- $result1 = $soapclient->call($WS_METHOD1,$parameters,$ns,'');
- if (! $result1)
- {
- print $soapclient->error_str;
- print "<br>\n\n";
- print $soapclient->request;
- print "<br>\n\n";
- print $soapclient->response;
- exit;
- }
- }
- // Test url 2
- if ($WS_METHOD2)
- {
- $parameters = array(
- 'authentication'=>$authentication,
- 'id'=>'',
- 'ref'=>'REF_TEST_WS'
- );
- dol_syslog("Call method ".$WS_METHOD2);
- $result2 = $soapclient->call($WS_METHOD2,$parameters,$ns,'');
- if (! $result2)
- {
- print $soapclient->error_str;
- print "<br>\n\n";
- print $soapclient->request;
- print "<br>\n\n";
- print $soapclient->response;
- exit;
- }
- }
- /*
- * View
- */
- header("Content-type: text/html; charset=utf8");
- print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
- echo '<html>'."\n";
- echo '<head>';
- echo '<title>WebService Test: '.$WS_METHOD1.'</title>';
- echo '</head>'."\n";
- echo '<body>'."\n";
- echo 'NUSOAP_PATH='.NUSOAP_PATH.'<br>';
- echo "<h2>Request:</h2>";
- echo '<h4>Function</h4>';
- echo $WS_METHOD1;
- echo '<h4>SOAP Message</h4>';
- echo '<pre>' . htmlspecialchars($soapclient1->request, ENT_QUOTES) . '</pre>';
- //echo '<hr>';
- echo "<h2>Response:</h2>";
- echo '<h4>Result</h4>';
- echo '<pre>';
- print_r($result1);
- echo '</pre>';
- echo '<h4>SOAP Message</h4>';
- echo '<pre>' . htmlspecialchars($soapclient1->response, ENT_QUOTES) . '</pre>';
- print '<hr>';
- echo "<h2>Request:</h2>";
- echo '<h4>Function</h4>';
- echo $WS_METHOD2;
- echo '<h4>SOAP Message</h4>';
- echo '<pre>' . htmlspecialchars($soapclient2->request, ENT_QUOTES) . '</pre>';
- //echo '<hr>';
- echo "<h2>Response:</h2>";
- echo '<h4>Result</h4>';
- echo '<pre>';
- print_r($result2);
- echo '</pre>';
- echo '<h4>SOAP Message</h4>';
- echo '<pre>' . htmlspecialchars($soapclient2->response, ENT_QUOTES) . '</pre>';
- echo '</body>'."\n";
- echo '</html>'."\n";
- ?>
|