首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PhP PhP服务开发

PhP PhP服务开发
EN

Stack Overflow用户
提问于 2012-09-29 13:59:43
回答 2查看 3.1K关注 0票数 0

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

代码语言:javascript
运行
复制
------ 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>';
        }
}
?>

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

代码语言:javascript
运行
复制
Error

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

回答 2

Stack Overflow用户

发布于 2012-09-29 14:24:24

实例化nusoap_client时:

代码语言:javascript
运行
复制
new nusoap_client('server.php');

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

docs

所以,无论你的'server.php‘实际在哪里。如果它在运行client.php的同一台机器上,可能是这样的:http://127.0.0.1/app/server.php

票数 0
EN

Stack Overflow用户

发布于 2012-09-29 14:40:22

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

一个数组将被传递给你的方法,并且你已经为方法使用了字符串参数$name。

$name'name';//is correct!

  • Client应该调用某些实例或web url,而不是硬盘url(server.php)。

新的nusoap_client(SOME_IP_OR_HOSTNAME .'/server.php');//正确!require_once 'server.php';新nusoap_client($server);//正确!新建nusoap_client(WSDL_INSTANCE_OBJECT);//正确!new nusoap_client('server.php');//不正确!

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12650353

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档