PHP Web Service NuSOAP complex type

橙三吉。 提交于 2019-12-06 15:52:09

问题


I wrote php web service using NuSOAP and client script. I used array complex type to return an array of complex type, but it's print nothing!!

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 return product array

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);
}
?>

the client.php print the function result

pleas help me. thanks!


回答1:


IN here your WSDL is not working. Go to your ..../server.php?wsdl. Nothing is displaying. Use $server->service(isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''); before the php end tag(?>). That would do you the thing. After saving just run your client. It will display your array.



来源:https://stackoverflow.com/questions/14001916/php-web-service-nusoap-complex-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!