【问题标题】:nusoap simple servernusoap 简单服务器
【发布时间】:2012-02-26 03:46:45
【问题描述】:

您好,我正在将此代码用于 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();
?>

帮助...

【问题讨论】:

  • 那么,您有没有要求 WSDL 服务任何事情?或者只是在浏览器中访问它?它所做的只是告诉您没有要服务的网页,但是如果您向它发送一些它所期望的 SOAP,也许它会起作用...
  • 我只想从我的 server.php 文件中显示 xml

标签: php nusoap


【解决方案1】:

请将您的代码更改为,

<?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"));
【解决方案2】:

Web 浏览器没有调用 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>);

【讨论】:

    【解决方案3】:

    你也可以使用 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)
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      相关资源
      最近更新 更多