use python zsi to create and publish a web service (rpc-encoded)

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?wsdl

to 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值