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

More fun with arrays

Expand Messages
  • gdhgdh
    Hullo :) Can someone offer assistance because my poor Perl skills are really showing through here? I have a tiny SOAP::Lite client calling a method on a
    Message 1 of 3 , May 10, 2004
    • 0 Attachment
      Hullo :)

      Can someone offer assistance because my poor Perl skills are really
      showing through here? I have a tiny SOAP::Lite client calling a
      method on a SOAP::Lite service, and though I can see all the
      elements of the returned array in a Dumper output, I cannot see how
      to access it via the SOAP::Lite methods.

      The client:

      #!/usr/bin/perl

      use SOAP::Lite +trace=>'debug';
      use Data::Dumper;

      $soap = SOAP::Lite
      -> uri('System')
      -> proxy('http://my.server.ip/');

      $soapcall = $soap->getCurrentIP();
      print Dumper($soapcall);
      @lansettings = $soapcall->result;
      print "Current LAN settings:\n\n";
      print " IP Address: $lansettings[0]\n";
      print " Subnet Mask: $lansettings[1]\n";
      print " Default Gateway: $lansettings[2]\n";

      Unfortunately, the @lansettings array only has one element. I've
      omitted the full Dumper output for the sake of brevity, (it's at
      http://gdh.ca/dump.txt ) but the SOAP::Lite trace is as follows:

      SOAP::Transport::HTTP::Client::send_receive: POST
      http://my.server.ip/
      Accept: text/xml
      Accept: multipart/*
      Content-Length: 438
      Content-Type: text/xml; charset=utf-8
      SOAPAction: "System#getCurrentIP"

      <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV:Body><namesp1:getCurrentIP
      xmlns:namesp1="System"/></SOAP-ENV:Body></SOAP-ENV:Envelope>


      SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK
      Date: Mon, 10 May 2004 14:49:29 GMT
      Server: libwww-perl-daemon/1.25
      Content-Length: 659
      Content-Type: text/xml; charset=utf-8
      Client-Date: Mon, 10 May 2004 14:50:00 GMT
      Client-Response-Num: 1
      SOAPServer: SOAP::Lite/Perl/0.55

      <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
      xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
      SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-ENV:Body><namesp14:getCurrentIPResponse
      xmlns:namesp14="System"><s-gensym86
      xsi:type="xsd:string">82.49.223.14</s-gensym86><s-gensym88
      xsi:type="xsd:string">255.255.255.240</s-gensym88><s-gensym90
      xsi:type="xsd:string">82.49.223.11</s-gensym90></namesp14:getCurrentIPResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

      Can anyone offer a push in the right direction?

      Thank you,
      Gavin.
    • Christopher Parker
      ... Can someone offer assistance because my poor Perl skills are really showing through here? I have a tiny SOAP::Lite client calling a method on a SOAP::Lite
      Message 2 of 3 , May 10, 2004
      • 0 Attachment
        --- gdhgdh <gdh@...> wrote:
        Can someone offer assistance because my poor Perl skills are really
        showing through here? I have a tiny SOAP::Lite client calling a
        method on a SOAP::Lite service, and though I can see all the
        elements of the returned array in a Dumper output, I cannot see how
        to access it via the SOAP::Lite methods.

        The client:

        #!/usr/bin/perl

        use SOAP::Lite +trace=>'debug';
        use Data::Dumper;

        $soap = SOAP::Lite
        -> uri('System')
        -> proxy('http://my.server.ip/');

        $soapcall = $soap->getCurrentIP();
        print Dumper($soapcall);
        @lansettings = $soapcall->result;
        print "Current LAN settings:\n\n";
        print " IP Address: $lansettings[0]\n";
        print " Subnet Mask: $lansettings[1]\n";
        print " Default Gateway: $lansettings[2]\n";

        Unfortunately, the @lansettings array only has one element.
        -----

        You're returning an array with your server. ``result'' only returns the first element of this
        array (a scalar). ``paramsout'' returns the rest of your output parameters, minus the first
        element (if any exist).

        To completely rebuild your array, you'll have to do something like this:

        @lansettings = ($soapcall->result, $soapcall->paramsout);

        -OR-

        @lansettings = $soapcall->paramsall;

        This is explained at http://search.cpan.org/~byrne/SOAP-Lite-0.60a/lib/SOAP/Lite.pm#SOAP::SOM

        I believe this was also explained in the book "Programming Web Services with Perl". If you don't
        have this book, I recommend it (written by Pavel Kulchenko and Randy J. Ray). It's been an
        invaluable resource to me thus far. Additionally, you may wish to check out "Programming Web
        Services with SOAP" (written by James Snell, Dough Tidwell, and Pavel Kulchenko). Both are
        available directly from O'Reilly's Web site:

        - http://www.oreilly.com/catalog/pwebserperl/
        - http://www.oreilly.com/catalog/progwebsoap/

        HTH

        --
        Parker
      • gdhgdh
        ... returns the first element of this ... parameters, minus the first ... Of course! Now it comes back to me :( I ve been writing exclusively
        Message 3 of 3 , May 13, 2004
        • 0 Attachment
          > You're returning an array with your server. ``result'' only
          returns the first element of this
          > array (a scalar). ``paramsout'' returns the rest of your output
          parameters, minus the first
          > element (if any exist).

          <slaps forehead>

          Of course! Now it comes back to me :(

          I've been writing exclusively in PHP with NuSOAP for months, but
          have now had to write a little client in Perl - thanks so much for
          the refresher! :)

          I'm a little embarrassed I wasn't able to find this in the perldocs
          myself :/

          Cheers,
          Gavin.
        Your message has been successfully submitted and would be delivered to recipients shortly.