Tornado – SOAP Web Services

SOAP (or Simple Object Access protocol) is a protocol that is used for development of web services in turn used for exchanging information across computers. While the message format is XML, the mode of negotiation and transmission typically is HTTP. SOAP provides a messaging framework where the client and web services are bind to a protocol and message format. More about SOAP can be read at wikipedia..

SOAP web services can be developed on top of web servers like Apache (*NIX) or IIS (Windows).. and of course Tornado web server! Let’s see how…

rancavil has come up with an excellent module that helps you develop SOAP based web services in Python and Tornado. This post describes development of SOAP Web Service on Tornado and a client program that can access this web service using Python-suds.

Let’s take an example

import tornado.httpserver
import tornado.ioloop
from tornadows import soaphandler
from tornadows import webservices
from tornadows import xmltypes
from tornadows.soaphandler import webservice
class MathService(soaphandler.SoapHandler):
def add(self, a, b):
return a+b
if __name__ == '__main__':
service = [('MathService',MathService)]
ws = webservices.WebService(service)
application = tornado.httpserver.HTTPServer(ws)

view raw

hosted with ❤ by GitHub

In this code snippet:

  • We create a SOAP Handler ‘MathService’ that performs mathematical operations
  • Method add() is defined that tales two integers as input and returns an integer value
  • Run the python code and the web service is up and running…
  • You could browse the WSDL at http://localhost:8080/MathService?wsdl

Let’s now have a look at the client code

import suds
## Invoke add method of MathService
url = 'http://localhost:8080/MathService?wsdl'
client = suds.client.Client(url,cache=None)
print client.service.add(2,3)
print "Request sent"
print client.last_sent()
print "Response received"
print client.last_received()

  • The Client is developed with Python Suds module
  • It makes a request to the add() method of MathService with parameters 2 and 3
  • and waits for a response

Output of this code can be found below, where the response body contains the summation of 2 and 3 i.e., 5.


Request sent
<!--?xml version="1.0" encoding="UTF-8"?>
xmlns:ns0="" xmlns:xsi="" xmlns:SOAP-ENV="">

Response received
<!--?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xsi:schemaLocation="">

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.