Service Requests
When invoking "serviceEndPoint()", the member function needs to be supplied with either a service binding object for the particular service agent to which you wish to send the request, or the name of the service. When a service name is supplied, a lookup will be made against the service reg- istry and the first service agent found with that service name will be used.
To invoke the request against the remote service agent, the service endpoint object is used as a proxy. That is, a member function call is made against the object as if it were the actual service object you wished to call. The only difference is that the call isn’t synchronous but asynchronous. This means that the result is not returned immediately.
As to the parameters to the call, multiple arguments can be supplied, with any of the basic Python sca- lar types, a list, tuple, dictionary, the None type, as well as a number of extended types being able to be used. User defined scalar types can also be used providing that appropriate encoders are available. Note that keyword arguments cannot be used and will be ignored.
class PagerClient(netsvc.Service): def __init__(self,number,message):
netsvc.Service.__init__(self,"","") service = self.serviceEndPoint("SMS") if service:
service.send(number,message)
When a service endpoint is created by using a service name, you should always check whether a serv- ice agent with that name could actually be found. This is done by doing a truth test against the service endpoint object or comparing it to None. Note that although it may equate to None, the service end- point object is a distinct object in its own right. If you don’t check the validity of the service endpoint object and still make a request against the service, a special exception indicating that such a service isn’t available will be raised.
class PagerClient(netsvc.Service): def __init__(self,number,message):
netsvc.Service.__init__(self,"","") service = self.serviceEndPoint("SMS") try:
service.send(number,message) except netsvc.ServiceUnavailable:
# ...
Obviously the service name by itself can only be used if you don’t care which instance of a service is used when there is more than one. If you wanted to select a specific service agent, or wanted to be able to send a request to all service agents with the same service name, you would need to perform a lookup against the service registry to obtain the full list of service agents.
class Client(netsvc.Service): def __init__(self,name):
netsvc.Service.__init__(self,"","") bindings = self.lookupServiceName(name)
58