Re: using the RPC::XML perl module, getting started

Ted Pedersen <[email protected]> Thu, 13 Jan 2011 19:33:59 -0600
Newsgroups gmane.text.xml.rpc.specification
Message-ID <[email protected]>
Hi Bill,

Yes, this is exactly the sort of example I needed! I am not quite sure what
happened, but the Dumper didn't seem to want to display the output, but I
was able to modify the following client example combined with your
suggestion and achieved some success.

http://www.herongyang.com/Perl/RPC-XML-Client-Sample-Program.html

So...here's the server, following your suggestion....

use XRFortune;
use RPC::XML::Server;

# The object created by the constructor will be used to
# chain on a set of calls to add_proc() (which means it
# isn't necessary to deal with the local routines being
# called as methods), and then drop directly into the
# server_loop() method.

RPC::XML::Server->new(port => 19000)
    # add_proc can take a pre-created RPC::XML::Procedure
    # object, or a hash reference.
    ->add_proc({ name => 'books',
                 signature => [ 'array',
                                'array string',
                                'array array' ],
         code => sub  {return [1,2,3] }})
    ->server_loop;

exit;

And then here is the client, more or less following the site above...

 require RPC::XML::Client;

   my $client = RPC::XML::Client->new('http://localhost:19000');

   my $res = $client->send_request('books');
   print "   Response class = ".(ref $res)."\n";
   print "   Response type = ".$res->type."\n";
   print "   Response string = ".$res->as_string."\n";
   print "   Response value = ".$res->value."\n";
   foreach (@{$res->value}) {
      print "      $_\n";
   }

exit;

And then the output....

 Response class = RPC::XML::array
   Response type = array
   Response string =
<array><data><value><int>1</int></value><value><int>2</int></value><value><int>3</int></value></data></array>
   Response value = ARRAY(0x8a0385c)
      1
      2
      3

And this is very satisfying indeed, since I'm now convinced this actually
can work (seeing is believing :)

I'll see if I can make some more progress now, but this was really a big
help.

Thanks!
Ted



On Thu, Jan 13, 2011 at 3:15 PM, Bill Moseley <[email protected]> wrote:

>
>
> On Thu, Jan 13, 2011 at 12:56 PM, Ted Pedersen <[email protected]<duluthted%40gmail.com>>
> wrote:
>
> >
> > So...given that I have this server running, what should the client look
> > like
> > to get this going?
> >
>
> Well, I think those methods return a reference to a list. I don't have the
> fortune program, so I just replaced the code like this:
>
> RPC::XML::Server->new(port => 19000)
>
> # add_proc can take a pre-created RPC::XML::Procedure
> # object, or a hash reference.
> ->add_proc({ name => 'books',
> signature => [ 'array',
> 'array string',
> 'array array' ],
> code => sub { return [1,2,3]} })
>
> And then the client:
>
> use strict;
> use warnings;
> use RPC::XML::Client;
> use Data::Dumper;
>
> my $client = RPC::XML::Client->new( 'http://localhost:19000' );
> my $response = $client->send_request( 'books' );
> print Dumper $response->value;
>
> Which returns:
>
> $VAR1 = [
> '1',
> '2',
> '3'
> ];
>
> You would want to add a bit more error handling, of course.
>
> Is that what you are after?
>
>
> --
> Bill Moseley
> [email protected] <moseley%40hank.org>
>
> [Non-text portions of this message have been removed]
>
>  
>



-- 
Ted Pedersen
http://www.d.umn.edu/~tpederse


[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/xml-rpc/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/xml-rpc/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/