我有问题在蛋糕php 2.3中创建Web服务,我在我的网站上使用nusoap lib 我在Web服务输出中有错误 简单代码: 输出: 错误 响应不是text / xml类型:text / html
WebservicesController:
App::uses('AppController', 'Controller');
App::uses('Sanitize', 'Utility');
ini_set('soap.wsdl_cache_enabled', 0);
class WebservicesController extends AppController{
var $components = array('RequestHandler');
var $helpers = array('Text', 'Xml');
public $name = 'Webservices';
public $useTable = false;
public $uses = array();
public $autoRender = false;
public $layout = false;
function process()
{
Configure::write('debug',0);
Configure::write('Session.start', false);
App::import('Vendor', 'nusoap',array('file'=>'nusoap'.DS.'lib'.DS.'nusoap.php'));
$server = new soap_server();
$endpoint = 'http://localhost/mysite/webservices/process';
//initialize WSDL support
$server->configureWSDL('helloWorldwsdl', 'urn:helloWorldwsdl', $endpoint);
$server->soap_defencoding='UTF-8';
$server->decode_utf8 = false;
$this->RequestHandler->respondAs('xml');
//$this->layoutPath = 'xml';
$server->register('helloWorld', // method name
array('return' => 'xsd:string'), // output parameters
'urn:helloWorldwsdl', // namespace
'urn:helloWorldwsdl#helloWorld', // soapaction
'rpc', // style
'encoded', // use
'Says hello to the caller' // documentation
);
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
$this->autoRender = false;
exit();
}
function helloWorld() {
return 'Hello';
}
}
客户代码:
require_once('lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('http://localhost/mysite/webservices/process?wsdl');
$client->soap_defencoding='UTF-8';
$client->decode_utf8 = false;
// Check for an error
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
// At this point, you know the call that follows will fail
}
//======================================================
// Call the SOAP method
$result = $client->call('helloWorld') ;
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
答案 0 :(得分:1)
我尝试了你的例子,它在soap服务器中记录方法“helloworld”时正确添加了一个空数组 例如:
$server->register('helloWorld', // method name
array(), //input parameters
array('return' => 'xsd:string'), // output parameters
'urn:helloWorldwsdl', // namespace
'urn:helloWorldwsdl#helloWorld', // soapaction
'rpc', // style
'encoded', // use
'Says hello to the caller' // documentation