nusoap简单的服务器

时间:2012-02-03 14:24:24

标签: php nusoap

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

帮助......

3 个答案:

答案 0 :(得分:16)

请将您的代码更改为,

<?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/

答案 1 :(得分:4)

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>);

答案 2 :(得分:4)

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