Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Describing hashes in WSDL?

by suaveant (Parson)
on Apr 25, 2005 at 19:59 UTC ( #451320=perlquestion: print w/replies, xml ) Need Help??

suaveant has asked for the wisdom of the Perl Monks concerning the following question:

Ok... this is on the bare edge of being a Perl question, bear with me...

I am trying to use Perl to publish a SOAP::Lite service that I can connect to from Macromedia Flash... I am reasonably sure that I should be able to send hashes across to Flash but I am having trouble figuring out how to represent an assocative array in WSDL. I got the SOAP up and working fine, and I can send hashes from perl to perl without WSDL.

Anyone know the proper WSDL layout for a hash?

                - Ant
                - Some of my best work - (1 2 3)

Replies are listed 'Best First'.
Re: Describing hashes in WSDL?
by jhourcle (Prior) on Apr 25, 2005 at 23:28 UTC

    'proper' is completely subjective. Every SOAP toolkit seems to have its own little quirks, and finding something that completely interoperates can be a royal pain in the ass.

    If there is a limited number of valid keys that are going to be in the hash, I would bless the hashref ( so that SOAP::Lite will give it a specific datatype ), and would define the hash as being an 'all' complex type, and not a 'sequence', as it allows the elements to appear in any order, but no more than one occurance each.

    If you don't know what the valid keys might be, you can force SOAP::Lite to serialize it as a mapping, but I didn't have much luck with that in my WSDL, because it seems that apache no longer makes that file available, and I don't know exactly how to define it. (it seems to be an array of items, each having two elements (a key and value, but I can't remember what they were called... just mess with the 'as_mapping' function in SOAP::Lite, and you'll see what I'm talking about).

    And if that didn't help... try the soaplite mailing list

Re: Describing hashes in WSDL?
by webengr (Pilgrim) on Apr 25, 2005 at 21:16 UTC

    It is my (limited) understanding that we do not represent the implementation of the data structure (e.g., hash), but rather the data itself. Web services should not make any assumptions about implementation at either end of the wire.

    See page 99 of "Web Services with Perl" (Ray & Kulchenko, O'Reilly, 2003) for an example. The recommendation there is to define a compound type, with a parent element representing the hash, child elements named after the keys, and their text nodes containing the values.

      This is pretty much spot-on - In the WSDL, you can define complex argument types which may be composed by any number of sub-elements. For example, from a Perl web service that I wrote which employed WSDL:
      <xsd:complexType name="queryElement"> <xsd:sequence> <xsd:element maxOccurs="1" minOccurs="1" name="address" type="xsd: +string"/> <xsd:element maxOccurs="1" minOccurs="1" name="category" type="xsd +:integer"/> <xsd:element maxOccurs="1" minOccurs="1" name="id" type="xsd:strin +g"/> <xsd:element maxOccurs="1" minOccurs="1" name="request" type="xsd: +string"/> <xsd:element maxOccurs="1" minOccurs="1" name="time" type="xsd:int +eger"/> </xsd:sequence> </xsd:complexType>


      perl -le "print unpack'N', pack'B32', '00000000000000000000001000000000'"

        Ok.. this is looking better... I was looking at Programming Web Services with SOAP, however, and it said something about a structure type and being able to describe basically the top level and not have to define all the elements inside. Basically allowing you to adjust the hash as needed (this may not be the best for mass consumption, but would work well in my current project). Basically this supposedly would work because SOAP embeds the types in the data. Know how to do that? Until then, I will play with this and see if I can make it work. Thanks!

                        - Ant
                        - Some of my best work - (1 2 3)

      SOAP::Lite already turns the hash into useful SOAP (or so it seems), my problem is finding out how to represent it in WSDL so the Flash can understand it... the book doesn't seem to go into that right there. I picked it up from my work's library though and will look at it in more detail, thanks!

                      - Ant
                      - Some of my best work - (1 2 3)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://451320]
Approved by jbrugger
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-07-06 01:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found