In developing a soap client proxy, which return structure is easier to use and more sensible?

Posted by cori on Programmers See other posts from Programmers or by cori
Published on 2012-12-14T20:12:32Z Indexed on 2012/12/14 23:21 UTC
Read the original article Hit count: 161

Filed under:
|

I'm writing (in PHP) a client/proxy for a SOAP web service. The return types are consistently wrapped in response objects that contain the return values. In many cases this make a lot of sense - for instance when multiple values are being returned:

GetDetailsResponse Object 
(
    Results Object
    (
        [TotalResults] => 10
        [NextPage]     => 2
    )

    [Details] => Array
    (
        [0] => Detail Object
        (
            [Id] => 1
        )
    )
)

But some of the methods return a single scalar value or a single object or array wrapped in a response object:

GetThingummyIdResponse Object
(
    [ThingummyId] => 42
)

In some cases these objects might be pretty deep, so getting at properties within requires drilling down several layers:

$response->Details->Detail[0]->Contents->Item[5]->Id

And if I unwrap them before passing them back I can strip out a layer from consumers' code.

I know I'm probably being a little bit of an Architecture Astronaut here, but the latter style really bug me, so I've been working through my code to have my proxy methods just return the scalar value to the client code where there's no absolute need for a wrapper object.

My question is, am I actually making things more difficult for the consumers of my code? Would I be better off just leaving the return values wrapped in response objects so that everything is consistent, or is removing unneccessary layers of indirection/abstraction worthwhile?

© Programmers or respective owner

Related posts about php

Related posts about soap