Perl Tutorials - Herong's Tutorial Examples - v6.03, by Herong Yang
RpcXmlClient.pl - RPC::XML Client Sample Program
This section provides a tutorial example on how to write a RPC::XML client sample program, RpcXmlClient.pl, to test remote methods offered by the server sample program, RpcXmlServer.pl.
To test my server program, I wrote the following client program, RpcXmlClient.pl:
#- RpcXmlClient.pl
#- Copyright (c) HerongYang.com. All Rights Reserved.
require RPC::XML;
require RPC::XML::Client;
my $client = RPC::XML::Client->new('http://localhost:8001');
#
print "\nCalling system.listMethods...\n";
my $res = $client->send_request('system.listMethods');
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";
}
#
print "\nCalling system.methodSignature...\n";
my $req = RPC::XML::request->new('system.methodSignature',
RPC::XML::string->new('system.listMethods'));
$res = $client->send_request($req);
print " Response type = ".$res->type."\n";
print " Response string = ".$res->as_string."\n";
print " Response value = ".$res->value."\n";
foreach (@{$res->value}) {
print " ".join(', ',@$_)."\n";
}
#
print "\nCalling com.herong.hello...\n";
my $res = $client->send_request('com.herong.hello');
print " Response string = ".$res->as_string."\n";
print " Response value = ".$res->value."\n";
#
print "\nCalling com.herong.getCelsius...\n";
my $res = $client->send_request('com.herong.getCelsius');
print " Response value = ".$res->value."\n";
#
print "\nCalling com.herong.getCelsius...\n";
my $req = RPC::XML::request->new('com.herong.getCelsius',
RPC::XML::double->new('100.0'));
$res = $client->send_request($req);
print " Response value = ".$res->value."\n";
#
print "\nCalling com.herong.getInfo...\n";
my $res = $client->send_request('com.herong.getInfo');
print " Response value = ".$res->value."\n";
foreach (@{$res->value}) {
print " $_\n";
}
exit;
If you run the RpcXmlClient.pl in another command window, you will see:
Calling system.listMethods...
Response class = RPC::XML::array
Response type = array
Response string = <array><data><value><string>com.herong.getCelsiu
s</string></value><value><string>com.herong.getInfo</string></value><
value><string>com.herong.hello</string></value><value><string>system.
identity</string></value><value><string>system.introspection</string>
</value><value><string>system.listMethods</string></value><value><str
ing>system.methodHelp</string></value><value><string>system.methodSig
nature</string></value><value><string>system.multicall</string></valu
e><value><string>system.status</string></value></data></array>
Response value = ARRAY(0x232ddc8)
com.herong.getCelsius
com.herong.getInfo
com.herong.hello
system.identity
system.introspection
system.listMethods
system.methodHelp
system.methodSignature
system.multicall
system.status
Calling system.methodSignature...
Response type = array
Response string = <array><data><value><array><data><value><string>
array</string></value></data></array></value><value><array><data><val
ue><string>array</string></value><value><string>string</string></valu
e></data></array></value></data></array>
Response value = ARRAY(0x232d338)
array
array, string
Calling com.herong.hello...
Response string = <string>Hello world!</string>
Response value = Hello world!
Calling com.herong.getCelsius...
Response value = -17.7777777777778
Calling com.herong.getCelsius...
Response value = 37.7777777777778
Calling com.herong.getInfo...
Response value = ARRAY(0x2244aa8)
Author
Herong Yang
Version
2005
Table of Contents
Data Types: Values and Variables
Expressions, Operations and Simple Statements
Name Spaces and Perl Module Files
Hard References - Addresses of Memory Objects
Objects (or References) and Classes (or Packages)
Typeglob and Importing Identifiers from Other Packages
String Built-in Functions and Performance
File Handles and Data Input/Output
Open Directories and Read File Names
File System Functions and Operations
Socket Communication Over the Internet
XML::Simple Module - XML Parser and Generator
SOAP::Lite - SOAP Server-Client Communication Module
Perl Programs as IIS Server CGI Scripts
CGI (Common Gateway Interface)
XML-RPC - Remote Procedure Call with XML and HTTP
►RPC::XML - Perl Implementation of XML-RPC
RPC::XML::Server - XML-RPC Server Interface Class
RPC::XML Client and Data Classes
RpcXmlServer.pl - RPC::XML Server Sample Program
►RpcXmlClient.pl - RPC::XML Client Sample Program
Sending Arrays with Remote Method Calls
Integrating Perl with Apache Web Server
CGI.pm Module for Building Web Pages
LWP::UserAgent and Web Site Testing
Converting Perl Script to Executable Binary