nusoap简单服务器

11

你好,我正在使用此代码作为nusoap服务器,但是当我在Web浏览器中调用服务器时,它显示消息“此服务未提供Web描述”。以下是代码:

<?
//call library
require_once ('lib/nusoap.php');

//using soap_server to create server object
$server = new soap_server;

//register a function that works on server
$server->register('hello');

// create the function
function hello($name)
{
if(!$name){
return new soap_fault('Client','','Put your name!');
}

$result = "Hello, ".$name;
return $result;
}

// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);

exit();
?>

一份帮助文档不应该只是代码片段的集合,而应该提供解决特定问题所需的全部信息。这些信息包括背景知识、概念解释、附加资源和对可能出现的错误或警告的说明。


1
你有让 WSDL 服务去 什么吗?还是只是在浏览器中访问它?它所做的只是告诉你没有要提供的网页,但如果你发送一些它期望的 SOAP,也许它会工作... - DaveRandom
我只想在我的server.php文件中显示XML。 - h_a86
3个回答

18

请将您的代码更改为以下内容:

<?php
//call library
require_once('nusoap.php');
$URL       = "www.test.com";
$namespace = $URL . '?wsdl';
//using soap_server to create server object
$server    = new soap_server;
$server->configureWSDL('hellotesting', $namespace);

//register a function that works on server
$server->register('hello');

// create the function
function hello($name)
{
    if (!$name) {
        return new soap_fault('Client', '', 'Put your name!');
    }
    $result = "Hello, " . $name;
    return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>

您没有定义命名空间。

请参见此处的简单示例:

http://patelmilap.wordpress.com/2011/09/01/soap-simple-object-access-protocol/


从PHP 7开始,$HTTP_RAW_POST_DATA已被移除。因此,不要再使用$server->service($HTTP_RAW_POST_DATA);,而是使用$server->service(file_get_contents("php://input"));。 - Kristjan Adojaan

5

网页浏览器没有调用 Web 服务 - 您可以创建一个 PHP 客户端:

// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new soapclient('your server url');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'StackOverFlow'));
// Display the result
print_r($result);

这应该显示Hello, StackOverFlow 更新
要创建WSDL,您需要添加以下内容:
$server->configureWSDL(<webservicename>, <namespace>);

5
您可以使用nusoap_client。
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('your server url'); // using nosoap_client
// Call the SOAP method
$result = $client->call('hello', array('name' => 'Pingu'));
// Display the result
print_r($result)
?>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接