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!
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:
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
I think you should read NuSoap documents more accurate. Some wrongs i found in your code:
An array will be passed to your method and you've used string parameter $name for hello method.
$name['name']; //is correct!
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.