2012-12-22 40 views
0

我使用NuSOAP和客户端脚本编写了php web服务。我用数组复杂类型 返回一个复杂类型的数组,但它不打印任何东西!PHP Web服务NuSOAP复杂类型

server.php

<?php 
     // Pull in the NuSOAP code 
     require_once('nusoap-php5-0.9/lib/nusoap.php'); 
     ini_set ('soap.wsdl_cache_enabled', 0); 
     // Create the server instance 
     $server = new soap_server(); 
     // Initialize WSDL support 
     $server->configureWSDL('GetCus', 'urn:GetCus'); 



     $server->wsdl->addComplexType(
    'Product', 
    'complexType', 
    'struct', 
    'all', 
    '', 
    array(
     'Name' => array('name'=>'name','type'=>'xsd:string'), 
     'Code' => array('name'=>'product_number','type'=>'xsd:string'), 
    'Price' => array('name'=>'price','type'=>'xsd:int'), 
     'Ammount' => array('name'=>'quantity','type'=>'xsd:int') 
    ) 
); 

$server->wsdl->addComplexType(
    'ProductArray', 
    'complexType', 
    'array', 
    '', 
    'SOAP-ENC:Array', 
    array(), 
    array(
     array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Product[]') 
    ), 
    'tns:Product' 
); 



      // Register the method to expose 
     $server->register('GetProductsByCode',     // method name 
      array(),   // input parameters 
      array('return' => 'tns:ProductArray'), // output parameters tns:Customer 
      'urn:GetCus',       // namespace 
      'urn:GetCus#GetProductsByCode',     // soapaction 
      'rpc',         // style 
      'encoded',        // use 
      'Get Customer Information'  // documentation 
     ); 

    function GetProductsByCode() 
    { 
     $productArray=array(); 
     for($i=0; $i<5 ; $i++) 
     { 
      $product=array('Name' => 'somthing'.$i, 
      'Code' => '23456yui'.$i, 
      'Price' => 222*($i+1), 
      'Ammount' => 5+$i 
      ); 
      $productArray[]=$product; 
     } 
    return $productArray; 
    } 
?> 

server.php返回产品阵列

client.php

<?php 
require_once('nusoap-php5-0.9/lib/nusoap.php'); 
ini_set ('soap.wsdl_cache_enabled', 0); 
try{ 
    $sClient = new nusoap_client('http://localhost/DataBaseTest/nusoap_server2.php?wsdl','wsdl','','','',''); 
    $response = $sClient->call('GetProductsByCode',array(),'','', false,true); 
    print_r($response); 
} catch(SoapFault $e){ 
    var_dump($e); 
} 
?> 

的client.php打印功能结果

请帮我。 谢谢!

回答

0

在这里你的WSDL不工作。去你的..../server.php?wsdl。没有显示。使用$ server-> service(isset($ HTTP_RAW_POST_DATA)?$ HTTP_RAW_POST_DATA:''); php结束标记之前(?>)。那会做你的事情。保存后运行你的客户端。它会显示你的数组。