[XML-SIG] Document style SOAP Web Service with ZSI (docstyle)
Joshua Boverhof
JRBoverhof at lbl.gov
Thu Feb 5 23:56:38 EST 2004
Creating a client is simple, just use the wsdl2py tool to generate a
couple modules.
%wsdl2py -u http://ws.cdyne.com/ziptogeo/zip2geo.asmx?wsdl
% ls
Zip2Geo_services.py Zip2Geo_services_types.py
% python
Python 2.3 (#1, Aug 8 2003, 13:12:42)
[GCC 3.2 20020903 (Red Hat Linux 8.0 3.2-7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from Zip2Geo_services import Zip2GeoLocator, GetLatLongSoapInWrapper
>>> import sys
>>> kw = {'tracefile':sys.stdout}
>>> loc = Zip2GeoLocator()
>>> port = loc.getZip2GeoSoap(**kw)
>>> msg = GetLatLongSoapInWrapper()
>>> msg._zipcode = '94610'
>>> response = port.GetLatLong(msg)
_________________________________ Thu Feb 5 20:26:31 2004 REQUEST:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ZSI="http://www.zolera.com/schemas/ZSI/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" >
<SOAP-ENV:Body>
< xmlns="http://ws.cdyne.com">
<zipcode id="405aefa0" xsi:type="xsd:string">94610</zipcode>
</GetLatLong>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
_________________________________ Thu Feb 5 20:26:32 2004 RESPONSE:
Date: Fri, 06 Feb 2004 04:19:39 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
MicrosoftOfficeWebServer: 5.0_Pub
X-AspNet-Version: 1.1.4322
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: text/xml; charset=utf-8
Content-Length: 779
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetLatLongResponse
xmlns="http://ws.cdyne.com"><GetLatLongResult><ServiceError>false</ServiceError><AddressError>false</AddressError><City>OAKLAND</City><StateAbbrev>CA</StateAbbrev><ZipCode>94610</ZipCode><County>ALAMEDA</County><FromLongitude>-122.279480</FromLongitude><FromLatitude>37.799127</FromLatitude><ToLongitude>-122.279480</ToLongitude><ToLatitude>37.828727</ToLatitude><AvgLongitude>-122.247329</AvgLongitude><AvgLatitude>37.813927</AvgLatitude><CMSA>7362</CMSA><PMSA>5775</PMSA></GetLatLongResult></GetLatLongResponse></soap:Body></soap:Envelope>
>>> response._GetLatLongResult
<Zip2Geo_services_types.LatLongReturn_Def instance at 0x4076812c>
>>> response._GetLatLongResult._ServiceError
0
>>> response._GetLatLongResult._City
u'OAKLAND'
>>> response._GetLatLongResult._AvgLatitude
37.813927
There isn't currently a way to automatically generate the server-side,
but basically
you create modules that contain callback functions. But using the
dispatch module
in ZSI is problematic. This is a way to do it but it is not 100% correct.
$ cat run.py
#!/usr/bin/env python
from ZSI.dispatch import AsServer
import ZipServer
AsServer(port=8080, modules=(ZipServer,), docstyle=1)
$ cat ZipServer.py
from xml.dom.ext.reader import PyExpat
def GetLatLong(msg):
reply =
"""<GetLatLongResult><ServiceError>false</ServiceError><AddressError>false</AddressError><City>OAKLAND</City><StateAbbrev>CA</StateAbbrev><ZipCode>94610</ZipCode><County>ALAMEDA</County><FromLongitude>-122.279480</FromLongitude><FromLatitude>37.799127</FromLatitude><ToLongitude>-122.279480</ToLongitude><ToLatitude>37.828727</ToLatitude><AvgLongitude>-122.247329</AvgLongitude><AvgLatitude>37.813927</AvgLatitude><CMSA>7362</CMSA><PMSA>5775</PMSA></GetLatLongResult>"""
reader = PyExpat.Reader()
doc = reader.fromString(reply)
return doc
To change your client to send a message to your server just change the
portAddress of the port
when you get it from the locator object.
port = loc.getZip2GeoSoap(portAddress='http://localhost:8080', **kw)
-josh
Ertl, John wrote:
>I was following a thread about a doc style web service using Pythons ZSI and
>I could not follow the solution. Would anyone have a full simple example of
>a ZSI server and client doc style? I am also trying to use dispatch.AsCGI.
>
>John C. Ertl
>Fleet Numerical Meteorology & Oceanography Center
>7 Grace Hopper Ave
>Monterey, CA 93943
>phone: (831) 656-5704
>fax: (831) 656-4363
>
>
>_______________________________________________
>XML-SIG maillist - XML-SIG at python.org
>http://mail.python.org/mailman/listinfo/xml-sig
>
>
More information about the XML-SIG
mailing list