0

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

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

当我运行客户端时,出现以下错误。

Error

no transport found, or selected transport is not yet supported!
4

2 回答 2

0

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

  1. 一个数组将被传递给您的方法,并且您已将字符串参数 $name 用于 hello 方法。

    $name['name']; //is correct!
    
  2. 客户端应该调用一些实例或 web url 而不是 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!
    

更多信息请阅读 NuSoap 文档。

于 2012-09-29T06:40:21.633 回答
0

当您实例化 nusoap_client 时:

new nusoap_client('server.php');

您的构造函数参数'server.php'对我来说似乎无效。它应该是一个有效的端点:

文档

因此,无论您的“server.php”实际在哪里。也许如果它在运行 client.php 的同一台机器上,它可能是这样的:http://127.0.0.1/app/server.php

于 2012-09-29T06:24:24.130 回答