|
| Error retrieving data from NuSOAP webservice | |
Joined: 08 Mar 2007 |
Posts: 5 |
|
|
|
Posted: Wed Mar 07, 2007 3:19 pm |
|
|
|
|
|
I'm working on writing a webservice that queries a Ventrilo voice server & returns a list of channels & users for that server. I have written this as a stand-alone page (so the functionality of the page is working), but I'm interested in breaking it out into a webservice.
So, after stumbling around, I found NuSOAP & started messing with it. I'm normally a .Net developer, but have been using PHP for a couple months now, so please don't leave any "simple" information out. I may have missed something basic.
Anyway, the problem stems from the fact that the data I retrieve for the status has a "recursive" structure:
Main Channel
- User1
- User2
- SubChannel1
--- User3
--- SubChannel2
----- User4
I need to find a way to pull all of this back & still keep the hierarchy of the channels.
So, I created the following "ComlexTypes" in my webservice:
$server->wsdl->addComplexType(
'ventUser',
'complexType',
'struct',
'all',
'',
array(
'userName' => array('name' => 'userName',
'type' => 'xsd:string'),
'userFlags' => array('name' => 'userFlags',
'type' => 'xsd:string'),
'userComments' => array('name' => 'userComments',
'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'ventChannel',
'complexType',
'struct',
'all',
'',
array(
'channelName' => array('name' => 'channelName',
'type' => 'xsd:string'),
'channelLinkURL' => array('name' => 'channelLinkURL',
'type' => 'xsd:string'),
'channelUsers' => array('name' => 'channelUsers',
'type' => 'tns:ventUser[]'),
'channelSubchannels' => array('name' => 'channelSubchannels',
'type' => 'tns:ventChannels[]')
)
);
$server->wsdl->addComplexType(
'ventChannels',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:ventChannel[]')
),
'tns:ventChannel'
); |
I then call register my function: $server->register('getVentStatus',
array('inputStringArray'=>'tns:ArrayOfstring'),
array('return'=>'tns:ventChannels'),
'http://soapinterop.org/');
|
If I attempt to call this page I get the following error:
"Fault: Array ( [faultcode] => Server [faultactor] => [faultstring] => unable to serialize result [detail] => )"
http://mywebserver/VentStatusService/VentStatusClient.php
On a different site, I found a function to encode a multi-dimensional array into a string & then to decode it. If I use this method, you can view the data that my function is trying to send back.
http://mywebserver/VentStatusService/VentStatusClientEncoded.php
So, I'm not sure if that's enough information, but I hate to babble on too much. Please let me know if I've made a simple mistake, or if you need more information.
Thanks,
Ian Cazabat
|
|
|
| | |
|
| | |
Joined: 08 Mar 2007 |
Posts: 5 |
|
|
|
Posted: Thu Mar 08, 2007 5:19 pm |
|
|
|
|
|
Thanks for your response & I hope this is what you're wanting:
function getVentStatus( $serviceParams ) { //input array or parameters
$stat->m_cmdhost = $serviceParams['serverName']; //$serverAddress;
$stat->m_cmdport = $serviceParams['queryPort']; //$serverPort; // Port to be statused.
$stat->m_cmdpass = $serviceParams['serverPass']; //$serverPwd; // Status password if necessary.
(additional code removed for brevity)
} |
$serviceParams = array('serverName' => 'vent.lonecoders.info', 'queryPort' => '3784', 'serverPass'=>'');
$result = $client->call(
'getVentStatus', // method name
array('serviceParams' => $serviceParams) // input parameters
); |
Again, it's not that I'm stupid, just "more than a little" confused.
Thanks Again,
Ian
|
|
|
| | |
Site Admin
Joined: 13 Jul 2003 |
Posts: 8344 |
|
|
|
Posted: Fri Mar 09, 2007 7:55 am |
|
|
|
|
|
Quote: | array('inputStringArray'=>'tns:ArrayOfstring'), |
I can't find your definition for ArrayOfstring
Quote: | 'type' => 'tns:ventChannels[]') |
what did you mean by these brackets?
With example below it works quite good (I +changed+ input type as I found no definition in your sample):
SERVER (C:\Program Files\nusphere\PhpED\projects\tst.php):
<?
require_once('nusoap.php');
$server = new soap_server;
$server->configureWSDL('Test','http://soapinterop.org/');
$server->wsdl->addComplexType(
'ventUser',
'complexType',
'struct',
'all',
'',
array(
'userName' => array('name' => 'userName',
'type' => 'xsd:string'),
'userFlags' => array('name' => 'userFlags',
'type' => 'xsd:string'),
'userComments' => array('name' => 'userComments',
'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'ventChannel',
'complexType',
'struct',
'all',
'',
array(
'channelName' => array('name' => 'channelName',
'type' => 'xsd:string'),
'channelLinkURL' => array('name' => 'channelLinkURL',
'type' => 'xsd:string'),
'channelUsers' => array('name' => 'channelUsers',
'type' => 'tns:ventUser'),
'channelSubchannels' => array('name' => 'channelSubchannels',
'type' => 'tns:ventChannels')
)
);
$server->wsdl->addComplexType(
'ventChannels',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:ventChannel[]')
),
'tns:ventChannel'
);
function getVentStatus( $serviceParams ) { //input array or parameters
return array(0 => array('channelName' => 'samp of channelName',
'channelLinkURL' => 'samp of channelLinkURL',
'channelUsers' => array('userName' => 'samp of userName',
'userFlags' => 'samp of userFlags',
'userComments' => 'samp of userComments'
),
'channelSubchannels' => array()
),
1 => array('channelName' => 'samp of channelName2',
'channelLinkURL' => 'samp of channelLinkURL2',
'channelUsers' => array('userName' => 'samp of userName2',
'userFlags' => 'samp of userFlags2',
'userComments' => 'samp of userComments2'
)
),
'channelSubchannels' => array()
);
}
$server->register('getVentStatus',
array('inputStringArray'=>'xsd:string'),
array('return'=>'tns:ventChannels'),
'http://soapinterop.org/');
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ?
$HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?> |
CLIENT:
<?php
require_once('nusoap.php');
$wsdl = "http://localhost:8080/file:/C:/Program Files/nusphere/PhpED/projects/tst.php?wsdl";
$client = new soapclient($wsdl,"wsdl");
$result = $client->call(
'getVentStatus', // method name
array(array('serviceParams' => 'sample')) // input parameters
);
?> |
and it returned $result with arrays returned by the server's getVentStatus
|
_________________ The PHP IDE team
|
|
| | |
Joined: 08 Mar 2007 |
Posts: 5 |
|
|
|
Posted: Sun Mar 11, 2007 1:41 pm |
|
|
|
|
|
Thanks a bunch for your input!!! You helped me along the path to finding what was wrong. As it turned out, I was returning a "malformed" array. After running your code, I could see the array structure should be like this: Array
(
[0] => Array
(
[channelName] => *samp of channelName
[channelLinkURL] => samp of channelLinkURL
[channelUsers] => Array
(
[userName] => samp of userName
[userFlags] => samp of userFlags
[userComments] => samp of userComments
)
[channelSubchannels] => Array
(
)
)
[1] => Array
(
[channelName] => samp of channelName2
[channelLinkURL] => samp of channelLinkURL2
[channelUsers] => Array
(
[userName] => samp of userName2
[userFlags] => samp of userFlags2
[userComments] => samp of userComments2
)
[channelSubchannels] => Array
(
[0] => Array
(
[channelName] => samp of subChannelName3
[channelLinkURL] => samp of subChannelLinkURL3
[channelUsers] => Array
(
[userName] => samp of subChanUserName4
[userFlags] => samp of subChanUserFlags4
[userComments] => samp of subChanUserComments4
)
)
)
)
) |
Where mine was coming back like this: Array
(
[channelName] => MyVent
[channelLinkURL] => ventrilo://myvent.com/servername=MyVent
[channelUsers] =>
[channelSubchannels] => Array
(
[0] => Array
(
[channelName] => Lobby #1
[channelLinkURL] => ventrilo://myvent.com/servername=MyVent&channelname=Lobby #1
[channelUsers] =>
[channelSubchannels] => Array
(
)
)
[1] => Array
(
[channelName] => Lobby #2
[channelLinkURL] => ventrilo://myvent.com/servername=MyVent&channelname=Lobby #2
[channelUsers] =>
[channelSubchannels] => Array
(
)
)
[2] => Array
(
[channelName] => SRA1
[channelLinkURL] => ventrilo://myvent.com/servername=MyVent&channelname=SRA1
[channelUsers] =>
[channelSubchannels] => Array
(
)
)
[3] => Array
(
[channelName] => PVP #1
[channelLinkURL] => ventrilo://myvent.com/servername=MyVent&channelname=PVP #1
[channelUsers] =>
[channelSubchannels] => Array
(
)
)
[4] => Array
(
[channelName] => PVP #2
[channelLinkURL] => ventrilo://myvent.com/servername=MyVent&channelname=PVP #2
[channelUsers] =>
[channelSubchannels] => Array
(
)
)
[5] => Array
(
[channelName] => PVP #3
[channelLinkURL] => ventrilo://myvent.com/servername=MyVent&channelname=PVP #3
[channelUsers] =>
[channelSubchannels] => Array
(
)
)
)
) |
Needless to say, the FIRST element I passed in, wasn't an element in an array & so that screwed up the serialization. So, thank you VERY MUCH for setting me on the right path! It was a simple solution, once I could rule out what WASN'T wrong.
Thanks Again,
Ian
|
|
|
| | |
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
|
|
|
| |