2013-07-12 88 views
0

我有問題,在蛋糕的PHP 2.3創建Web服務,我在網站 我使用的NuSOAP的lib我在Web服務輸出誤差 簡單的代碼: 輸出: 錯誤 響應的類型不是文本/ XML:text/html的輸出的NuSOAP web服務的蛋糕PHP 2.3

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>'; 
    } 
} 

回答

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