PhP Web服务开发

PhP Web服务开发,php,web-services,nusoap,Php,Web Services,Nusoap,我正在使用NuSOAP库开发一个PhP Web服务,但遇到了一个错误。我不能理解这个错误。如果有人知道解决方案,请帮助。下面是我的代码 ------ 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 exp

我正在使用NuSOAP库开发一个PhP Web服务,但遇到了一个错误。我不能理解这个错误。如果有人知道解决方案,请帮助。下面是我的代码

------ 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>';
        }
}
?>

实例化nusoap_客户端时:

您的构造函数参数“server.php”在我看来无效。它应该是一个有效的端点:


因此,无论您的“server.php”实际位于何处。如果它在运行client.php的同一台机器上,它可能类似于:
http://127.0.0.1/app/server.php

我认为您应该更准确地阅读NuSoap文档。我在您的代码中发现了一些错误:

  • 一个数组将被传递给您的方法,您已经为hello方法使用了字符串参数$name

  • 客户端应该调用一些实例或web url而不是HDD url(server.php)

  • 有关更多信息,请阅读NuSoap文档

    Error
    
    no transport found, or selected transport is not yet supported!
    
    new nusoap_client('server.php');
    
    $name['name']; //is correct!
    
    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!