Ruby 编写一个 SOAP 服务器端

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

require 'soap/rpc/standaloneServer'

class MyServer < SOAP::RPC::StandaloneServer
  def initialize(*args)
    super
    add_method(self, 'sayhelloto', 'username')
  end

  def sayhelloto(username)
    "Hello, #{username}."
  end
end

server = MyServer.new('CoolServer','urn:mySoapServer','localhost',8888)
trap('INT') { server.shutdown }
server.start

# Call your service

require 'soap/rpc/driver'
driver = SOAP::RPC::Driver.new('http://localhost:8888/', 'urn:mySoapServer')
driver.add_method('sayhelloto', 'username')
driver.sayhelloto('aaa')