in reply to Getting an XML-RPC array with Frontier::Client

It seems the Frontier::Client only expects to return simple values, not arrays. You'll have to go down to the Frontier::RPC2 level and do "decode" calls for yourself. Here's an example:
sub doCommand { # Decode the results of the raw command from XML. my ($uri, $coder, @rest) = @_; my $encoded = doRawCommand($uri, $coder, @rest); return $encoded if ($encoded eq ""); my $result; # Decode XML RPC wrapper case. my $decoded = $coder->decode($encoded); # Note: the result is an array ref with params inside $result = $decoded->{value}[0]; return $result; }

Update: I should explain that doRawCommand is a routine I wrote to encode and make an XML-RPC request, and that $coder is an instance of Frontier::RPC2.

Update2: One thing about your original code is that Frontier::Client::call will never return an array of values, even if the decoding had worked. It should be able to do an array reference, though.

Update3: I just tried an encoding example, trying to match what Advogato returns:

use strict; use Frontier::RPC2; my $coder = Frontier::RPC2->new(use_objects => 1); my $result = [ "you guessed", 42 ]; my $xml_string = $coder->encode_response($result); print $xml_string,"\n";
This is the result I got:
<?xml version="1.0"?> <methodResponse> <params> <param><value><array><data> <value><string>you guessed</string></value><value><i4>42</i4></value>< +/data></array></value> </param> </params> </methodResponse>
The difference is a "value" tag around the "array" level. I believe that is what is throwing off your decode. Advogato must be using a different version of the encoding scheme.

I would suggest asking their support board. If they can't help, you could use a wrapper like my subroutine above and munge the return value to the right syntax before decoding it.

Replies are listed 'Best First'.
Re: Re: Getting an XML-RPC array with Frontier::Client
by jaldhar (Vicar) on Apr 10, 2003 at 22:59 UTC

    Update: nicer error-handling code, correction of syntax errors.

    Sorry I got sidetracked by other things (or rather I got retracked from this side track :-) but I returned to this subject and your advice was invaluable.

    In the end though I used RPC::XML which is just as easy to use and apparently more complete. Here is what my example code would look like with this module:

    use RPC::XML::Client; my $client = RPC::XML::Client->new('http://www.advogato.org/XMLRPC'); my $result = $client->send_request('test.guess'); die $result unless defined($result); die $result->code . ': ' . $result->string if $result->is_fault; print join(' ', @{$result->value}), "\n";

    --
    જલધર

Re^2: Getting an XML-RPC array with Frontier::Client
by Anonymous Monk on Aug 28, 2007 at 00:10 UTC
    Dude, I found a real cool solution.. Just pass the array elements like below $result1 = $server->call('method1',reasonsArray =>"reason1","reason2","reason3") Thanks, Sarat
      you have to keep all your array elemement in square braces. in the above comment square braces were removed by this site tagging process