lost and found ( for me ? )

Python SOAPpy : parse WSDL with python SOAPpy

I’m newbie to SOAP API and Python :p
just referred to http://www.diveintopython.net/soap_web_services/introspection.html.
many , many , many thx.


# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.1 LTS
Release:        12.04
Codename:       precise

# python --version
Python 2.7.3


install SOAPpy , if you have not installed it.


# apt-get install python-soappy -y


to test soap API , I’ll use weather info wsdl  http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl , which is provided by National weather service. (http://graphical.weather.gov/xml/)

- check available methods


# python
Python 2.7.3 (default, Aug  1 2012, 05:14:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from SOAPpy import WSDL
>>> wsdlfile = 'http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl'
>>> server = WSDL.Proxy(wsdlfile)
>>> server.methods.keys()
[u'NDFDgenByDay', u'GmlTimeSeries', u'LatLonListCityNames', u'GmlLatLonList', u'NDFDgenLatLonList', u'LatLonListSquare', u'LatLonListLine', u'LatLonListSubgrid', u'CornerPoints', u'NDFDgenByDayLatLonList', u'NDFDgen', u'LatLonListZipCode']
>>>


- check arguments

check arguments of LatLonListCityNames
>>> callInfo = server.methods['LatLonListCityNames']

>>> callInfo.inparams
[<SOAPpy.wstools.WSDLTools.ParameterInfo instance at 0x7fad265ea998>]


name attribute
>>> callInfo.inparams[0].name
u'displayLevel'


data type defined in XML schema.
>>> callInfo.inparams[0].type
(u'http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd', u'displayLevelType')

- check return values


>>> callInfo.outparams
[<SOAPpy.wstools.WSDLTools.ParameterInfo instance at 0x7fad265ea9e0>]


outparams instance (0x7fad265ea9e0) is adjacent to inparams instance (0x7fad265ea998).

attributes and data type
>>> callInfo.outparams[0].name
u'listCityNamesOut'

>>> callInfo.outparams[0].type
(u'http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd', u'listCityNamesType')


- use SOAP API with WSDL Proxy


>>> from SOAPpy import WSDL
>>> wsdlfile = 'http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl'
>>> server = WSDL.Proxy(wsdlfile)
>>> server.LatLonListCityNames('1')
'<?xml version=\'1.0\' ?>\n<dwml version=\'1.0\' xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">\n<latLonList>35.4,-97.6 36.2,-95.9 35.82,-83.98 33.65,-84.42 39.5,-119.78 35.13,-111.67 33.44,-112.02 32.12,-110.93 35.60,-88.92 35.22,-92.38 34.027,-118.329 32.73,-117.17 38.29,-104.52 39.75,-104.87 38.85,-77.04 24.58,-81.75 25.80,-80.28 28.55,-81.33 27.97,-82.53 43.57,-116.22 41.98,-87.9 39.85,-89.67 39.37,-101.7 37.07,-88.77 30.03,-90.03 44.801,-68.778 46.861,-68.012 43.65,-70.32 39.18,-76.67 42.23,-83.33 46.54,-87.41 46.83,-92.18 44.88,-93.22 34.27,-88.77 38.75,-90.37 45.8,-108.53 45.95,-112.5 48.22,-106.62 46.92,-114.08 40.83,-115.78 36.08,-115.17 35.05,-106.6 42.75,-73.8 42.93,-78.73 43.12,-76.12 40.77,-73.98 46.77,-100.75 46.9,-96.8 48.27,-101.28 41.42,-81.87 40.00,-82.88 41.6,-83.8 45.6,-122.6 42.08,-80.18 39.88,-75.25 40.35,-79.93 41.73,-72.65 43.58,-96.73 36.17,-86.78 30.3,-97.7 25.9,-97.43 32.9,-97.03 31.8,-106.4 32.00,-102.08 29.65,-95.28 29.53,-98.47 40.78,-111.97 47.63,-117.53 42.95,-87.9 37.5,-77.33 18.40,-66.00 18.34,-64.96 17.70,-64.90 61.17,-150.02 71.30,-156.78 64.82,-147.87 58.37,-134.58 64.50,-165.43</latLonList>\n<cityNameList>Oklahoma City,OK|Tulsa,OK|Knoxville,TN|Atlanta,GA|Reno,NV|Flagstaff,AZ|Phoenix,AZ|Tucson,AZ|Jackson,TN|Little Rock,AR|Los Angeles,CA|San Diego,CA|Pueblo,CO|Denver,CO|Washington,DC|Key West,FL|Miami,FL|Orlando,FL|Tampa,FL|Boise,ID|Chicago,IL|Springfield,IL|Goodland,KS|Paducah,KY|New Orleans,LA|Bangor,ME|Caribou,ME|Portland,ME|Baltimore,MD|Detroit,MI|Marquette,MI|Duluth,MN|Minneapolis,MN|Tupelo,MS|St Louis,MO|Billings,MT|Butte,MT|Glasgow,MT|Missoula,MT|Elko,NV|Las Vegas,NV|Albuquerque,NM|Albany,NY|Buffalo,NY|Syracuse,NY|New York,NY|Bismarck,ND|Fargo,ND|Minot,ND|Cleveland,OH|Columbus,OH|Toledo,OH|Portland,OR|Erie,PA|Philadelphia,PA|Pittsburgh,PA|Hartford,CT|Sioux Falls,SD|Nashville,TN|Austin,TX|Brownsville,TX|Dallas,TX|El Paso,TX|Midland,TX|Houston,TX|San Antonio,TX|Salt Lake City,UT|Spokane,WA|Milwaukee,WI|Richmond,VA|San Juan,PR|St Thomas,VI|St Croix,VI|Anchorage,AK|Barrow,AK|Fairbanks,AK|Juneau,AK|Nome,AK</cityNameList>\n</dwml>\n'
>>>


outputs detailed requests/responses info.
>>> server.soapproxy.config.dumpSOAPOut = 1
>>> server.soapproxy.config.dumpSOAPIn = 1
>>> server.LatLonListCityNames('1')
*** Outgoing SOAP ******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
 SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/1999/XMLSchema"
>
<SOAP-ENV:Body>
<ns1:LatLonListCityNames xmlns:ns1="http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl" SOAP-ENC:root="1">
<v1 xsi:type="xsd:string">1</v1>
</ns1:LatLonListCityNames>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
************************************************************************
*** Incoming SOAP ******************************************************
<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:LatLonListCityNamesResponse xmlns:ns1="http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl"><listLatLonOut xsi:type="xsd:string">&lt;?xml version=&apos;1.0&apos; ?&gt;
&lt;dwml version=&apos;1.0&apos; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd&quot;&gt;
&lt;latLonList&gt;35.4,-97.6 36.2,-95.9 35.82,-83.98 33.65,-84.42 39.5,-119.78 35.13,-111.67 33.44,-112.02 32.12,-110.93 35.60,-88.92 35.22,-92.38 34.027,-118.329 32.73,-117.17 38.29,-104.52 39.75,-104.87 38.85,-77.04 24.58,-81.75 25.80,-80.28 28.55,-81.33 27.97,-82.53 43.57,-116.22 41.98,-87.9 39.85,-89.67 39.37,-101.7 37.07,-88.77 30.03,-90.03 44.801,-68.778 46.861,-68.012 43.65,-70.32 39.18,-76.67 42.23,-83.33 46.54,-87.41 46.83,-92.18 44.88,-93.22 34.27,-88.77 38.75,-90.37 45.8,-108.53 45.95,-112.5 48.22,-106.62 46.92,-114.08 40.83,-115.78 36.08,-115.17 35.05,-106.6 42.75,-73.8 42.93,-78.73 43.12,-76.12 40.77,-73.98 46.77,-100.75 46.9,-96.8 48.27,-101.28 41.42,-81.87 40.00,-82.88 41.6,-83.8 45.6,-122.6 42.08,-80.18 39.88,-75.25 40.35,-79.93 41.73,-72.65 43.58,-96.73 36.17,-86.78 30.3,-97.7 25.9,-97.43 32.9,-97.03 31.8,-106.4 32.00,-102.08 29.65,-95.28 29.53,-98.47 40.78,-111.97 47.63,-117.53 42.95,-87.9 37.5,-77.33 18.40,-66.00 18.34,-64.96 17.70,-64.90 61.17,-150.02 71.30,-156.78 64.82,-147.87 58.37,-134.58 64.50,-165.43&lt;/latLonList&gt;
&lt;cityNameList&gt;Oklahoma City,OK|Tulsa,OK|Knoxville,TN|Atlanta,GA|Reno,NV|Flagstaff,AZ|Phoenix,AZ|Tucson,AZ|Jackson,TN|Little Rock,AR|Los Angeles,CA|San Diego,CA|Pueblo,CO|Denver,CO|Washington,DC|Key West,FL|Miami,FL|Orlando,FL|Tampa,FL|Boise,ID|Chicago,IL|Springfield,IL|Goodland,KS|Paducah,KY|New Orleans,LA|Bangor,ME|Caribou,ME|Portland,ME|Baltimore,MD|Detroit,MI|Marquette,MI|Duluth,MN|Minneapolis,MN|Tupelo,MS|St Louis,MO|Billings,MT|Butte,MT|Glasgow,MT|Missoula,MT|Elko,NV|Las Vegas,NV|Albuquerque,NM|Albany,NY|Buffalo,NY|Syracuse,NY|New York,NY|Bismarck,ND|Fargo,ND|Minot,ND|Cleveland,OH|Columbus,OH|Toledo,OH|Portland,OR|Erie,PA|Philadelphia,PA|Pittsburgh,PA|Hartford,CT|Sioux Falls,SD|Nashville,TN|Austin,TX|Brownsville,TX|Dallas,TX|El Paso,TX|Midland,TX|Houston,TX|San Antonio,TX|Salt Lake City,UT|Spokane,WA|Milwaukee,WI|Richmond,VA|San Juan,PR|St Thomas,VI|St Croix,VI|Anchorage,AK|Barrow,AK|Fairbanks,AK|Juneau,AK|Nome,AK&lt;/cityNameList&gt;
&lt;/dwml&gt;
</listLatLonOut></ns1:LatLonListCityNamesResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
************************************************************************
'<?xml version=\'1.0\' ?>\n<dwml version=\'1.0\' xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">\n<latLonList>35.4,-97.6 36.2,-95.9 35.82,-83.98 33.65,-84.42 39.5,-119.78 35.13,-111.67 33.44,-112.02 32.12,-110.93 35.60,-88.92 35.22,-92.38 34.027,-118.329 32.73,-117.17 38.29,-104.52 39.75,-104.87 38.85,-77.04 24.58,-81.75 25.80,-80.28 28.55,-81.33 27.97,-82.53 43.57,-116.22 41.98,-87.9 39.85,-89.67 39.37,-101.7 37.07,-88.77 30.03,-90.03 44.801,-68.778 46.861,-68.012 43.65,-70.32 39.18,-76.67 42.23,-83.33 46.54,-87.41 46.83,-92.18 44.88,-93.22 34.27,-88.77 38.75,-90.37 45.8,-108.53 45.95,-112.5 48.22,-106.62 46.92,-114.08 40.83,-115.78 36.08,-115.17 35.05,-106.6 42.75,-73.8 42.93,-78.73 43.12,-76.12 40.77,-73.98 46.77,-100.75 46.9,-96.8 48.27,-101.28 41.42,-81.87 40.00,-82.88 41.6,-83.8 45.6,-122.6 42.08,-80.18 39.88,-75.25 40.35,-79.93 41.73,-72.65 43.58,-96.73 36.17,-86.78 30.3,-97.7 25.9,-97.43 32.9,-97.03 31.8,-106.4 32.00,-102.08 29.65,-95.28 29.53,-98.47 40.78,-111.97 47.63,-117.53 42.95,-87.9 37.5,-77.33 18.40,-66.00 18.34,-64.96 17.70,-64.90 61.17,-150.02 71.30,-156.78 64.82,-147.87 58.37,-134.58 64.50,-165.43</latLonList>\n<cityNameList>Oklahoma City,OK|Tulsa,OK|Knoxville,TN|Atlanta,GA|Reno,NV|Flagstaff,AZ|Phoenix,AZ|Tucson,AZ|Jackson,TN|Little Rock,AR|Los Angeles,CA|San Diego,CA|Pueblo,CO|Denver,CO|Washington,DC|Key West,FL|Miami,FL|Orlando,FL|Tampa,FL|Boise,ID|Chicago,IL|Springfield,IL|Goodland,KS|Paducah,KY|New Orleans,LA|Bangor,ME|Caribou,ME|Portland,ME|Baltimore,MD|Detroit,MI|Marquette,MI|Duluth,MN|Minneapolis,MN|Tupelo,MS|St Louis,MO|Billings,MT|Butte,MT|Glasgow,MT|Missoula,MT|Elko,NV|Las Vegas,NV|Albuquerque,NM|Albany,NY|Buffalo,NY|Syracuse,NY|New York,NY|Bismarck,ND|Fargo,ND|Minot,ND|Cleveland,OH|Columbus,OH|Toledo,OH|Portland,OR|Erie,PA|Philadelphia,PA|Pittsburgh,PA|Hartford,CT|Sioux Falls,SD|Nashville,TN|Austin,TX|Brownsville,TX|Dallas,TX|El Paso,TX|Midland,TX|Houston,TX|San Antonio,TX|Salt Lake City,UT|Spokane,WA|Milwaukee,WI|Richmond,VA|San Juan,PR|St Thomas,VI|St Croix,VI|Anchorage,AK|Barrow,AK|Fairbanks,AK|Juneau,AK|Nome,AK</cityNameList>\n</dwml>\n'
>>>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.