We will try out our service first with a simple client that creates a new resource and performs a couple operations on it. Starting from the client.py that was generated by wsdl2web.py all that's needed are a few rpc calls to demonstrate WSRF resource's behavior.
#!/usr/bin/env python ############################################################################ # Automatically generated by wsdl2web.py # See LBNLCopyright for copyright notice! ########################################################################### from twisted.python import log from twisted.internet import reactor import ZSI from pyGridWare.utility.scripts.client import GetBasicOptParser, GetPortKWArgs, SetUp from generated.MathService.stubs import MathService as CLIENT def main(**kw): locator = CLIENT.MathServiceLocator() port = locator.getMathPortType(**kw)msg = port.createResource(CLIENT.CreateInputMessage())
iport = locator.getMathPortType(endPointReference=msg.EndpointReference, **kw)
for i in range(10): iport.add(CLIENT.AddInputMessage(i))
msg = iport.subtract(CLIENT.SubtractInputMessage(10)) msg = iport.getValueRP(CLIENT.GetValueRPInputMessage()) # Factory METHOD Just guessing here #response = port.create(CLIENT.CreateRequest()) #kw['endPointReference'] = response._EndpointReference #iport = locator.getMathPortType(**kw) reactor.stop() print "MSG: ", msg print "CORRECT: ", msg == sum(range(10)) - 10 if __name__ == '__main__': op = GetBasicOptParser() (options, args) = op.parse_args() SetUp(options) kw = GetPortKWArgs(options) reactor.callWhenRunning(main, **kw) reactor.run()
![]() | Copy & Paste example.. |
run the client:
./client.py -u http://127.0.0.1:9080/wsrf/services/MathService -d 0
If all goes well, you should see the following:
MSG: 35 CORRECT: True
If you run it again, you will get the exact same result. This is because we are creating a new resource every time we run the client.
MSG: 35 CORRECT: True