`
23c
  • 浏览: 74548 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Ruby的SOAP实践(一)

    博客分类:
  • ruby
阅读更多
本例实现了一个多方法,包含参数的SOAP实例。

SOAP 服务端:

#!/usr/local/bin/ruby
require 'soap/rpc/standaloneServer'

module MySOAP
	class Timer
		def now
			Time.new.strftime("%Y-%m-%d %H:%M:%S")
		end
	end
	class Add
	  def add(i, j)
		return i.to_i + j.to_i
	  end
	end
end

class TimeServer < SOAP::RPC::StandaloneServer
	def on_init
		time = MySOAP::Timer.new
		add = MySOAP::Add.new
		add_method(time,"now")
		add_method(add,"add")
	end
end

NS = 'http://localhost/soap'
port = 4000
svr = TimeServer.new('timer',NS,'0.0.0.0',port)

trap('INT') { svr.shutdown }

puts "My SOAP is starting... port:#{port} (Ctrl+c to quit)"

svr.start

puts "My SOAP is stop."


SOAP客户端:
require 'soap/rpc/driver'

proxy = SOAP::RPC::Driver.new("http://localhost:4000","http://localhost/soap")

proxy.add_method('now')

proxy.add_method('add','i','j')

puts "Server time now is : #{proxy.now}"

puts "9 + 2000 = #{proxy.add(9,2000)}"
2
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics