4

我正在尝试在 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,所有文件都在正确的位置。

4

2 回答 2

4

使用 NuSoap 所以你需要打电话nusoap_client:)

$client = new nusoap_client('http://localhost/webServiceResta.php');
于 2011-09-03T19:35:45.780 回答
0

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

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

于 2010-11-18T02:02:23.297 回答