Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

RPC::XML::Client example needed

by zeltus (Beadle)
on Mar 23, 2012 at 11:20 UTC ( #961197=perlquestion: print w/replies, xml ) Need Help??
zeltus has asked for the wisdom of the Perl Monks concerning the following question:

I am fairly new to XML-RPC stuff and I think I might be approaching it from an "unusual" angle! :-). Anyway, I have an API Server I need to interface with that expects to see input along the lines of

<?xml version="1.0"?> <methodCall> <methodName>Gateway.SendMessage</methodName> <params> <param> <value> <struct> <member> <name>Service</name> <value><int>0</int></value> </member> <member> <name>Password</name> <value>aPassword</value> </member> <member> <name>Text</name> <value>A demonstration short message</value> </member> <member> <name>DeliveryTime</name> <value><dateTime.iso8601>20050421T09:32:00</dateTime.iso8601>< +/value> </member> </struct> </value> </param> </params> </methodCall>


use RPC::XML::Client; my $client = RPC::XML::Client->new('http://path-to-rpc-server:19000'); my $res = $client->send_request('Gateway.SendMessage');

seems (I hope) clear enough, but I can't for the life of me understand how to get the Service,Password,Text etc parameters across.

Please, please can someone help?

Since I am coming across more and more API's written this way, it feels natural to take their expected XML input and translate it into what RPC::XML can work with. But I can't find any examples that display this sort of thinking. Am I really coming at this backwards?



Replies are listed 'Best First'.
Re: RPC::XML::Client example needed
by Khen1950fx (Canon) on Mar 23, 2012 at 12:29 UTC
    This is untested, but, in general, I would attack the problem like this:
    #!/usr/bin/perl -l use strict; use warnings; use RPC::XML::Client; use Devel::SimpleTrace; use Data::Dumper::Concise; my $client = RPC::XML::Client->new('http://path-to-rpc-server:19000'); my $req = RPC::XML::Client->new( 'Gateway.SendMessage', 'show', 'channels', ); $client->credentials(qw(Gateway user password)); my $resp = $client->send_request($req); print Dumper( ref $resp ? join(', ', @{$resp->value}) : "Error: $resp" );
Re: RPC::XML::Client example needed
by trwww (Priest) on Mar 23, 2012 at 20:56 UTC

    Based on that method signature, it should be as simple as:

    my $res = $client->send_request('Gateway.SendMessage' => { Service => 0, Password => 'apassword', Text => 'A demonstration short message', DeliveryTime => '20050421T09:32:00', });

    Sometimes RPC::XML doesn't serialize the data to the correct data type (you can tell by stringifying the object or watching the raw network data). In this case you have to wrap the value you want to send around an RPC::XML Data Class instance. There is an example of this right in the synopsis where you can see RPC::XML::int is being used to explicitly set the data type.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://961197]
Front-paged by Arunbear
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-03-28 15:00 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (333 votes). Check out past polls.