Loading ...
Sorry, an error occurred while loading the content.

Re: [soaplite] Returning structure

Expand Messages
  • Paul Kulchenko
    Hi, Weidong! ... in you $devices hashref you alredy have only ONE key= value pair. Should be @devices = ( # ARRAY, not HASH Device = device1 , Device =
    Message 1 of 2 , Sep 20, 2001
    • 0 Attachment
      Hi, Weidong!

      > return
      > SOAP::Data->name(TestResult)->type('ordered_hash' => [Acct =>
      > 'abc', Devices => $devices]);
      >
      > But it only returns 'device3'. I suppose it treats $devices as a
      > hash. And since the index is the same, it keeps the last one. How
      > do I do?
      in you $devices hashref you alredy have only ONE key=>value pair.

      Should be

      @devices = ( # ARRAY, not HASH
      Device => 'device1',
      Device => 'device2',
      Device => 'device3'
      );

      return SOAP::Data->name(TestResult => {
      Acct => 'abc',
      Devices => SOAP::Data->type(ordered_hash => \@devices)
      });

      > But the result is that "FileData" is serialized as an array with
      > the first element containing the base64'ed content.
      > How do I do?
      > return
      > SOAP::Data->name(TestResult)->type('ordered_hash' =>
      > [FileName => 'abc', FileData => [map
      > {SOAP::Data->type(base64)->value($_)} 'This is a test file
      > content'] ] );
      Shouldn't be so complicated ;)

      return SOAP::Data->name(TestResult => {
      FileName => 'abc',
      FileData => SOAP::Data->type(base64 => 'This is a test file'),
      });

      -- OR if you want to preserve order --

      return SOAP::Data->name(TestResult => [
      FileName => 'abc',
      FileData => SOAP::Data->type(base64 => 'This is a test file'),
      ])->type('ordered_hash');

      ordered_hash works exactly like hash, just change {} to [].

      Hope it helps.

      Best wishes, Paul.

      --- Weidong Wang <wwang@...> wrote:
      > Two questions regarding how to return a structure:
      >
      > 1. I want the wire data to look like:
      >
      > ...
      > <s:Body>
      > <g:TestResponse xmlns:g="someuri">
      > <g:TestResult>
      > <g:Acct>abc</g:Acct>
      > <Devices>
      > <Device>device1</Device>
      > <Device>device2</Device>
      > <Device>device3</Device>
      > </Device>
      > </g:TestResult>
      > </g:RestResponse>
      > </s:Body>
      > ...
      >
      > My code does:
      >
      > $devices = {
      > Device => 'device1',
      > Device => 'device2',
      > Device => 'device3'
      > };
      >
      > return
      > SOAP::Data->name(TestResult)->type('ordered_hash' => [Acct =>
      > 'abc', Devices => $devices]);
      >
      > But it only returns 'device3'. I suppose it treats $devices as a
      > hash. And since the index is the same, it keeps the last one. How
      > do I do?
      >
      > 2. I want the wire data to look like:
      >
      > ...
      > <s:Body>
      > <g:TestResponse xmlns:g="someuri">
      > <g:TestResult>
      > <g:FileName>abc</g:FileName>
      > <g:FileData SOAP-ENC:base64>kjadhflkjahf==</g:FileData>
      > </g:TestResult>
      > </g:RestResponse>
      > </s:Body>
      > ...
      >
      > and my code does:
      >
      > return
      > SOAP::Data->name(TestResult)->type('ordered_hash' =>
      > [FileName => 'abc', FileData => [map
      > {SOAP::Data->type(base64)->value($_)} 'This is a test file
      > content'] ] );
      >
      > But the result is that "FileData" is serialized as an array with
      > the first element containing the base64'ed content.
      > How do I do?
      >
      > Thanks.
      >
      > Weidong
      >
      >


      __________________________________________________
      Terrorist Attacks on U.S. - How can you help?
      Donate cash, emergency relief information
      http://dailynews.yahoo.com/fc/US/Emergency_Information/
    Your message has been successfully submitted and would be delivered to recipients shortly.