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

Is this the best way to Web Services

Expand Messages
  • shonorio2000
    Hi, I trying to stablish comunication of client and server by SOAP::Lite. This comunication will have a lot of hash and array variable. On my SOAP::Lite study
    Message 1 of 1 , Apr 28, 2004
    • 0 Attachment
      Hi,

      I trying to stablish comunication of client and server by SOAP::Lite.
      This comunication will have a lot of hash and array variable. On my
      SOAP::Lite study I found some problem to get hash/array values by
      clients, usually I got just one element and/or message error
      like 'Odd number of elements in hash assignment...'

      Looking at google, I found some information that drive-me to change
      my sample code. Now they like this, and I'd like know if this is the
      best way to write a Web Services code...

      Thanks all for help-me on my starting...

      Solli

      <code>
      ####################################################
      # The package demo !
      package Demo;

      use subs qw( Sub1 Sub2 );

      sub Sub1
      {
      my %Test= ( 'Test01' => 1,
      'Test02' => 1,
      'Test99' => 1 );
      # I was just do "return %Test", and now ...
      return ( 1, \%Test );

      }

      sub Sub2
      {

      my @Test = ( qw (2 3 4 5 6 7 8 9 10) );
      # I was just do "return %Test", and now ...
      return (1, \@Test);
      }
      1;

      ####################################################
      # Server side
      # This is a test of one Web Service Server
      use strict;
      use SOAP::Transport::HTTP;
      use Demo;

      my $port = 8080;
      my $host = 'localhost';

      SOAP::Transport::HTTP::Daemon
      ->new(LocalAddr => $host, LocalPort => $port, Reuse => 1)
      ->dispatch_with({ 'urn:Demo' => 'Demo' })
      ->objects_by_reference('Demo')
      ->handle;
      exit;

      ####################################################
      # Client side
      use SOAP::Lite;
      use Data::Dumper;

      my $endpoint = shift || 'http://localhost:8080';
      my $soap = SOAP::Lite->uri('urn:Demo')
      ->proxy($endpoint);

      my ( %Test01, @Test02 );

      # My code was:
      # %Test01 = $soap->Sub1()->result;
      # but I receive the message 'Odd number of elements
      # in hash assignment...'

      if ( $soap->Sub1()->result )
      {
      %Test01 = %{$soap->Sub1()->paramsout};
      }

      if ( $soap->Sub2()->result )
      {
      @Test02 = @{$soap->Sub2()->paramsout};
      }

      print Dumper ( \%Test01 );
      print Dumper ( \@Test02 );
      </code>
    Your message has been successfully submitted and would be delivered to recipients shortly.