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

Re: [soaplite] Boolean behaviour

Expand Messages
  • Mark Knoop
    Thanks for your reply, Eric. I certainly have not ruled out the likelihood I am missing something obvious! What I am trying to understand is the logic of how
    Message 1 of 3 , Aug 25, 2008
    • 0 Attachment
      Thanks for your reply, Eric.

      I certainly have not ruled out the likelihood I am missing something
      obvious!

      What I am trying to understand is the logic of how SOAP::Lite deals with the
      SOAPy concept of booleans.

      In my example I do nothing to indicate that I want the value of 'value' to
      be a boolean (as you say after all - Perl has no concept of boolean... I did
      know that at least :). However, once it has been SOAPed it does become a
      boolean - this is what I am assuming is indicated by the <value
      xsi:type="xsd:boolean"> tag.

      Now I kinda thought this might happen as it makes sense that SOAP::Lite sees
      the value 'true' or 'false' and says 'Because I operate in the Perl world
      and therefore I should do what you mean, I will turn it into a SOAP boolean
      type.'

      If this is the case however I would expect 'false' to end up being a SOAP
      false.

      If this is not the case then how come it ever becomes a boolean and is not
      just treated as a string?

      I would like it to be a boolean once it is in SOAP as in all likelihood the
      client will not be Perl, will have a concept of booleans and for the app I
      am developing it would certainly be logical to use booleans.

      Any information on what is happening or why would be a great help in knowing
      the best way to approach this. Alternatively any further suggestions on
      workarounds would be helpful, but I am keen to understand what I am trying
      to workaround...

      Cheers
      Mark

      ----- Original Message -----
      From: "Eric Bridger" <eric@...>
      To: "Mark Knoop" <mark@...>
      Cc: <soaplite@yahoogroups.com>
      Sent: Friday, August 22, 2008 5:18 PM
      Subject: Re: [soaplite] Boolean behaviour


      > Sorry if this is too obvious and I'm just taking a guess.
      > Perl know nothing about 'true' and 'false'. Both are true as opposed
      > to '' or 0.
      > Try value => '' or value => 0 for your getFalse response.
      >
      > Eric
      >
      > On Aug 22, 2008, at 11:45 AM, Mark Knoop wrote:
      >
      >> Hi
      >>
      >> I'm sure I have read something about this but now I can't find it.
      >>
      >> Take the following example:
      >>
      >> #######################
      >>
      >> use strict;
      >> use SOAP::Transport::HTTP;
      >>
      >> SOAP::Transport::HTTP::CGI
      >> -> dispatch_to('MySOAP')
      >> -> handle;
      >>
      >> package MySOAP;
      >>
      >> sub getTrue {
      >>
      >> my $result = {
      >> descption => 'Test Boolean Behaviour - True',
      >> value => 'true',
      >> };
      >>
      >> return $result;
      >>
      >> }
      >>
      >> sub getFalse {
      >>
      >> my $result = {
      >> descption => 'Test Boolean Behaviour - False',
      >> value => 'false',
      >> };
      >>
      >> return $result;
      >>
      >> }
      >>
      >> 1;
      >>
      >> ########################
      >>
      >> When I call the function getTrue() function I get
      >>
      >> <?xml version="1.0" encoding="UTF-8"?><soap:Envelope
      >> xmlns:xsi="http://www.w3.or
      >> g/2001/XMLSchema-instance"
      >> xmlns:soapenc="http://schemas.xmlsoap.org/soap/encodi
      >> ng/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      >> soap:encodingStyle="http://sch
      >> emas.xmlsoap.org/soap/encoding/"
      >> xmlns:soap="http://schemas.xmlsoap.org/soap/env
      >> elope/"><soap:Body><getTrueResponse
      >> xmlns="http://soapdev.g-box.tv/MySOAP"><s-ge
      >> nsym3><value xsi:type="xsd:boolean">true</value><descption
      >> xsi:type="xsd:string"
      >> >Test Boolean Behaviour -
      >> >True</descption></s-gensym3></getTrueResponse></soap:B
      >> ody></soap:Envelope>
      >>
      >> where description has become a string but value is a boolean with a
      >> value
      >> true as one would expect.
      >>
      >> However when I call getFalse() I get
      >>
      >> <?xml version="1.0" encoding="UTF-8"?><soap:Envelope
      >> xmlns:xsi="http://www.w3.or
      >> g/2001/XMLSchema-instance"
      >> xmlns:soapenc="http://schemas.xmlsoap.org/soap/encodi
      >> ng/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      >> soap:encodingStyle="http://sch
      >> emas.xmlsoap.org/soap/encoding/"
      >> xmlns:soap="http://schemas.xmlsoap.org/soap/env
      >> elope/"><soap:Body><getFalseResponse
      >> xmlns="http://soapdev.g-box.tv/MySOAP"><s-g
      >> ensym3><value xsi:type="xsd:boolean">true</value><descption
      >> xsi:type="xsd:string
      >> ">Test Boolean Behaviour -
      >> False</descption></s-gensym3></getFalseResponse></soa
      >> p:Body></soap:Envelope>
      >>
      >> where value is still a boolean but still true.
      >>
      >> Can anyone explain how boolean conversion should work or where I
      >> might be
      >> going wrong? My client code is as follows:
      >>
      >> ################################
      >>
      >> use strict;
      >>
      >> #use SOAP::Lite;
      >> use SOAP::Lite +trace => [qw(method fault transport dispatch result
      >> parameters headers objects method fault freeform trace
      >> debug )];
      >>
      >> my $soap = SOAP::Lite
      >> -> uri('http://soapdev.g-box.tv/MySOAP')
      >> -> proxy ('https://soapdev.g-box.tv/demo.pl')
      >> ;
      >>
      >> {
      >>
      >> my $result = $soap
      >> ->getTrue()
      >> ->result;
      >>
      >> while ( my ($key, $value) = each(%$result ) ) {
      >> print "$key => $value\n";
      >> }
      >> }
      >>
      >> {
      >>
      >> my $result = $soap
      >> ->getFalse()
      >> ->result;
      >>
      >> while ( my ($key, $value) = each(%$result ) ) {
      >> print "$key => $value\n";
      >> }
      >> }
      >>
      >> ###########################
      >>
      >> TIA
      >>
      >> Mark
      >>
      >>
      >>
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.