11

Hi i am using this code for nusoap server but when i call the server in web browser it shows message "This service does not provide a Web description" Here is the code

<?
//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();
?>

An help ...

h_a86
  • 764
  • 6
  • 14
  • 24
  • 1
    Well, did you ask the WSDL service to *do* anything? Or just visit it in a browser? All it is doing is telling you that there are no web pages to serve, but if you send it some SOAP that it is expecting, maybe it will work... – DaveRandom Feb 03 '12 at 14:29
  • i just want to show xml from my server.php file – h_a86 Feb 03 '12 at 14:32

3 Answers3

18

Please change your code to,

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

You didnt Define namespace..

Please see simple example here :-

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

Milap
  • 6,096
  • 8
  • 21
  • 44
  • As of PHP 7 $HTTP_RAW_POST_DATA is removed. So instead of $server->service($HTTP_RAW_POST_DATA); use $server->service(file_get_contents("php://input")); – Kristjan Adojaan Sep 11 '20 at 10:09
5

You can also use 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)
?>
Brian Kenya
  • 71
  • 1
  • 3
5

The web browser is not calling the Web service - you could create a PHP client :

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

This should display Hello, StackOverFlow

Update

To create a WSDL you need to add the following :

$server->configureWSDL(<webservicename>, <namespace>);
Manse
  • 36,627
  • 9
  • 75
  • 105