- 论坛徽章:
- 0
|
最近一直研究SOAP,并且实现了Python与Ruby的互通,这里和大家分享一下~
Python为服务器端
- from ZSI import dispatch
- def getWelcome(name):
- return "welcome " + name
- print "Starting server..."
- dispatch.AsServer(port=9000)
复制代码
Ruby为客户端
- require 'soap/rpc/driver'
- proxy = SOAP::RPC::Driver.new("http://localhost:9000",nil,'test')
- proxy.add_method('getWelcome','name')
- print proxy.getWelcome('interhui')
复制代码
这个是已经实现的,可是Ruby做服务器,Python做客户端却没有完全实现。
Ruby为服务端
- require 'soap/rpc/standaloneServer'
- class StringServant
- def getWelcome(name)
- return "Welcome "+name
- end
- end
- class Server < SOAP::RPC::StandaloneServer
- def on_init
- servant = StringServant.new
- add_method(servant,'getWelcome','name')
- end
- end
- if __FILE__ == $0
- svr = Server.new('Server','','0.0.0.0',9000)
- trap('INT') { svr.shutdown }
- svr.start
- end
复制代码
Python为客户端
- from ZSI.client import Binding
- u = ''
- n= 'Server'
- b = Binding(url=u, ns=n, host='localhost', port=9000)
- result = b.getWelcome('inter')
- print result
复制代码
也请各路高手给予指点 |
|