5.4. New MathService.rpy Script

We no longer need to implement the getValueRP operation. The WS-ResourceProperties portTypes, or operations, are generated in the MathServiceWSRF class. But we need to implement the add, subtract and createResource methods.


############################################################################
# Automatically generated by wsdl2web.py
# See LBNLCopyright for copyright notice!
###########################################################################
from generated.MathRPService.services.MathRPService.MathService import MathServiceWSRF

class Service(MathServiceWSRF):

    def wsa_add(self, ps, address, **kw):
        request,response = MathServiceWSRF.wsa_add(self, ps, address)
        ctx = self.GetResourceContext(ps, address)
        ctx.properties.Value += request
        ctx.properties.LastOp = "ADDITION"
        return request,response


    def wsa_subtract(self, ps, address, **kw):
        request,response = MathServiceWSRF.wsa_subtract(self, ps, address)
        ctx = self.GetResourceContext(ps, address)
        ctx.properties.Value -= request
        ctx.properties.LastOp = "SUBTRACT"
        return request,response

    #
    # The Factory Method for our Finished MathService
    #
    def wsa_createResource(self, ps, address, **kw):
        # Get request and response
        request,response = MathServiceWSRF.wsa_createResource(self, ps, address, **kw)

        # Create Resource Context
        from pyGridWare.utility.http import GetURLFromRequest
        ctx = self.NewResourceContextMathPort(\
            GetURLFromRequest(kw['request'])
        )

        # Initialize Value to 0
        counter = ctx.properties
        counter.Value = 0

        # Create EndPointReference and set in response
        from pyGridWare.addressing.AddressingUtils import AddressingUtils
        epr = AddressingUtils.createEndpointReference(ctx)
        response.EndpointReference = epr
        return request,response

resource = Service()