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

Ted Pedersen <[email protected]> Thu, 13 Jan 2011 21:05:00 -0600
Newsgroups gmane.text.xml.rpc.specification
Message-ID <[email protected]>
I have realized what the problem was with the examples from the Programming
Web Services with Perl book. The client examples they provide (for the
Meerkat service) all use "simple_request" for client-side requests. When I
tried that for the fortune example, no success. However, after following
Bill's model and using "send_request" instead, things started to work just
fine.

From what I understand of the RPC::XML Perl module, simple_request is a
wrapper around send_request, and perhaps not understanding what it wants to
do was the root of my original troubles.

http://kobesearch.cpan.org/htdocs/RPC-XML/RPC/XML/Client.pm.html#simple_request_ARGS

Is anyone conversant enough with simple_request to show how our little
client below could/should be reconstructed using that rather than
send_request??

Thanks!
Ted

On Thu, Jan 13, 2011 at 7:51 PM, Ted Pedersen <[email protected]> wrote:

> BTW, the Dumper idea works just fine - I must have made a simple error...So
> here's that client again...
>
>  require 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;
>
> exit;
>
> And then the output...
>
> $VAR1 = [
>           '1',
>           '2',
>           '3'
>         ];
>
> So...all is well! This is exactly as you described, but just wanted to
> confirm that this works as advertised.
>
> Thanks again,
> Ted
>
>
> On Thu, Jan 13, 2011 at 7:33 PM, Ted Pedersen <[email protected]> wrote:
>
>> 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 <http://www.d.umn.edu/%7Etpederse>
>>
>
>
>
> --
> Ted Pedersen
> http://www.d.umn.edu/~tpederse <http://www.d.umn.edu/%7Etpederse>
>



-- 
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/