простой сервер nusoap - PullRequest
       8

простой сервер nusoap

9 голосов
/ 03 февраля 2012

Привет! Я использую этот код для сервера nusoap, но когда я вызываю сервер в веб-браузере, он показывает сообщение «Эта служба не предоставляет веб-описание». Вот код

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

16 голосов
/ 03 февраля 2012

Пожалуйста, измените свой код на,

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

4 голосов
/ 18 мая 2012

Вы также можете использовать 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)
?>
4 голосов
/ 03 февраля 2012

Веб-браузер не вызывает веб-сервис - вы можете создать клиент 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>);
...