Question

I'm trying to do an example web service with NuSOAP in PHP, and I built this example class:

<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the server instance
$server = new soap_server;
// Register the method to expose
$server->register('hello');
// Define the method as a PHP function
function hello($name) {
    return 'Hello, ' . $name;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

and this class for the client:

<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new soapclient('http://localhost/webServiceResta.php');
// Call the SOAP method
$result = $client->call('hello', array('name' => 'Scott'));
// Display the result
print_r($result);
?>

but I seem to get this error, when I run the script:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/webServiceResta.php' : Start tag expected, '<' not found in /opt/lampp/htdocs/prueba.php:5 Stack trace: #0 /opt/lampp/htdocs/prueba.php(5): SoapClient->SoapClient('http://localhos...') #1 {main} thrown in /opt/lampp/htdocs/prueba.php on line 5

I'm using XAMPP on ubuntu, and all the files are in the right place.

Was it helpful?

Solution

Using NuSoap so you need to call nusoap_client :)

$client = new nusoap_client('http://localhost/webServiceResta.php');

OTHER TIPS

You're sending data (Hello,...) that's not proper XML, moreso not proper SOAP WSDL format.

See: http://www.w3.org/TR/wsdl#_wsdl

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top