So you are in need for a fast way to implement an XML based service ?
Few months ago i got an assignment to write a test project (with all the SRS/STP/STD) since i just got some extra time recently i realized it could be a great time for learning new technologies.
The first find i remembers that it is time to sharpen my TAP and perhaps study a bit cucumber things.
Thanks to Ido i was able to find alot of info but i noted that it took me too much time ,
So i dropped the the cucumber and went back to TAP.
Wow developing in TDD after not doing so more then a year was a bit problematic but hey that was fun.
next was the real thing SOAP vs XML-RPC to bethe middle-ware protocol (gui <-> middle ware < -> db ).
After googling and reading and help (again from Ido) i choose XML-RPC you might ask "why ?"
The reason is simple - KISS plus it did exactly what i need (no need for object serialization ).
There are many other protocols but i wished an XML based and one that it would be relatively easy to work with.
The fun part came and there was the module to work with ,
I really don't know but allmost in all the tutorials i found there was use of Frontier or RPC2
while at first glance i didn't see anything bad in Frontier i start to work with.
Basically a standalone daemon would look like :
Just returning a hash with the correct parameter values and all should be ok ?
The problem becomes when you need to use language as C# or C where strong types are used.
Then you will probably find your self searching for a way how to work with (to use the correct int or double).
While that was hard i found some hacks (using Frontier::RPC2) so you could do some thing like :
Or even better what about function signatures ?
So if you don't need the signatures (call with unknown amount of parameters or unknown return type it is a benefit).
Just remember set the Return type using array / struct or void.
For instance i need to create a fault or an exception there is no documentation how to call it (using Frontier::Deamon).
I googled , ircd and what not.
Then I started to read the code and realized that in my tight schedule it will be too expensive (to find how to call it by reading all the connected modules).
So having only one spare day i started the search from scratch , i even thought about using cgi solution (Frontier::RPC2),
but then i stumbled on XML::RPC wow that was a relief.
the basic server look like :
The receiving part (for instance XML-RPC.NET) could looke like :
Another benefit that i found in RPC::XML is the speed the same code work much faster on startup the Frontier::Daemon.
btw the project was released by MIT license (Connector.pm) the perl coding took me 14 coding hours (from 9 am till 11 pm) while the longest things was the switch from Frontier to RPC::XML.
Few months ago i got an assignment to write a test project (with all the SRS/STP/STD) since i just got some extra time recently i realized it could be a great time for learning new technologies.
The first find i remembers that it is time to sharpen my TAP and perhaps study a bit cucumber things.
Thanks to Ido i was able to find alot of info but i noted that it took me too much time ,
So i dropped the the cucumber and went back to TAP.
Wow developing in TDD after not doing so more then a year was a bit problematic but hey that was fun.
next was the real thing SOAP vs XML-RPC to bethe middle-ware protocol (gui <-> middle ware < -> db ).
After googling and reading and help (again from Ido) i choose XML-RPC you might ask "why ?"
The reason is simple - KISS plus it did exactly what i need (no need for object serialization ).
There are many other protocols but i wished an XML based and one that it would be relatively easy to work with.
The fun part came and there was the module to work with ,
I really don't know but allmost in all the tutorials i found there was use of Frontier or RPC2
while at first glance i didn't see anything bad in Frontier i start to work with.
Basically a standalone daemon would look like :
Simple right ?
#!/usr/bin/perl -w
use Frontier::Daemon;
use DBI;
sub sumAndDifference {
my ($x, $y) = @_;
return {'sum' => $x + $y, 'difference' => $x - $y};
}
$methods = {'sample.sumAndDifference' => \&sumAndDifference};
Frontier::Daemon->new(LocalPort => 8080, methods => $methods)
or die "Couldn't start HTTP server: $!";
Just returning a hash with the correct parameter values and all should be ok ?
The problem becomes when you need to use language as C# or C where strong types are used.
Then you will probably find your self searching for a way how to work with (to use the correct int or double).
While that was hard i found some hacks (using Frontier::RPC2) so you could do some thing like :
use Frontier::RPC2;But again there was a but , how do i work with exceptions ?
my $foo = Frontier::RPC2->new;
$int_object = $foo->int(42);
Or even better what about function signatures ?
So if you don't need the signatures (call with unknown amount of parameters or unknown return type it is a benefit).
Just remember set the Return type using array / struct or void.
For instance i need to create a fault or an exception there is no documentation how to call it (using Frontier::Deamon).
I googled , ircd and what not.
Then I started to read the code and realized that in my tight schedule it will be too expensive (to find how to call it by reading all the connected modules).
So having only one spare day i started the search from scratch , i even thought about using cgi solution (Frontier::RPC2),
but then i stumbled on XML::RPC wow that was a relief.
the basic server look like :
in this example you see how to use both exception and return structure.
use RPC::XML::Server; # The server
use RPC::XML; # will be used for functions
sub get_structure_by_string{
return
RPC::XML::struct->new(
{
"someString" => RPC::XML::string->new( $_[1] ),
"someInt" => RPC::XML::i4->new( 2 ),
"someDouble" => RPC::XML::double->new("3.14" )
}
);
}
$srv = RPC::XML::Server->new(port => 9000); #server object
$srv->add_method(
{
"name" => "makeFault", # calling this function will throw fault aka exception
"signature" => [''], #what are the return type and call parameters beware of the spaces!
"code" => sub { return RPC::XML::fault->new( 99999, "Test drive error" );}
}
);
$coder->add_method(
{
"name" => "get_structure_by_string",
"signature" => ['struct string'],
"code" => \&get_structure_by_string
}
);
$srv->server_loop; # Just work
The receiving part (for instance XML-RPC.NET) could looke like :
As you see the signature has to be as the RPC::XML definitions (while in Frontier there is no check perhaps a feature in Frontier::Deamon ? ) .
using CookComputing.XmlRpc;
public struct Foo
{
public String someString;
public int someInt;
public double someDouble;
}
[XmlRpcUrl("http://192.168.0.135:8080/RPC2")]
public interface Interface
{
[XmlRpcMethod]
Foo get_structure_by_string(String parameter);
[XmlRpcMethod]
void makeFault();
}
Another benefit that i found in RPC::XML is the speed the same code work much faster on startup the Frontier::Daemon.
btw the project was released by MIT license (Connector.pm) the perl coding took me 14 coding hours (from 9 am till 11 pm) while the longest things was the switch from Frontier to RPC::XML.

