-
Notifications
You must be signed in to change notification settings - Fork 32
How customize the returns values (a proposal).
rancavil edited this page Jul 15, 2012
·
3 revisions
You can customize the returns values using tornadows.complextypes.ComplexType.
The complextypes, allow us indicate the names of the attributes of a XML document, that will be use like web service return.
import tornado.ioloop
from tornadows import webservices
from tornadows import xmltypes
from tornadows.soaphandler import SoapHandler
from tornadows.complextypes import ComplexType
from tornadows.soaphandler import webservice
class MyReturn(ComplexType):
name = str
age = int
class DataService(SoapHandler):
@webservice(_params=str,_returns=MyReturn)
def getData(self,name):
r = MyReturn()
r.name = name
r.age = 21
return r
if __name__ == '__main__':
service = [('DataService',DataService)]
app = webservices.WebService(service)
app.listen(8080)
tornado.ioloop.IOLoop.instance().start()
The messages generated and returned by the web service are:
<soapenv:Envelope xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<MyReturn>
<age>21</age>
<name>Rodrigo</name>
</MyReturn>
</soapenv:Body>
</soapenv:Envelope>
Note: This web services was tested with SoapUI.
You can see how the subclass of ComplexType (MyReturn), it's converted to a XML Document.