|
Posted by wagemage.pt on 05/22/06 14:36
I'm having some trouble with PEAR soap and a response from a webservice
when the number of results is one or more than one.
Versions are PHP 4.4.2-1build1, PEAR-1.4.6, SOAP-0.9.4 running in
Linux (Ubuntu Dapper)
When we have multiple items in the result, all goes well, and I can use
the result straight away (I do some JSON translation afterwards, but
that's beyond the scope of my question).
Multiple result:
Actual XML sent back from webservice (sniffed off the connection):
[snipped headers]
<GetChildCategoriesResult>
<item>
<CategoryId>1</CategoryId>
<Name>Cultura</Name>
<ParentCategoryId>0</ParentCategoryId>
</item>
<item>
<CategoryId>2</CategoryId>
<Name>Autom..veis</Name>
<ParentCategoryId>0</ParentCategoryId>
</item>
</GetChildCategoriesResult>
[snipped trailing markup]
How PEAR::SOAP translates:
array(2) {
[0]=>
object(stdClass)(3) {
["CategoryId"]=>
string(1) "1"
["Name"]=>
string(7) "Cultura"
["ParentCategoryId"]=>
string(1) "0"
}
[1]=>
object(stdClass)(3) {
["CategoryId"]=>
string(1) "2"
["Name"]=>
string(11) "Automóveis"
["ParentCategoryId"]=>
string(1) "0"
}
}
When I get a single item in the result, however, things go a little
differently - and I'd have to write some pretty silly code to be able
to actually use it "as is":
Single result:
Actual XML sent back from webservice (sniffed off the connection):
[snipped headers]
<GetChildCategoriesResult>
<item>
<CategoryId>3</CategoryId>
<Name>Carros</Name>
<ParentCategoryId>2</ParentCategoryId>
</item>
</GetChildCategoriesResult>
[snipped trailing markup]
How PEAR::SOAP translates it:
object(stdClass)(1) {
["item"]=>
&object(stdClass)(3) {
["CategoryId"]=>
string(1) "3"
["Name"]=>
string(6) "Carros"
["ParentCategoryId"]=>
string(1) "2"
}
}
As you can see, instead of an array of length one, I get an object with
an "item" property, with the expected object inside it. That's not (for
me, at least) the desired behaviour for the beast - is this a bug, a
miss-feature? Or is it supposed to work like that, and I have to write
a work-around for my purposes? Does anyone know of an already-written
workaround?
Thanks in advance for your time,
WageMage / Manuel
[Back to original message]
|