The finished MathService can be installed directly as an "rpy" script in the "services sub-directory where the service container is executed.
The service container above appears to have only a MathService, but other services that are transparent to the user such as SubscriptionManager and NotificationProducer are configured in the server-config.tac file.
![]() | Finished MathService.rpy script |
from generated.MathService.services.MathService.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
def wsa_getValueRP(self, ps, address, **kw):
request,response = MathServiceWSRF.wsa_getValueRP(self, ps, address)
ctx = self.GetResourceContext(ps, address)
ctx.properties.LastOp = "GETVALUE"
return request,response.__class__(ctx.properties.Value)
#
# 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()