Marek Wywiał

python software developer

Python SOAP server (flask) + wsdl generation

by Marek Wywiał
  |   Source

Install

$ pip install Flask-Enterprise

file: soap.py

from time import ctime
from flask import Flask
from flaskext.enterprise import Enterprise

app = Flask(__name__)

enterprise = Enterprise(app)


class DemoService(enterprise.SOAPService):
    __soap_server_address__ = '/soap'
    __soap_target_namespace__ = 'ns'

    @enterprise.soap(_returns=enterprise._sp.String)
    def get_time(self):
        return ctime()

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5555)

Run service

$ python soap.py

file: client.py

1
2
3
4
from suds.client import Client

c = Client('http://127.0.0.1:5555/soap?wsdl')
print c.service.get_time()

Run test

$ python client.py
Tue Aug 13 19:49:53 2013
Comments powered by Disqus
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/IT dx s: a C+++$ U>$ P+ L++$ !E-(+) W++$ N+ !o K--? !w !O !M !V PS PE !Y PGP !t !5 X++ R tv+ b+++ DI D G e+++(++++) h--- r y+++
------END GEEK CODE BLOCK------