Nusoap - registering complex data types

Nusoap - registering complex data types

Friday 07 December 2007 5:38:52 pm - 4 replies

Modified on Friday 07 December 2007 5:40:44 pm by Geoff Bentley

Author Message

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>

You must be logged in to post messages in this topic!

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