-
-
Save herrfz/6003491 to your computer and use it in GitHub Desktop.
suds Python SOAP client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "metadata": { | |
| "name": "soap_client" | |
| }, | |
| "nbformat": 3, | |
| "nbformat_minor": 0, | |
| "worksheets": [ | |
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "First import `suds` (install via **`pip install suds`**, or **`easy_install suds`**, or download tarball from https://pypi.python.org/pypi/suds, extract, then **`python setup.py install`**)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "from suds.client import Client" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 1 | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "Define the WSDL URL and configure the client. We'll try the Data Management Service (DMS) we developed for the OGC OWS-9 project:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "WSDL_URL = 'http://195.37.61.154:8080/axis2/services/DMServices?wsdl'\n", | |
| "client = Client(WSDL_URL)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [], | |
| "prompt_number": 2 | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "The available interfaces/operations in the WSDL can be listed as follows:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "for s in client.sd:\n", | |
| " print s" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "stream": "stdout", | |
| "text": [ | |
| "Service ( DMServices ) tns=\"http://www.opengis.net/dms/0.1\"\n", | |
| " Prefixes (1)\n", | |
| " ns0 = \"http://www.opengis.net/dms/0.1\"\n", | |
| " Ports (1):\n", | |
| " (DMServicesSOAP12)\n", | |
| " Methods (4):\n", | |
| " clientRequest(xs:string endpoint, xs:string serviceURL, xs:string request, )\n", | |
| " clientSubscribeRequest(xs:string serviceURL, xs:string request, )\n", | |
| " createSession(xs:string endpoint, Module[] Module, )\n", | |
| " getSessionOptions()\n", | |
| " Types (2):\n", | |
| " Module\n", | |
| " Options\n", | |
| "\n", | |
| "\n" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 3 | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "Let's try `getSessionOptions`:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "res = client.service.getSessionOptions()\n", | |
| "res" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "pyout", | |
| "prompt_number": 4, | |
| "text": [ | |
| "[(Module){\n", | |
| " name = \"PassThrough\"\n", | |
| " description = \"DMS pass through without filtering, validation, and provenance processing\"\n", | |
| " option = \n", | |
| " (Options){\n", | |
| " enabled = True\n", | |
| " }\n", | |
| " },\n", | |
| " (Module){\n", | |
| " name = \"RM\"\n", | |
| " description = \"DMS reliable messaging option\"\n", | |
| " option = \n", | |
| " (Options){\n", | |
| " enabled = True\n", | |
| " }\n", | |
| " },\n", | |
| " (Module){\n", | |
| " name = \"Compression\"\n", | |
| " description = \"DMS compression option\"\n", | |
| " option = \n", | |
| " (Options){\n", | |
| " enabled = True\n", | |
| " }\n", | |
| " },\n", | |
| " (Module){\n", | |
| " name = \"Validation\"\n", | |
| " description = \"DMS validation\"\n", | |
| " option = \n", | |
| " (Options){\n", | |
| " enabled = False\n", | |
| " }\n", | |
| " },\n", | |
| " (Module){\n", | |
| " name = \"Filtering\"\n", | |
| " description = \"DMS filtering\"\n", | |
| " option = \n", | |
| " (Options){\n", | |
| " enabled = True\n", | |
| " }\n", | |
| " },\n", | |
| " (Module){\n", | |
| " name = \"Prioritization\"\n", | |
| " description = \"DMS prioritization\"\n", | |
| " option = \n", | |
| " (Options){\n", | |
| " enabled = False\n", | |
| " }\n", | |
| " }]" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 4 | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "The response (on the wire it's XML) is stored as Python data structure:" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "type(res)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "pyout", | |
| "prompt_number": 5, | |
| "text": [ | |
| "list" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 5 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "len(res)" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "pyout", | |
| "prompt_number": 6, | |
| "text": [ | |
| "6" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 6 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "type(res[0])" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "pyout", | |
| "prompt_number": 7, | |
| "text": [ | |
| "instance" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 7 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "res[3]['name']" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "pyout", | |
| "prompt_number": 8, | |
| "text": [ | |
| "Validation" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 8 | |
| }, | |
| { | |
| "cell_type": "code", | |
| "collapsed": false, | |
| "input": [ | |
| "res[3]['option']['enabled']" | |
| ], | |
| "language": "python", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "output_type": "pyout", | |
| "prompt_number": 9, | |
| "text": [ | |
| "False" | |
| ] | |
| } | |
| ], | |
| "prompt_number": 9 | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "There you go! I haven't tried other scenarios, such as how to send a request containing a more complex data structure, e.g. the `createSession` method requires the specification of a `Module` data type. But I guess it should be possible in `suds`." | |
| ] | |
| } | |
| ], | |
| "metadata": {} | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment