NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Soap client does not return the array


Joined: 08 Jan 2009
Posts: 4
Reply with quote
I am learning to write Soap service for a function which returns an array.The code is pasted below.I am not able to get the
array from the function.
B.php
Code:

<?php
class B
{
   function get()
   {       
        $input=array('G','B','K');       
        return $input;   
        }
}

?>

server.php
Code:
<?php 
  require('B.php'); 
  require('nusoap.php');
 
//Create the server instance
  $server=new soap_server(); 

//intializing the WSDL support
   $server->configureWSDL('Inputwsdl','urn:Inputwsdl');

//define class properties
   $server->wsdl->addComplexType(
                                 'Input      ',     
                                 'complexType',     
                                 'array',           
                                 '',                 
                                 'SOAP-ENC:Array',   
                                 array(),         
                                                               
                                 array(
                                       array('ref'=>'SOAP-ENC:arrayType',
                                             'wsdl:arrayType'=>'tns:input[]')                                       
                                             
                                  ),
                                 'tns:input'
                                 );

//Register the method to expose
  $server->register(
                    'B.get',                         
                     array(),                     
                     array('return'=>'tns:input')                     
                    );

  //calling the method
    B::get(); 
 
  // 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
Code:
<?php
require_once('nusoap.php');
include('B.php');

$client = new soapclient('http://localhost/server.php?wsdl');
        }
//call for the method
$return = $client->call('B.get',array());
print_r($return);

?>


The soap client does not outputs the array.I am confused.Can anyone please tell what the problem is?i am not able to figure out.
Thanks
View user's profileFind all posts by Ms.RanjanSend private message


Joined: 08 Jan 2009
Posts: 4
Reply with quote
After reading the previous post in this forum and few other sites on Nusoap




I came to a conclusion that a possible mistake might be in defining the complextype.so I have made few improvements in
the code which I have pasted below.
B.php
Code:
<?php
class B
{
   function get()
   {       
        return array('inp'=>'G','oup'=>'B','res'=>'K');       
           
        }
}

?>


server.php
Code:
<?php 
  require('B.php'); 
  require('nusoap.php');
 
//Create the server instance
  $server=new soap_server(); 

//intializing the WSDL support
   $server->configureWSDL('Inputwsdl','urn:Inputwsdl');

//define class properties   
   $server->wsdl->addComplexType(
                                 'Ret',
                                 'complexType',
                                 'struct',
                                 'all',
                                 '',
                                 array(
                                       'inp'=>array('name'=>'inp',type=>'xsd:string'),
                                       'oup'=>array('name'=>'oup',type=>'xsd:string'),
                                       'res'=>array('name'=>'res',type=>'xsd:string')
                                       )
                  );
   $server->wsdl->addComplexType(
                                 'ArrayofRet',      //name of the array
                                 'complexType',      //type class
                                 'array',            //type of the structure
                                 '',                 //compositor
                                 'SOAP-ENC:Array',   //Restriction Base
                                 array(),            //element parameter is blank
                                 //the attr parameter is an array instead of struct                                 
                                 array(
                                       array('ref'=>'SOAP-ENC:arrayType',
                                             'wsdl:arrayType'=>'tns:Ret[]')                                       
                                             
                                  ),
                                 'tns:Ret'
                                 );

//Register the method to expose
  $server->register(
                    'B.get',                         
                     array(),                     
                     array('return'=>'tns:Ret')                     
                    );

  //calling the method
    B::get(); 
 
  // 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);
?>


The client code is same as the one posted in previous post above.But still i could not get the array or output.
Any kind of lead on how to solve the problem will be of great help.since i am working on project of creating webservices for a php application using Nusoap.Whatever code i have pasted is just a sample one..am yet to work on the main one,i am just stuck up with this..

Thanks
View user's profileFind all posts by Ms.RanjanSend private message


Joined: 08 Jan 2009
Posts: 4
Reply with quote
The output which i get is pasted below.


Request
POST /forums/server.php?wsdl HTTP/1.0
Host: localhost
User-Agent: NuSOAP/0.7.3 (1.114)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: ""
Content-Length: 460
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns7762:B.get xmlns:ns7762="http://tempuri_org"></ns7762:B.get></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
HTTP/1.1 200 OK
Date: Fri, 09 Jan 2009 19:41:42 GMT
Server: Apache/2.2.11 (Win32) PHP/5.2.8
X-Powered-By: PHP/5.2.8
Content-Length: 2544
Connection: close
Content-Type: text/xml; charset=ISO-8859-1

<br />
<b>Notice</b>: Use of undefined constant type - assumed 'type' in <b>C:\wamp\www\forums\server.php</b> on line <b>19</b><br />
<br />
<b>Notice</b>: Use of undefined constant type - assumed 'type' in <b>C:\wamp\www\forums\server.php</b> on line <b>20</b><br />
<br />
<b>Notice</b>: Use of undefined constant type - assumed 'type' in <b>C:\wamp\www\forums\server.php</b> on line <b>21</b><br />

<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:Inputwsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:Inputwsdl">
<types>
<xsd:schema targetNamespace="urn:Inputwsdl"
>
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
<xsd:complexType name="Ret">
<xsd:all>
<xsd:element name="inp" type="xsd:string"/>
<xsd:element name="oup" type="xsd:string"/>
<xsd:element name="res" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ArrayofRet">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:Ret[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
</types>
<message name="B.getRequest"></message>
<message name="B.getResponse">
<part name="return" type="tns:Ret" /></message>
<portType name="InputwsdlPortType">
<operation name="B.get">
<input message="tns:B.getRequest"/>
<output message="tns:B.getResponse"/>
</operation>
</portType>
<binding name="InputwsdlBinding" type="tns:InputwsdlPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="B.get">
<soap:operation soapAction="http://localhost/forums/server.php/B.get" style="rpc"/>
<input><soap:body use="encoded" namespace="" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
<output><soap:body use="encoded" namespace="" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
</operation>
</binding>
<service name="Inputwsdl">
<port name="InputwsdlPort" binding="tns:InputwsdlBinding">
<soap:address location="http://localhost/forums/server.php"/>
</port>
</service>
</definitions>

I know the Notice part which i get can be turned of which change the php.ini settings,the output which i am interested right now
View user's profileFind all posts by Ms.RanjanSend private message
Soap client does not return the array
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic