I successfully published the web service in ubunbu 8 (remote) and vista64 (local) and invoked them for testing.
python 2.5, zsi 2.1 (other zsi version may be different)
step1. create helloDBfetch.wsdl, it is almost as same as hello wold.
-------------------------------------------------------------------------------
http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="
xmlns:wsdl="
xmlns:xsd="
name="helloDBfetch" targetNamespace="
>
http://schemas.xmlsoap.org/soap/encoding/" namespace="
use="encoded"/>
http://schemas.xmlsoap.org/soap/encoding/" namespace="
use="encoded"/>
http://localhost:8080/"/>
-------------------------------------------------------------------------------
step2. run wsdl2py helloDBfetch.wsdl, generated 3 .py files (helloDBfetch_client.py, helloDBfetch_server.py, helloDBfetch_types.py), I put them under a folder called helloDBfetch, and also create a empty __init__.py in the folder to make it a package.
step3. create service implementation code: helloDBimpl.py
-------------------------------------------------------------------------
# make sure the path to helloDBfetch_server.py is correct, and import it
from helloDBfetch.helloDBfetch_server import *
from ZSI.ServiceContainer import AsServer # have to import this
# class name can be anything, but has to be sub class of helloDBfetch, which is defined in helloDBfetch_server.py
class myhelloDBfetchServices(helloDBfetch):
# Make WSDL available for HTTP GET
_wsdl = "".join(open("helloDBfetch.wsdl").readlines())
def soap_helloDbfetch(self,ps, **kw): #rewrite the soap_helloDbfetch method of helloDBfetch of helloDBfetch_server.py
try:#use the method from class helloDBfetch in helloDBfetch_server.py
request, response = helloDBfetch.soap_helloDbfetch(self, ps, **kw)
#_helloDbfetchResponse and _fetchDataReturn are defined in the helloDBfetch_server.py
response._helloDbfetchResponse="Hello "+request._fetchDataReturn
except Exception, e:
print str(e)
return request, response
--------------------------------------------------------------------------
step4. create server code: helloDBserver.py
----------------------------------------------------------------------------
from ZSI.ServiceContainer import AsServer
from helloDBimpl import myhelloDBfetchServices #have to import the service class you defined
from ZSI import dispatch
if __name__ == "__main__":
port = 8080
#service name has to be as same as the class name in helloDBimpl.py
AsServer(port,(myhelloDBfetchServices('helloDBfetch'),))
--------------------------------------------------------------------------------
testing: local in vista64
run the helloDBserver.py
you can open a browser check the wsdl file:
http://localhost:8080/helloDBfetch?wsdlto invoke this web service, I use SoapUI (a free GUI service client, you can download it for free: http://www.soapui.org/), then just open the soapUI and create a new project, type in the project name and the URL of the wsdl file, it will generate a sample request for you, double click the sample request, in the popup window you will see the soap message, just replace the ? with any string you want, e.g. lalal, click the send arrow button, you will see the returned string is “hello lalal” inside the soap message.
*****************************
testing: remote in ubuntu 8
upload all files in your ubuntu machine: helloDBfetch.wsdl, helloDBimpl.py, helloDBserver.py and the whole fold: helloDBfetch
run helloDBserver.py in ubuntu 8
the URL of the wsdl is : http://yourUbuntuComputerIP:8080/helloDBfetch?wsdl
still use SoapUI to invoke it, but the URL should changed to the new one, another thing is the generated wsdl file in the binding/location=…., it give the machine name, other than the real ip, in localhost, it does not matter, but remotely invoke the web service, you have to change the endpoint of the request in soapUI to the real ip of ubuntu machine other than the machine name, otherwise soapUi can not find your ubuntu machine. I do not know how to make it automatically use ip in the wsdl, so I have to manually change it when I use soapUI invoke it.
+++++++++++++++++++++++++++++++++++
one wired thing I find is, in the helloDBimpl.py, the last line of code
return response | this works in the ubuntu 8
return request, response | this works in vista64
otherwise it returns error:
#return response, in vista, error: 'helloDbfetchResponse' object is not iterable
#return request, response, in ubuntu, error: type object tuple has no typecode