帮助NuSOAP获取Web服务

时间:2010-11-18 01:58:16

标签: php web-services xampp nusoap

我正在尝试用PHP中的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

我在ubuntu上使用XAMPP,所有文件都在正确的位置。

2 个答案:

答案 0 :(得分:4)

使用NuSoap,因此您需要致电nusoap_client:)

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

答案 1 :(得分:0)

您发送的数据(Hello,...)不是正确的XML,也不是正确的SOAP WSDL格式。

请参阅:http://www.w3.org/TR/wsdl#_wsdl