Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging
- from datetime import datetime
- from spyne.application import Application
- from spyne.decorator import srpc
- from spyne.service import ServiceBase
- from spyne.util.wsgi_wrapper import WsgiMounter
- from spyne.model.primitive import DateTime
- from spyne.protocol.xml import XmlDocument
- from spyne.protocol.soap import Soap11
- from spyne.protocol.json import JsonDocument
- tns = 'spyne.examples.multiple_protocols'
- port = 9910
- host = '127.0.0.1'
- class HelloWorldService(ServiceBase):
- @srpc(_returns=DateTime)
- def get_utc_time():
- return datetime.utcnow()
- if __name__ == '__main__':
- xml = Application([HelloWorldService], tns=tns,
- in_protocol=XmlDocument(), out_protocol=XmlDocument())
- soap = Application([HelloWorldService], tns=tns,
- in_protocol=Soap11(), out_protocol=Soap11())
- json0 = Application([HelloWorldService], tns=tns,
- in_protocol=JsonDocument(), out_protocol=JsonDocument())
- root = WsgiMounter({
- 'xml': xml,
- 'soap': soap,
- 'json0': json0,
- })
- from wsgiref.simple_server import make_server
- server = make_server(host, port, root)
- logging.basicConfig(level=logging.DEBUG)
- logging.info("listening to http://%s:%d" % (host,port))
- server.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment