运行基本nuSOAP教程时收到错误

时间:2014-08-12 13:14:13

标签: php web-services soap web nusoap

我正在尝试创建一个使用网站API从Web服务检索数据的网站。

' nuSOAP' PHP库似乎是一个完美的解决方法,所以我一直试图通过Scott Nichol的一个基本教程来调用NuSOAP'简介。

以下是server.php的代码:

<?php

// Pull in the NuSOAP code
require_once('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);

?>

...这是client.php的代码:

<?php

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

// Create the client instance
$client = new soapclient('http://localhost/beehive/server.php');

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

// Display the result
print_r($result);

?>

我有&#39; XAMMP&#39;已安装,所以当我通过浏览器调出client.php时,它应该显示一个基本页面,上面写着“你好,约翰&#39;但我收到以下错误消息:

致命错误:未捕获的SoapFault异常:[WSDL] SOAP-ERROR:解析WSDL:无法从&#39; ... / server.php&#39;加载:期望开始标记,&#39;&lt;&#39;在C:\ xampp \ htdocs \ beehive \ client.php中找不到:7堆栈跟踪:#0 C:\ xampp \ htdocs \ beehive \ client.php(7):SoapClient-&gt; SoapClient(&#39; http:在第7行的C:\ xampp \ htdocs \ beehive \ client.php中抛出了#1&gt; {main}

我认为我应该加载客户端页面而不是服务器,但如果我加载server.php,那么我收到错误消息&#39; 此服务不提供Web描述&#39;

我完全按照教程进行操作,无法弄清楚它为什么会抛出此错误;有人可以帮忙吗?

谢谢!

2 个答案:

答案 0 :(得分:1)

您收到的错误对您的错误说明非常重要。服务器没有以正确的格式进行响应,因此您的客户端会中断。

这里讨论了同样的错误: nusoap simple server

答案 1 :(得分:0)

您需要将客户端构造函数指向您的wsdl文件...

$client = new soapclient('http://localhost/beehive/server.php');