繁体   English   中英

PhP Web服务开发

[英]PhP Webservices development

我正在使用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>';
        }
}
?>

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

Error

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

实例化nusoap_client时:

new nusoap_client('server.php');

您的构造函数参数'server.php'对我而言无效。 应该是有效的端点:

docs

因此,无论您的“ server.php”实际上在哪里。 也许如果它在同一台运行client.php的计算机上,则可能类似于: http://127.0.0.1/app/server.php : http://127.0.0.1/app/server.php

我认为您应该更准确地阅读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文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM