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

Hi, I'm trying to get a array and hash value from one SOAP Web Services Server without success.

When try to get a hash, I receive 'Odd number of elements in hash assignment at C:\Temp\SOAP\client.pl line 9.' message, or just 1 element from a array variable with no message.

Looking at the dump (after turn on trace on client) I could see all elements of array and hash received from server. Because this maybe I must have to turn on something on client to get the correct values.

My codes are bellow, and I'd like your help to show me where are my bugs.

# Server system # 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;
# The package demo ! package Demo; use subs qw( Sub1 Sub2 ); sub Sub1 { my %Test= ( 'Test01' => 1, 'Test02' => 1, 'Test99' => 1 ); return %Test; } sub Sub2 { my @Test = qw (2 3 4 5 6 7 8 9 10); return @Test; } 1;
# Client side use SOAP::Lite; my $endpoint = shift || 'http://localhost:8080'; my $soap = SOAP::Lite->uri('urn:Demo') ->proxy($endpoint); my %Test = $soap->Sub1()->result; foreach my $Key01 ( keys %Test ) { print "Key : $Key01\n"; }
Thanks all.
Solli Moreira Honorio
Sao Paulo - Brazil

Replies are listed 'Best First'.
Re: SOAP::Lite returning strange value
by shonorio (Hermit) on Apr 28, 2004 at 14:23 UTC
    Looking at google, I found on dbForum on problem like this, where was recomended to change the return code.

    The new code recomended will look like:

    # The package demo ! package Demo; use subs qw( Sub1 Sub2 ); sub Sub1 { my %Test= ( 'Test01' => 1, 'Test02' => 1, 'Test99' => 1 ); return ( 1, \%Test ); # return changed } sub Sub2 { my @Test = ( qw (2 3 4 5 6 7 8 9 10) ); # return changed return (1, \@Test); } 1; # New Client !!!! # 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 ); if ( $soap->Sub1()->result ) # First get 1 { %Test01 = %{$soap->Sub1()->paramsout}; # and then hash } if ( $soap->Sub2()->result ) # First get 1 { @Test02 = @{$soap->Sub2()->paramsout}; # and then array } print Dumper ( \%Test01 ); print Dumper ( \@Test02 );
    Now i'd like know your opinion if it's the best way to implement one Web Service.

    Thanks,

    Solli Moreira Honorio
    Sao Paulo - Brazil