I am new to the programming area and this is my first nusoap-0.9.5 client and server program. Although the the server looks correct the client keeps giving me this warning:
PHP Fatal error: SoapClient::SoapClient(): Invalid parameters in /var/www/client.php on line 5
PHP Fatal error: Uncaught SoapFault exception: [Client] SoapClient::SoapClient(): Invalid parameters in /var/www/client.php:5
Stack trace:
#0 /var/www/client.php(5): SoapClient->SoapClient('http://localhos...', true)
#1 {main}
thrown in /var/www/client.php on line 5
Anybody knows the reason? I am trying to find a solution over the net more than a week now and I can not understand what is wrong with my program why it is not working.
Client code:
Thanks again Davey, I have read all the tutorials that you recommend and I am still a bit confused but at least less confused than before. I have modified my code again, I hope it makes more sense now. So here it is:
<?php
include "conf_client.php";
require_once('nusoap.php');
$client = new soapclient('http://localhost:8048/server.php?wsdl',true);
class Data {
public $acro = acro;
public $note = note;
public $prio = prio;
public $date = date;
public function Delete() {
$create = array ($acro,
$date,
$note,
$prio);
return $create;
}// End of Function Delete
}// End of class Data
$data = new Data();
$delete = $data->Delete();
$response = $client->call('Lists.DeleteToDo',$delete);
var_dump($response);
?>
directory: {file:///var/www/server.php}
Any help is much appreciated.
'List.DeleteToDo'
Is the class: List and the Function: DeleteToDo on the side of the server that I am calling.
I manage to find more about my problem and I have solved it. I am posting my server code here maybe it can help also someone else.
As a beginner I have simplified the code as much as possible. I am not including to my answer the configuration file, but if anybody needs it please let me know and I will post it as well.
I would also like to say thank you to everyone who answered my query at this forum and help me understand my errors.
<?php
include "conf.php";
require_once('nusoap/lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('This is my First nuSoapServer', 'urn:nuSoapServer');
$server->wsdl->addComplexType('Data',
'compexType',
'struct',
'all',
'',
array('id' => array('name' => 'id', 'type' => 'xsd:int'),
'acro' => array('name' => 'acro', 'type' => 'xsd:string'),
'time' => array('name' => 'time', 'type' => 'xsd:string'),
'date' => array('name' => 'date', 'type' => 'xsd:string'),
'note' => array('name' => 'note', 'type' => 'xsd:string'),
'prio' => array('name' => 'prio', 'type' => 'xsd:int'),
'data' => array('name' => 'data', 'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'DataArray', // Name
'complexType', // Type Class
'array', // PHP Type
'', // Compositor
'SOAP-ENC:Array', // Restricted Base
array(), // Elements
array( // Atributes
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:Data[]')
),
'tns:Data'
);
$server->register('GetTodoList', // method name
array('acro' => 'xsd:string'), // input parameters
array('DataResult' => 'tns:DataArray'), // output parameters
'urn:nuSoapServer', // namespace($namespace)
'urn:nuSoapServer#GetTodoList', // soap action
'rpc', // style
'encoded', // use
'Return Get to do list'); // documentation
function GetMyConnection() {
global $InputArray;
$dbase_link = mysql_connect($InputArray['host'],$InputArray['mysql_user'],$InputArray['mysql_password']);
//check if connected
if (!$dbase_link) {
die("Can not connect: " . mysql_error());
}
//return $this->myconn;
//http://se1.php.net/manual/en/function.mysql-create-db.php
$dbase_select = mysql_select_db($InputArray['mysql_dbase']);
if (empty($dbase_select)) {
$sql = "CREATE DATABASE IF NOT EXISTS ".$InputArray['mysql_dbase']."\n";
if (mysql_query($sql)) {
echo "Database: " . $InputArray['mysql_dbase'] . " was created succesfully\n";
}
else {
echo "Error creating database: " . mysql_error() . "\n";
}
}
$dbase_select = mysql_select_db($InputArray['mysql_dbase']);
$sql = "CREATE TABLE IF NOT EXISTS ".$InputArray['mysql_dbase_table']." (
`id` int(11) NOT NULL AUTO_INCREMENT,
`acro` varchar(25) NOT NULL,
`time` varchar(25) NOT NULL,
`date` varchar(25) NOT NULL,
`note` varchar(1024) NOT NULL,
`prio` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
$create = mysql_query($sql);
if (!$create) {
echo "Error creating table: " . mysql_error() . "\n";
}
}// End of Function GetMyConnection
function closeConnection() {
$terminate = mysql_close();
if ($terminate) {
echo "Connection terminated\n";
}
else {
echo "Error terminating connection: " . mysql_error() . "\n";
}
}//End of function closeConnection
// create the function
function GetTodoList($acro) {
global $InputArray;
GetMyConnection();
if (!$acro) {
return new soap_fault('Client', '', 'No data received!');
}
else {
$dbase_select = mysql_select_db($InputArray['mysql_dbase']);
$get = mysql_query("SELECT * FROM " . $InputArray['mysql_dbase_table'] . " WHERE `acro` = '" . $acro . "'");
if($get === FALSE) {
echo "Could not retrieve data from: " . $InputArray['mysql_dbase_table'] . " due to: " . mysql_error() . "\n";
}
else {
while($total = mysql_fetch_array($get)) {
$Data[] = array('id' => $total['id'],
'acro' => $total['acro'],
'time' => $total['time'],
'date' => $total['date'],
'note' => $total['note'],
'prio' => $total['prio']);
}
}
}
return $Data;
closeConnection();
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>