2010-11-18 99 views
4

我想PHP中的NuSOAP做榜樣的Web服務,我建這個例子類:幫助的NuSOAP爲Web服務

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

與此類客戶端:

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

但我似乎得到這個錯誤,當我運行該腳本:

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 

我使用的XAMPP在Ubuntu上,所有的文件都在鑽機高的地方。

+0

它的客戶端代碼,在新版本中它被重命名爲nusoap_client(); – Osukaa 2010-11-18 15:00:14

回答

4

使用的NuSOAP所以你需要調用nusoap_client :)

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