service that we have been discussing in this tutorial is a Synchronous Moby Service
, meaning that if you execute it, the response from the
server will immediately contain the result data. This is distinct from Asynchronous Moby Services
where the service provider gives you a "ticket" with which
you can retrieve the result data at a later time (e.g. for long-executing services). The way to know if a discovered service is Synchronous or Asynchronous is by the "category" method of the
services use the category "moby", while Asynchronous services use the category "moby-async".
This part of the tutorial deals only with Synchronous Moby Services.
Moby services can be invoked once, or multiple times, in a single message.
So, let's discover our service and then execute it:
use MOBY::Client::Service; # this is what we use to interact with a service
my $m = MOBY::Client::Central->new;
my ($serv_instances, $reg) = $m->findService(
authURI => "mydomain.mycompany.org",
serviceName => "getGoTerm");
my $SI = shift @$serv_instances; # $SI is a MOBY::Client::ServiceInstance object
# remember, because we have queried using the authorty and service name we are assured
# that there will be only one response, so it is safe to "shift" the array above
print "Service Name: ", $SI->name, "\n";
print "Authority: ", $SI->authority, "\n";
print "Description: ", $SI->description, "\n";
print "Category: ", $SI->category, " (should be 'moby')\n";
# remember from the last tutorial page that you can find out what
# the correct input is, and its parameter name (articleName),
# by using the "input" and "output" methods of the ServiceInstance object.
# here we'll just set it explicitly...
my $articleName = "my_input_parameter";
my $wsdl = $m->retrieveService($SI);
# we now have the WSDL description of the Service
# we use this to create a MOBY::Client::Service object
my $SERV = MOBY::Client::Service->new(service => $wsdl);
# the $SERV object knows everything it needs to know to interact with
# that Moby Service, so all we have to do it provide the correct data
my $articleName =
my $inputdata1 = "<Object namespace='GO' id='0050789'>";
my $inputdata2 = "<Object namespace='GO' id='0050789'>";
@single_invocation = ([$articleName, $inputdata1]);
@multiple_invocation = ([$articleName, $inputdata1], [$articleName, $inputdata2]);
my $result1 = $SERV->execute(XMLinputlist => \@single_invocation);
my $result2 = $SERV->execute(XMLinputlist => \@multiple_invocation);
# The content of $result is the raw XML of whatever the service provider
# gave us. There are a variety of ways to deal with this data, or you
# can write your own. The Moby Perl code has a module called
# MOBY::CommonSubs that contains a paradigmatic way of parsing the
# output message. We'll use that module here.