0

I was developing a PhP webservice using NuSOAP library but facing an error. I couldn't understand the error. If anyone knows a solution, please help. Following is my code.

------ server.php ------

<?php

// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the server instance
$server = new soap_server;

// Register the method to expose
$server->register('hello');

    // Define the method as a PHP function
    function hello($name) 
    {
        return 'Hello, ' . $name;   
    }

    // Use the request to (try to) invoke the service
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? 
           $HTTP_RAW_POST_DATA : '';

    $server->service($HTTP_RAW_POST_DATA);

?>

------ client.php ------

<?php

// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('server.php');
// Check for an error
$err = $client->getError();

if ($err) 
{
   // Display the error
   echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
   // At this point, you know the call that follows will fail
}

// Call the SOAP method
$result = $client->call('hello', array('name' => 'Scott'));

// Check for a fault    
if ($client->fault) 
{
        echo '<h2>Fault</h2><pre>';
        print_r($result);
        echo '</pre>';
}
 else
 {

    // Check for errors
        $err = $client->getError();
        if ($err) 
    {
            // Display the error
            echo '<h2>Error</h2><pre>' . $err . '</pre>';
        }
     else 
     {
            // Display the result
            echo '<h2>Result</h2><pre>';
            print_r($result);
            echo '</pre>';
        }
}
?>

When I run the client, following error arises.

Error

no transport found, or selected transport is not yet supported!
parsaya
  • 67
  • 1
  • 4
Ammar
  • 1,811
  • 5
  • 26
  • 60

2 Answers2

0

When you instantiate the nusoap_client:

new nusoap_client('server.php');

Your constructor parameter 'server.php' does not look valid to me. It's supposed to be a valid endpoint:

docs

So, wherever your 'server.php' actually is. Maybe if it's on the same machine running client.php, it might be something like: http://127.0.0.1/app/server.php

Shad
  • 15,134
  • 2
  • 22
  • 34
0

I think you should read NuSoap documents more accurate. Some wrongs i found in your code:

  1. An array will be passed to your method and you've used string parameter $name for hello method.

    $name['name']; //is correct!
    
  2. Client should call some instances or web url not HDD url(server.php).

    new nusoap_client(SOME_IP_OR_HOSTNAME . '/server.php'); //is correct!
    
    require_once 'server.php';
    new nusoap_client($server); //is correct!
    
    new nusoap_client(WSDL_INSTANCE_OBJECT); //is correct! 
    
    new nusoap_client('server.php'); //is incorrect!
    

for more information read NuSoap document.

Mohammad Emami
  • 68
  • 1
  • 10