NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Please help defining a complexType of mine


Joined: 26 Sep 2007
Posts: 6
Reply with quote
Hi soapers,
I've been playing with this stuff for 3 days. I've learned lots of things also applied them with success. But there is one thing that i couldn't succeed and it seems in the end i'll go back to xml-rpc just because of this issue. So please help me or this will be a huge disappointment for me, many thanks.

Here is what i want:

I've a function that gets an sql select statement and returns assoc array of the whole resultset:
Code:

function query($sql) {
    $result = mysql_query($sql);
    if (!$result) {
        global $server;
        $server->fault('Server', mysql_errno() . ':' . mysql_error());
    } else {
        $response = array();

        while ($row = mysql_fetch_assoc($result)) {
            array_push($response, $row);
        }

        return $response;
    }
}


How can i register this function with wsdl support?
Thanks.
View user's profileFind all posts by sempsteenSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
see links to the samples published on this forum

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 26 Sep 2007
Posts: 6
Reply with quote
Hi dmitri,
I've looked lots of examples around the web including this forum but couldn't find a solution yet.
I've no problem defining complex types that's all structures (keys, value types) are known.
But how do i define a complex structure that is mapping a database row (variant keys, variant values).

I've tried this:
Code:

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

This works with a nusoap client but not with a .NET client.
Here i can't go any further with QueryRow definition because it doesn't have a fixed structure, it has the structure of the database table that's returned by executing the sql statement. So i still need your help.
Thanks.
View user's profileFind all posts by sempsteenSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
I'm not sure if variants (in VB terms) are supported by soap standards itself. Also, from your sample it looks like you use mysql. For sure it does not support variants too. Finally, php uses strings/int/float/array for storing values. Where the variants come from?
Finally, if you need to pass a value which type is now known beforehand, you can always map it into string and pass as string, it's portable the most.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 26 Sep 2007
Posts: 6
Reply with quote
Hi dmitri,
By variant i mean it changes, i didn't mean as a variable type. Sorry for my english.
The function gets a string which is a select sql statement and returns the resultset.
For example user can call this function with this:

select * from table1;

or

select * from table1 as t1 left join table2 as t2...

or

select id from table1

each resultset is different, i don't know which columns, data types it has.
how can i define my function's return value type in wsdl with nusoap?

thanks.
View user's profileFind all posts by sempsteenSend private message


Joined: 26 Sep 2007
Posts: 6
Reply with quote
any hope?
View user's profileFind all posts by sempsteenSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
I have very little to add to what you have already replied. The problem is more of soap standard. It can't work "this time with endpoint will work with this set of parameters and next time it will work with totally different one". What you can is define two dimensional array of _STRINGS_ and return it as a resultset. In this case you'll have to convert all fields returned from database to strings and put them into the array of arrays.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 26 Sep 2007
Posts: 6
Reply with quote
scalar data types are not important for me, it may all be string.
can't i just say "this function returns an array" like:

Code:

$server->register(
    'query', // method name
    array('sql' => 'xsd:string'), // input parameters
    array('return' => 'xsd:array'), // output parameters
    'urn:database', // namespace
    'urn:database#query', // soapaction
    'rpc', // style
    'encoded', // use
    'bla bla.' // documentation
);
View user's profileFind all posts by sempsteenSend private message
Please help defining a complexType of mine
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