francis

Soap4r woes

posted Tuesday, 20 May 2008
Just in case this burns someone else

Talking to a web service that returns an array of mixed complex types (ooh goody!)

soap4r returns a lot of SOAP::Mapping::Object

These pretend to be a kind of hash (of hashes of hashes if you go really deep), so I could get my proposal back by the rather horrible

response.submitResult.returnMsg['Proposal']

(lots of console work required to get this far .. :))

I needed the proposal's ID and it was nowhere to be seen. When I looked at the wire trace it told me that the proposal ID was being returned as an attribute of the Proposal XML node.

Lots of pain and headscratching later discovered a blog post talking about the semi-hidden __xmlattr method, this is a proper hash but it is indexed using the qualified name class XSD::QName

So, to get the ID out we end up with ...

proposal_id_key = XSD::QName.new(nil,'proposalID')
response.submitResult.returnMsg['Proposal'].__xmlattr[proposal_id_key]

Let the joy be unconfined ... SOAP is another unnecessary PIA. Most of the time you *could* just post XML direct using HTTP(S). I can't see any benefit for the additional complexity.

If we didn't have soap4r I'd still be banging my head on the desk so +1 for that ...

Top tip, you can set $DEBUG=true in the console to get the wire trace.

links: digg this    del.icio.us    technorati