简体   繁体   中英

Help with NuSoap - Creation of web service

I have been helplessly trying to create a web service in PHP using NuSoap for the past 2 days. However, after endlessly sifting through various tutorials and guides, i am still stuck with 10 lines of code that refuse to work.

Server :

// Pull in the NuSOAP code
require_once('./lib/nusoap.php');

// Create the server instance
$server = new soap_server;

// Initialize WSDL support
$server->configureWSDL('hellowsdl','http://mysite.com');

// Register the method to expose
$server->register('hello',
    array("params"=>"xsd:string"),
    array("result"=>"xsd:string"),
    'http://mysite.com'
);

// 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 the Client :

// Pull in the NuSOAP code
require_once('./lib/nusoap.php');

// Create the client instance
$client = new nusoap_client('http://localhost/nusoap/server.php?wsdl',true);

// Call the SOAP method
$result = $client->call('hello',array("name"=>"Scott"));

var_dump($result);

Gives me a bool(false)

Where am i going wrong ???

When you register the method, you are calling the parameter 'params' not 'name', the code should be:

$server->register('hello',
array("name"=>"xsd:string"),
array("result"=>"xsd:string"),
'http://mysite.com'
);

You shouldn't be getting false though, when I ran the code with the bug in it i still got

string(12) "Hello, "

(empty $name variable). Go to http://localhost/nusoap/server.php?wsdl and make sure you can see the WSDL from the same machine you are executing the client on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM