Our client application will make calls to some of the WS-ResourceProperties portTypes. The next example will use more complex resource properties and then we will see how to invoke the rest of the portTypes.
In the examples that follow instances of python stub classes are directly manipulated and access through attributes. The python attributes of an object represent XML Schema element declarations, there is a predictable mapping. Above the tests are a few relevant XML Schema samples.
#!/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.MathRPService.stubs import MathRPService as CLIENT def GetResourceProperty(iport): # Replace reactor.stop() def SetResourceProperty(iport): # Replace reactor.stop() def GetMultipleResourceProperties(iport): # Replace reactor.stop() def main(*argv, **kw): locator = CLIENT.MathServiceLocator() port = locator.getMathPortType(**kw) msg = port.createResource(CLIENT.CreateInputMessage()) iport = locator.getMathPortType(endPointReference=msg.EndpointReference, **kw) if len(argv) > 0: method = eval(argv[0]) method(iport) reactor.stop() if __name__ == '__main__': op = GetBasicOptParser() (options, args) = op.parse_args() SetUp(options) kw = GetPortKWArgs(options) reactor.callWhenRunning(main, *args, **kw)
![]() | Copy & Paste to client.py, we'll add the missing sections below. |
XML Schema GetResourceProperty global element declaration(GED), its type is QName. XML Schema GetResourcePropertyResponse GED. It contains an element wildcard any, and the value of its maxOccurs facet is unbounded.
<!-- ========== Message Types for GetResourceProperty ============ --> <xsd:element name="GetResourceProperty" type="xsd:QName" /> <xsd:element name="GetResourcePropertyResponse" > <xsd:complexType> <xsd:sequence> <xsd:any minOccurs="0" maxOccurs="unbounded" /> </xsd:sequence> </xsd:complexType> </xsd:element>
def GetResourceProperty(iport): for i in range(10): iport.add(CLIENT.AddInputMessage(i)) iport.subtract(CLIENT.SubtractInputMessage(10)) msg = iport.GetResourceProperty(\CLIENT.GetResourcePropertyRequest(\ ("http://www.globus.org/namespaces/examples/core/MathService_instance_rp","Value"), ) ) print "MSG: ", msg
print "PROPERTIES: ", msg.Any print "PROPERTY: ", msg.Any[0]
print "CORRECT: ", msg.Any[0] == sum(range(10)) - 10
% ./client.py -u http://127.0.0.1:9080/wsrf/services/MathService -d 0 GetResourceProperty MSG: <pyGridWare.generated.types.resourceproperties.GetResourcePropertyResponse_Holder instance at 0x13480a8> PROPERTIES: [35] PROPERTY: 35 CORRECT: True
XML Schema Type Definiton and GED for Update and SetResourceProperties.
<xsd:complexType name="UpdateType"> <xsd:sequence> <xsd:any processContents="lax" minOccurs="1" maxOccurs="unbounded" /> </xsd:sequence> </xsd:complexType> <xsd:element name="Update" type="wsrp:UpdateType"/> <xsd:element name="SetResourceProperties"> <xsd:complexType> <xsd:choice minOccurs="0" maxOccurs="unbounded"> <xsd:element ref="wsrp:Insert"/> <xsd:element ref="wsrp:Update"/> <xsd:element ref="wsrp:Delete"/> </xsd:choice> </xsd:complexType> </xsd:element> <xsd:element name="SetResourcePropertiesResponse" > <xsd:complexType /> </xsd:element>
![]() | Replace test function and add a SetResourceProperties call |
def SetResourceProperties(iport): iport.add(CLIENT.AddInputMessage(111)) # Take the Value ResourceProperty and create a new instance from generated.MathRPService.properties.MathRPService.MathService.MathPort import MathPortType properties = MathPortType()properties.Value = 100
req = CLIENT.SetResourcePropertiesRequest()
req.Update = req.new_Update()
req.Update.Any = properties.Value
smsg = iport.SetResourceProperties(req)
assert ("http://www.globus.org/namespaces/examples/core/MathService_instance_rp","Value") ==\ (properties.Value.typecode.nspname, properties.Value.typecode.pname),\ "Grab Value ResourceProperty GED's namespace, name." msg = iport.GetResourceProperty(\ CLIENT.GetResourcePropertyRequest(\ (properties.Value.typecode.nspname, properties.Value.typecode.pname), ) ) reactor.stop() print "SetResourceProperties MSG: ", smsg print "PROPERTIES: ", msg.Any print "CORRECT: ", msg.Any[0] == 100
%./client.py -u http://127.0.0.1:9080/wsrf/services/MathService -d 0 SetResourceProperties SetResourceProperties MSG: <pyGridWare.generated.types.resourceproperties.SetResourcePropertiesResponse_Holder instance at 0x107d080> PROPERTIES: [100] CORRECT: True
![]() | Replace test function and add a GetMultipleResourceProperties call |
def GetMultipleResourceProperties(iport): for i in range(10): iport.add(CLIENT.AddInputMessage(i)) req = CLIENT.GetMultipleResourcePropertiesRequest()req.ResourceProperty = ("http://www.globus.org/namespaces/examples/core/MathService_instance_rp","Value")
req.ResourceProperty.append(\
("http://www.globus.org/namespaces/examples/core/MathService_instance_rp","LastOp") ) msg = iport.GetMultipleResourceProperties(req) reactor.stop() print "MSG: ", msg for any in msg.Any:
print "Resource Property(%s) = " %any.__class__,any
% ./client.py -u http://127.0.0.1:9080/wsrf/services/MathService -d 0 GetMultipleResourceProperties MSG: <pyGridWare.generated.types.resourceproperties.GetMultipleResourcePropertiesResponse_Holder instance at 0x134a468> Resource Property(<class 'pyGridWare.generated.types.mathservicerp._Value_immutable_holder'>) = 45 Resource Property(<class 'pyGridWare.generated.types.mathservicerp._LastOp_immutable_holder'>) = ADDITION