HOWTO


 

 

  1. Generate client stubs, server stubs, and types from a WSDL file.
  2. Example Client Script
    1. Basic Counter Example
    2. Add Notification Consumer

      3.  Create A Service

a.    Create Service Module

b.    Secure Messaging

c.     Add Service Instance to Twisted Container

 

 


I.      Generate client stubs, server stubs, and types

 

Add your WSDL entry under appropriate section in "pyGridWare/config.txt".

 

[WSDL]

CounterService = share/schema/core/samples/counter/counter_service.wsdl

 

Regenerate all bindings and install.

 

%python setup.py --regenerate install

 

Generates several modules for each WSDL (eg. Òcounter_service.wsdlÓ)

 

1) Types module:

pyGridWare/generated/types/counterservice.py

 

      2) Client module:

pyGridWare/generated/stubs/counterservice.py

 

      3) Service stub module:

pyGridWare/generated/services/stubs/counterservice.py

 

      4) Service WSRF modules:

pyGridWare/generated/services/counterservice/CounterService.py

pyGridWare/generated/properties/counterservice/CounterService/CounterPortTypePort.py

pyGridWare/generated/resource/counterservice/CounterService.py

 

 

 


II.    Client Script

A.   Basic Example (eg. "bin/CounterClient.py"):

 

Create a resource

 

import pyGridWare.generated.stubs.Counter_services as COUNTER

locator = COUNTER.CounterServiceLocator()

port = locator.getCounterPortType(portAddress=url, **kw)

request = COUNTER.CreateCounterRequest()

msg = port.createCounter(request)

 

Counter Port using EPR

 

epr = msg._EndpointReference

port = locator.getCounterPortType(portAddress=url, \

endPointReference=epr, **kw)

msg = port.add(100)

 

B.   Add Notification (eg. Òbin/NotificationCounterClient.pyÓ)

 

First you need to create a notification consumer, and from it you can retrieve the notification context.  Second, provide the notificationConsumer's EPR in the Subscribe message, and also provide the resource property QName we want to be notified about.

 

1.    Create a Notification Consumer:

 

from pyGridWare.notification.NotificationConsumer import \

    NotificationConsumer

notificationConsumer = NotificationConsumer()

notificationConsumer.start()

 

2.    Use Stub to Subscribe:

 

WARNING -- The topic expression expects to receive a QName in text content.  This is a little screwy since we need to manually specify the prefix mapping, to do this we need to specify a typecode attribute for the text content.

 

Class Qname(tuple):

    typecode = ZSI.TC.Qname()

 

ctx = notificationConsumer.getNotificationContext()

request = COUNTER.SubscribeRequest()

request._ConsumerReference = ctx.getConsumerReference()

request._TopicExpression = TopicExpression()

request._TopicExpression._text = Qname(Òhttp://counter.comÓ, ÒValueÓ)

request._UseNotify = True

msg = port.Subscribe(request)

 

 

 


 

 

III.   Create a Service

 

First youÕll need to create a resource context, and resource home.  The context will hold state and information specific to the resource.  Secondly youÕll need to implement the service by sub-classing the generated server module.

A.   Create a new service module

 

 Eg. 'pyGridWare.services.CounterService'.

 

First subclass the generated server interface, and overide any "wsa_" methods you need to and call the base class method to set up the request instance (available as "self.request") and initialize the response (return by base class "wsa_" call).

 

All the logic of each operation will reside within the service's "wsa_" methods. Standard WSRF methods will already be implemented in the generated code.

 

 

Types of Operations:

1.    Factory Pattern:  Create a resource  'wsa_createCounter'

 

First need to create a context, set the URL of the service, and register it to the resource home.   Then need to retrieve the End Point Reference (EPR) from the context instance, and set this in the response message that is returned to the calling party.

 

2.    Lifetime:  Destroy a resource 'wsa_Destroy'

 

Automatically generated.

 

3.    Lifetime: Set terminationTime 'wsa_SetTerminationTime'

 

Automatically generated.

 

4.    Properties:  Retrieve a resource property value 'wsa_GetResourceProperty'

 

Automatically generated.

5.    Counter Add:  add an integer to the counter.

 

Retrieve the resource context from the ResourceHome, then grab the resource properties from the resource context.  Then grab the "Value" resource property.  Add "self.request" to "Value", and set the "Value" resource property to their sum.

 

6.    Subscribe: Subscribe to a resource property 'wsa_Subscribe'

 

Subscribe to a resource property to receive notifications when that resource property's state changes.  Retrieve the resource context from the ResourceHome, then get the SubscriptionManager singleton.  Use the Subscription Manager to subscribe to the resource property using the request, it will return an EPR representing the subscription that must be returned in the response message.

 

 

B.   Secure Messaging:

 

Eg. "pyGridWare.generated.services.Counter_services_server.py"

 

Inherit from class GssSecureResourceMixIn.

 

 

from pyGridWare.services.CounterService import Counter

from pyGridWare.security.gss.GssService import GssSecureResourceMixIn

 

class SecureCounter(GssSecureResourceService, Counter):

 

def __init__(self, post='/wsrf/services/SecureCounterService', **kw):

GssSecureResourceService.__init__(self, post)

 

C.  Add Service Instance to "bin/server-config.tac"

 

Basically you need to identify or create the resource node in the siteÕs resource tree where the service instance will reside, and also pass in the POST value when creating the service instance.

 

Run the twisted service container:

 

%./start-container.sh