class Garage(ComplexModel): _type_info = [ ('vehicles', Array(Vehicle)), ] class SomeService(ServiceBase): @rpc(_returns=Garage) def get_garage_dump(self): return Garage( vehicles=[ Car( color="blue", speed=100, owner="Simba" ), Bike( size=58, owner="Nala" ), ] ) application = Application([SomeService], 'tns', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11(polymorphic=True) ) sys.exit(cherry_graft_and_start(WsgiApplication(application)))
if __name__ == '__main__': # Python daemon boilerplate logging.basicConfig(level=logging.DEBUG) # Instantiate the application by giving it: # * The list of services it should wrap, # * A namespace string. # * An input protocol. # * An output protocol. application = Application([HelloWorldService], 'spyne.examples.hello.http', # The input protocol is set as HttpRpc to make our service easy to # call. Input validation via the 'soft' engine is enabled. (which is # actually the the only validation method for HttpRpc.) in_protocol=HttpRpc(validator='soft'), # The ignore_wrappers parameter to JsonDocument simplifies the reponse # dict by skipping outer response structures that are redundant when # the client knows what object to expect. out_protocol=JsonDocument(ignore_wrappers=True), ) # Now that we have our application, we must wrap it inside a transport. # In this case, we use Spyne's standard Wsgi wrapper. Spyne supports # popular Http wrappers like Twisted, Django, Pyramid, etc. as well as # a ZeroMQ (REQ/REP) wrapper. wsgi_application = WsgiApplication(application) sys.exit(cherry_graft_and_start(wsgi_application))
if __name__ == '__main__': # Python daemon boilerplate logging.basicConfig(level=logging.DEBUG) # Instantiate the application by giving it: # * The list of services it should wrap, # * A namespace string. # * An input protocol. # * An output protocol. application = Application( [HelloWorldService], 'spyne.examples.hello.http', # The input protocol is set as HttpRpc to make our service easy to # call. Input validation via the 'soft' engine is enabled. (which is # actually the the only validation method for HttpRpc.) in_protocol=HttpRpc(validator='soft'), # The ignore_wrappers parameter to JsonDocument simplifies the reponse # dict by skipping outer response structures that are redundant when # the client knows what object to expect. out_protocol=JsonDocument(ignore_wrappers=True), ) # Now that we have our application, we must wrap it inside a transport. # In this case, we use Spyne's standard Wsgi wrapper. Spyne supports # popular Http wrappers like Twisted, Django, Pyramid, etc. as well as # a ZeroMQ (REQ/REP) wrapper. wsgi_application = WsgiApplication(application) sys.exit(cherry_graft_and_start(wsgi_application))
] class Bike(Vehicle): _type_info = [ ('size', Integer), ] class Garage(ComplexModel): _type_info = [ ('vehicles', Array(Vehicle)), ] class SomeService(ServiceBase): @rpc(_returns=Garage) def get_garage_dump(self): return Garage(vehicles=[ Car(color="blue", speed=100, owner="Simba"), Bike(size=58, owner="Nala"), ]) application = Application([SomeService], 'tns', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11(polymorphic=True)) sys.exit(cherry_graft_and_start(WsgiApplication(application)))
parent.text = "session[%s]%s" % (self.login_id, cid) return parent @rpc(_body_style='out_bare') def SetCollectorPageSize(ctx): return @rpc(models.WaitForUpdatesEx, _body_style='bare') def WaitForUpdatesEx(ctx, req): self = ctx.udc gevent.sleep(20) return application = Application( [vCenterService], tns=NS, in_protocol=Soap11(), # in_protocol=Soap11(validator='lxml'), out_protocol=Soap11()) if __name__ == '__main__': from wsgiref.simple_server import make_server wsgi_app = WsgiApplication(application) cherry_graft_and_start( wsgi_app, port=443, ssl_module='pyopenssl', cert='/root/simulator/vcenter/ssl/certs/server.pem', key='/root/simulator/vcenter/ssl/private/server-privkey.pem', cacert='/root/simulator/vcenter/ssl/certs/ca-cert.pem')