-1

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.

Thanos
  • 1,618
  • 4
  • 28
  • 49
  • Please, explain this: `soapclient('http://var/www/connection.php?wsdl',true);` – Daniele Vrut Oct 31 '13 at 09:14
  • @Lame-up-duck I am not sure but on my browser the path appears as: file:///var/www/connection.php This is why I assumed that by adding the: http:// in the front will work. – Thanos Oct 31 '13 at 12:56
  • You are right I did understand what you mean: I entered on the url: localhost/connectio.php and the file was executed for me. So I replaced the line with '/localhost/connection.php?wsdl' but still the same error. What I am doing wrong now. I am confused I thought that this was my mistake. Thank you in advance for your time and effort. – Thanos Oct 31 '13 at 13:29

2 Answers2

1

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();
?>
Thanos
  • 1,618
  • 4
  • 28
  • 49
0

Your URL for the SOAP is trying to access a local file path rather than a URL

If you open the URL you've specified in a browser you should get back a (possibly large) chunk of XML. I can almost guarantee that you would get nothing apart from a 404 error

For the SOAP connection you have to use the URL specified by the webserver rather than a local file path (unless you replace http:// with file:/// - that may work).

If your webserver exposes a URL (e.g., http://localmachine) and the WSDL is hosted in a subfolder (e.g., soapstuff) then the URL you would need to enter into the $client=new soapclient line would be something like http://localmachine/soapstuff?wsdl

DaveyBoy
  • 2,928
  • 2
  • 17
  • 27
  • Based on your suggestion I replaced the: http://var/www/connection.php?wsdl with: http://file///var/www/connection.php?wsdl and still I am getting the same error. Is this format correct? Thanks in advance for your time and effort. – Thanos Oct 31 '13 at 13:06
  • I only said it _might_ work which, it appears, it didn't. Use the URL which it is being exposed as by the web server. Check the set up of the web server to find the base URL and go from there. Also, if you Google "nusoap tutorial" the first 4 results should give you a good idea of what you need to do – DaveyBoy Oct 31 '13 at 13:21
  • I was wrong, I did understand what you mean: I entered the url: localhost/connectio.php and the file was executed for me. So I replaced the line with '/localhost/connection.php?wsdl' but still the same error. What I am doing wrong now. I am confused I thought that this was my mistake. – Thanos Oct 31 '13 at 13:30
  • Check the tutorials you can get. They show you much more than I ever could – DaveyBoy Oct 31 '13 at 13:56
  • Dear Davey, I did check the tutorials that you recommended to me. I have modified my code, but I still getting the same error I do not understand the reason. Do you see something wrong? Thanks in advance. – Thanos Nov 01 '13 at 02:45
  • Does you PHP installation have the SOAP extensions loaded? If so, try using `$client=new nusoap_client(...);`. The PHP SOAP functions use an class called `SoapClient` which matches the error you're getting. To be honest, try using the PHP SOAP extension as it is faster due to it being compiled rather than interpreted. – DaveyBoy Nov 04 '13 at 10:16