Service Requests
Identifying a Response
If a callback is being registered to handle the response from multiple service requests, you will most likely need to be able to identify to which request a response belongs to. To get the conversation ID of the original request, the "conversationId()" member function can be called.
class Client(netsvc.Service): def __init__(self,name):
netsvc.Service.__init__(self,"","") bindings = self.lookupServiceName(name) for binding in bindings:
service = self.serviceEndPoint(binding) if service:
id = service.uptime() self.processResponse(self.uptimeResponse,id) print "request",binding.agentIdentity(),id
def uptimeResponse(self,result): id = self.conversationId() print "result",id,result
Instead of requesting the conversation id, it is also possible to define your callback so as to take two arguments instead of one, these being the conversation id and the result instead of just the result.
class Client(netsvc.Service): def __init__(self,name):
netsvc.Service.__init__(self,"","") bindings = self.lookupServiceName(name) for binding in bindings:
service = self.serviceEndPoint(binding) if service:
id = service.uptime() self.processResponse(self.uptimeResponse,id) print "request",binding.agentIdentity(),id
def uptimeResponse(self,id,result): print "result",id,result
These are not keyword arguments, but positional parameters which the code which calls the callback function supplies or not based on the number of arguments the callback accepts. In other words, the callback must accept the appropriate number of arguments as necessary and in the specified order. If you know that the remote method being called doesn’t actually return a valid response, ie., it returns a void or null response, you can even leave out the parameters altogether.
class Client(netsvc.Service): def __init__(self,name):
netsvc.Service.__init__(self,"","") bindings = self.lookupServiceName(name) for binding in bindings:
service = self.serviceEndPoint(binding) if service:
60