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
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
- 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.
5 Request sent <!--?xml version="1.0" encoding="UTF-8"?> xmlns:ns0="http://127.0.1.1:8080/MathService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns0:paramsadd> <a>2</a> <b>3</b> <!--ns0:paramsadd> </SOAP-ENV:Body> </SOAP-ENV:Envelope> Response received <!--?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header/> <soapenv:Body> <returns>5</returns> <!--soapenv:Body> <!--soapenv:Envelope>