The
"sayHello" service that we have been discussing in this tutorial is a
Asynchronous Moby Service, meaning that if you execute it, the response from the
server will contain a "ticket" with which you can retrieve the result data at a later time (e.g. for long-executing services).
This is distinct from
Synchronous Moby Services where the service will immediately contain the result data.
The way to know if a discovered service is either Synchronous or Asynchronous is by the "category" method of the
MOBY::Client::ServiceInstance object.
Synchronous services use the category "moby", while Asynchronous services use the category "moby-async".
This part of the tutorial deals only with Asynchronous 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 in the easy way (
but it is not the only one!):
1:#!/usr/bin/perl -W
2:
3:use strict;
4:
5:use MOBY::Client::Central;
6:use MOBY::CommonSubs;
7:use MOBY::Client::Service;
8:use MOBY::Async::Service;
9:
10:use SOAP::Lite;
11:
12:#######################################
13:# Assign the MOBY URI and MOBY SERVER #
14:#######################################
15:my $URL = 'http://moby-dev.inab.org/cgi-bin/MOBY-Central.pl';
16:my $URI = 'http://moby-dev.inab.org/MOBY/Central';
17:
18:
19:my $Central = MOBY::Client::Central->new(
20: Registries => {mobycentral => {URL => $URL,URI => $URI}});
21:
22:my ($ServiceInstances, $RegObject) = $Central->findService(
23: serviceName=> 'sayHello',
24: authURI => 'cnio.es'
25: );
26:
27:my $WSDL = $Central->retrieveService($ServiceInstances->[0]);
28:my $mobyData_empty = qq{
29:};
30:
31:my $mobyData = qq{
32: <Object namespace="HUGO" id="1234"/>
33:};
34:my $mobyData2 = qq{
35: <Object namespace="UniProt" id="P87654"/>
36:};
37:
38:print "Create instance----------\n";
39:my $Service = MOBY::Async::Service->new(service => $WSDL);
40:print "Execute async service----------\n";
41:my $response = $Service->execute(XMLinputlist => [
42: ['input', $mobyData ],
43:# ['input', $mobyData2 ],
44:]);
45:print "Output----------\n$response\n";
46:
|
And now, let's discover our service and then execute it step by step, which gives a finer control over polling process:
1:#!/usr/bin/perl -W
2:
3:use strict;
4:
5:use MOBY::Client::Central;
6:use MOBY::CommonSubs;
7:use MOBY::Client::Service;
8:use MOBY::Async::Service;
9:
10:use SOAP::Lite;
11:
12:#######################################
13:# Assign the MOBY URI and MOBY SERVER #
14:#######################################
15:my $URL = 'http://moby-dev.inab.org/cgi-bin/MOBY-Central.pl';
16:my $URI = 'http://moby-dev.inab.org/MOBY/Central';
17:
18:
19:my $Central = MOBY::Client::Central->new(
20: Registries => {mobycentral => {URL => $URL,URI => $URI}});
21:
22:my ($ServiceInstances, $RegObject) = $Central->findService(
23: serviceName=> 'sayHello',
24: authURI => 'cnio.es'
25: );
26:
27:my $WSDL = $Central->retrieveService($ServiceInstances->[0]);
28:
29:my $mobyData = qq{
30: <Object namespace="HUGO" id="1234"/>
31:};
32:my $mobyData2 = qq{
33: <Object namespace="UniProt" id="P87654"/>
34:};
35:
36:
37:print "Create instance----------\n";
38:my $Service = MOBY::Async::Service->new(service => $WSDL);
39:
40:print "Execute async service----------\n";
41:my($EPR,@queryIDs) = $Service->submit(XMLinputlist => [
42: ['input', $mobyData ],
43:# ['input', $mobyData2 ],
44:]);
45:
46:my($finished)=scalar(@queryIDs);
47:do {
48: sleep(1);
49: my(@status)=$Service->poll($EPR,@queryIDs);
50: foreach my $stat (@status) {
51: if($stat->new_state() ne 'created' && $stat->new_state() ne 'running') {
52: print "\nFetching ".$stat->id()."\n";
53: my(@response)=$Service->result($EPR,($stat->id()));
54: print "Output----------\n$response[0]\n";
55: $Service->destroy($EPR,($stat->id()));
56: $finished--;
57: }
58: }
59:} while($finished>0);
|