Nusoap - registering complex data types

Author Message

Geoff Bentley

Friday 07 December 2007 5:38:52 pm

I want to return an array of objects, but wondering how to register them. I'm currently using the "document" style as this seems to reference addComplexType in the WSDL class.

$server->register(  'getIssues', 
                    array( 'userId' => 'xsd:integer' ),
                    array( array( 'issueId' => 'xsd:integer', 'issueTitle' => 'xsd:string', 'issueDescription' => 'xsd:string', 'completed' => array('section' => 'xsd:integer' ))),
                    'urn:getIssueswsdl', 
                    'urn:getIssueswsdl#getIssues',
                    'document',
                    'encoded',
                    'Returns issues that relate to a particular user'
                ); 

Does anyone know the correct way to register complex data types in the Nusoap extension?

Igor Vrdoljak

Saturday 08 December 2007 2:51:28 pm

First define complex types that you need, then you can register web methods that use these types. Following code works for me:

$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:decimal'),
        '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'
);

$server->register(
   'GetProductsByCode',
   array('user'=>'xsd:string','password'=>'xsd:string','product_code'=>'xsd:string'),
   array('return'=>'tns:ProductArray'),
   $NAMESPACE);

Cheers

http://www.netgen.hr/eng
http://twitter.com/ivrdoljak

Geoff Bentley

Monday 10 December 2007 2:18:09 pm

Awesome! Many thanks Igor!

Daniel Dinnie

Wednesday 05 March 2008 1:17:54 am

Hi

I found your post in google, and im pretty much working on the same thing, but I have a small problem.

I pretty much got to the point you are now, and it seems to work fine when I return multiple rows of data. But if I only return 1 row of data, I get this as my output

array(4) { ["faultcode"]=> string(6) "Server" ["faultactor"]=> string(0) "" ["faultstring"]=> string(26) "unable to serialize result" ["detail"]=> string(0) "" }

Does anyone know why this is happening?
Can anyone help me please?

Thanks in advance

Samudaya Nanayakkara

Tuesday 21 April 2009 4:05:39 am

<b>I have a question regarding a identifying the client by server. When I write a simple helloworld server and client codes all wsdl and other functions are working. But I want to identify the requesting client in server code and respond (To set in return value in hellowold function) that client address back to client. Please help me to solve this. </b>


My nusoap.php in lib folder and all code in 'http://localhost/services/'


<b>Cleint code:</b>
<i>require_once('./lib/nusoap.php');
$client = new nusoap_client('http://localhost/services/server.php?wsdl', 'true');
echo $result = $client->call('helloworld'); </i>



<b>Server code: (server.php) </b>
<i>require_once('lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('hellowsdl','urn:hellowsdl');

$server->register('helloworld',
array('name' = 'xsd:string'),
array('return' = 'xsd:string'),
'urn:hellowsdl',
'urn:hellowsdl#hello',
'rpc',
'encoded',
'Says hello to the caller'
);

function helloworld()
{
return "Hi, ";
// I want to return requester(Client) address (Ip or url) here..................
// Return (This is your address.............)
}
// 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);</i>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 11:02:08
Script start
Timing: Jan 18 2025 11:02:08
Module start 'layout'
Timing: Jan 18 2025 11:02:08
Module start 'content'
Timing: Jan 18 2025 11:02:09
Module end 'content'
Timing: Jan 18 2025 11:02:09
Script end

Main resources:

Total runtime0.7365 sec
Peak memory usage4,096.0000 KB
Database Queries67

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 589.4453152.6250
Module start 'layout' 0.00610.0031 742.070339.4453
Module start 'content' 0.00920.7248 781.5156648.9219
Module end 'content' 0.73410.0024 1,430.437516.1563
Script end 0.7365  1,446.5938 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.5233160.0002
Check MTime0.00140.1916160.0001
Mysql Total
Database connection0.00110.153610.0011
Mysqli_queries0.668290.7253670.0100
Looping result0.00120.1618650.0000
Template Total0.700995.220.3504
Template load0.00190.259720.0010
Template processing0.699094.897620.3495
Template load and register function0.00020.026110.0002
states
state_id_array0.00190.252710.0019
state_identifier_array0.00200.276720.0010
Override
Cache load0.00170.2361610.0000
Sytem overhead
Fetch class attribute can translate value0.00060.079540.0001
Fetch class attribute name0.00170.228870.0002
XML
Image XML parsing0.00450.617640.0011
class_abstraction
Instantiating content class attribute0.00000.002180.0000
General
dbfile0.00410.5528220.0002
String conversion0.00000.001440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
8content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 22
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs