A simple example of how to use Flask to build a SOAP server from WSDL
files.
Make sure you have locally installed:
Open your terminal and go to your directory flask-soap-server-mock
. You can decide to deploy the server in two ways:
- locally
~$ pipenv install
~$ ./bootstrap.sh
- via Docker
# Build image
~$ docker build -t flasksoap:latest .
# Run the container
~$ docker run --name flask -d -p 5000:5000 flasksoap
You can now issue requests to your API as you prefer. An example is given by the provided SOAP client, which triggers sample requests to the server and parses returned responses.
~$ cd client
~$ pipenv install && pipenv shell
(client) ~$ ./cli.py --help
Usage: cli.py [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
-H, --host TEXT SOAP Web Server
-p, --port TEXT Web Server Port
-U, --username TEXT Username to login
-P, --password TEXT Password to login
--help Show this message and exit.
Commands:
download
edit
login
(client) ~$ ./cli.py login
Response code '0' with message 'Welcome back'
When your SOAP client is hosted in an external machine, your flask server running locally requires a public URL to be reachable. An easy solution would be using ngrok.
- If never used before, register and follow instructions to install and locally configure it
- In terminal execute
ngrok http 5000
- Among printed output you should see a line starting with Forwarding, specifying something similar to
http://xyz.ngrok.io -> localhost:5000
- Make sure that:
- your SOAP binding location uses this hostname and port, and
- your client points to this URL
- Add your
wsdl
file toserver/templates/wsdl
- Make sure
wsdl
binding location matches<soap12:address location="{{ binding }}" />
- Integrate your new routes in
server/index.py
similarly to what's done in the example
The binding automatically discovers the requesting host. Manual changes are possible.
Similarly to response.xml
, create your own template in server/templates
and refers to it when building your route(s) in index.py
.
So, do you want to use this mock for your own testing? Great!
MIT Licensed. See LICENSE for full details.