ted_pedersen | 13 Jan 2011 21:11
Picon
Gravatar

using the RPC::XML perl module, getting started

Greetings all,

I'm just getting started with using XML-RPC, and I'm using the Perl module RPC::XML as my implementation
tool, so far at least. :) 

There is a nice but incomplete RPC::XML example in a book called Web Services with Perl (by Ray and
Kulkchenko) which has a server side program for a fortune cookie example, but doesn't provide the client
side code. Does anyone have this (using RPC::XML) and if you could, would you be willing to share this? I
just like to have something simple I can test to make sure things are basically working. 

There is a second example in the book based on the OReilly Meerkat service, and that's a complete example
with client and server, but as best I can tell this service is no longer available (so I can't run the examples).

I've checked out the book page and written to the authors without success so wanted to check here.

http://www.blackperl.com/pwswp/

And yes, I know I should just figure this out and it must not be too hard, but I'm in the early days of working
with this and it just helps to convince myself that this module and paradigm works at all by running a simple
example. So I am hoping some industrious reader of this boo might have already worked this out or that
there's a client available somewhere...

Also, if anyone has any good recommendations on starter materials for programming with XML-RPC in Perl
(using RPC::XML or any other module). The book I've mentioned is ok, although the fact that I'm struggling
a bit to get something really simple going might suggest it's missing a few details. I know Perl reasonably
well and understand what XML-RPC is trying to do, so it's mostly the mechanics of using the Perl code that is
tripping me up (I think). 

Cordially,
Ted
(Continue reading)

Bill Moseley | 13 Jan 2011 21:42

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

I just happen to have been working with RPC::XML as your mail came in --
hadn't touched it in months.

I don't have the book you mention -- is the problem you need a server to
connect to to test? Or that you are not clear how to write the Perl code to
use the module?

For testing I often just start a web server and process requests using
RCP::XML.  And then write a small script to send requests and dump
responses.

Something as simple as this:

my $client = RPC::XML::Client->new( $endpoint );

my $response = $client->send_request( $method, \%request_data )
    || die 'failed to send';

print Dumper $response->value;

Maybe I'm not understanding your question, though.   Maybe you can provide
an example of the code you are trying to get working?

On Thu, Jan 13, 2011 at 12:11 PM, ted_pedersen <duluthted <at> gmail.com> wrote:

> Greetings all,
>
> I'm just getting started with using XML-RPC, and I'm using the Perl module
> RPC::XML as my implementation tool, so far at least. :)
>
(Continue reading)

Ted Pedersen | 13 Jan 2011 21:56
Picon
Gravatar

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

Hi Bill,

I am able to run the server just fine, I'm just not clear on what the client
should consist of.

The server looks like this:
Example C-7. fortune-RPC::XML.pl

#!/usr/bin/perl -w

use strict;

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 => 9000)
    # 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 => \&XRFortune::books })
    # It gets called once for each routine being made
    # public by the server.
(Continue reading)

Bill Moseley | 13 Jan 2011 22:15

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

On Thu, Jan 13, 2011 at 12:56 PM, Ted Pedersen <duluthted <at> gmail.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;
(Continue reading)

Ted Pedersen | 14 Jan 2011 02:33
Picon
Gravatar

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

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;

(Continue reading)

Ted Pedersen | 14 Jan 2011 02:51
Picon
Gravatar

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

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 <tpederse <at> d.umn.edu> wrote:

> Hi Bill,
>
(Continue reading)

Ted Pedersen | 14 Jan 2011 04:05
Picon
Gravatar

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

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 <tpederse <at> d.umn.edu> 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');
(Continue reading)

Bill Moseley | 14 Jan 2011 05:22

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

On Thu, Jan 13, 2011 at 7:05 PM, Ted Pedersen <duluthted <at> gmail.com> wrote:

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

Not sure I follow what you are asking.  simple_requests returns

   $self->send_request( <at> args)->value.

 so instead of: Dumper $response->value you would do Dumper $response,
right?

Is that your question?

--

-- 
Bill Moseley
moseley <at> hank.org

[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:
(Continue reading)

Ted Pedersen | 14 Jan 2011 14:00
Picon
Gravatar

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

Hi Bill,

Yes, thank you this is certainly part of the question! The other part is
more in terms of when I'm writing a client, when would I decide to use
simple_request versus send_request? Is there some reason reason (beyond the
way in which values are returned) that one would choose one over the other?

Thanks!
Ted

On Thu, Jan 13, 2011 at 10:22 PM, Bill Moseley <moseley <at> hank.org> wrote:

>
>
> On Thu, Jan 13, 2011 at 7:05 PM, Ted Pedersen <duluthted <at> gmail.com<duluthted%40gmail.com>>
> wrote:
>
> > Is anyone conversant enough with simple_request to show how our little
> > client below could/should be reconstructed using that rather than
> > send_request??
> >
>
> Not sure I follow what you are asking. simple_requests returns
>
> $self->send_request( <at> args)->value.
>
> so instead of: Dumper $response->value you would do Dumper $response,
> right?
>
> Is that your question?
(Continue reading)

Bill Moseley | 14 Jan 2011 15:28

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

On Fri, Jan 14, 2011 at 5:00 AM, Ted Pedersen <duluthted <at> gmail.com> wrote:

> Hi Bill,
>
> Yes, thank you this is certainly part of the question! The other part is
> more in terms of when I'm writing a client, when would I decide to use
> simple_request versus send_request? Is there some reason reason (beyond the
> way in which values are returned) that one would choose one over the other?
>

Hi Ted,

Take a look at the simple_request method in the source code.  That will make
it clear.

--

-- 
Bill Moseley
moseley <at> hank.org

[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
(Continue reading)

Bryan Henderson | 14 Jan 2011 00:06

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

>There is a second example in the book based on the OReilly Meerkat service,
>and that's a complete example with client and server, but as best I can tell
>this service is no longer available (so I can't run the examples).

Yes, Meerkat died around 2006, I think.

There also used to be servers and clients available to do full validation
of clients and servers respectively, on xmlrpc.com I believe.  But I don't
know of any today.

Can anyone suggest an XML-RPC server on the web that implements some
simple method so someone could use it to test a client?

I could put up a server dedicated to that purpose if there's nothing else
available.

--

-- 
Bryan Henderson                                   San Jose, California

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

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:
(Continue reading)

Gaetano Giunta | 14 Jan 2011 10:24
Picon
Gravatar

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

Bryan Henderson <bryanh <at> giraffe-data.com> wrote on 14/01/2011 00:06:
>
> >There is a second example in the book based on the OReilly Meerkat service,
> >and that's a complete example with client and server, but as best I can tell
> >this service is no longer available (so I can't run the examples).
>
> Yes, Meerkat died around 2006, I think.
>
> There also used to be servers and clients available to do full validation
> of clients and servers respectively, on xmlrpc.com I believe. But I don't
> know of any today.
>
> Can anyone suggest an XML-RPC server on the web that implements some
> simple method so someone could use it to test a client?
>
http://phpxmlrpc.sourceforge.net/server.php

bye
Gaetano
>
>
> I could put up a server dedicated to that purpose if there's nothing else
> available.
>
> -- 
> Bryan Henderson San Jose, California
>
> 

[Non-text portions of this message have been removed]
(Continue reading)

Ted Pedersen | 14 Jan 2011 18:02
Picon
Gravatar

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

Greetings all,

I have the fortune telling server described in Programming Web Services with
Perl up and running on :

maraca.d.umn.edu:31135

I'll plan on keeping that there, in the event anyone would like to test
clients. If you do something clever please do tell. :)

Below is the server cod that is running, along with the fortune module
itself. Again, these are taken from the above mentioned book.

Enjoy,
Ted

-------------------------------------------------
server.pl----------------------------------------

#!/usr/bin/perl -w

# This is an example program from Programming Web Services with Perl,
# by Randy Ray and Pavel Kulchenko

use strict;
use warnings;

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

(Continue reading)

Bryan Henderson | 15 Jan 2011 04:34

Re: test XML-RPC server

> http://phpxmlrpc.sourceforge.net/server.php

Looks great.  I've added a reference to it in the testing section of the
manual for the client library of XML-RPC For C/C++.

-- 
Bryan Henderson                                   San Jose, California

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

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:
    xml-rpc-digest <at> yahoogroups.com 
    xml-rpc-fullfeatured <at> yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    xml-rpc-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
(Continue reading)


Gmane