I implemented a standalone server with the help of this tutorial:
http://www.tutorialspoint.com/ruby/ruby_web_services.htm
The code is :
require "soap/rpc/standaloneserver"
begin
class MyServer < SOAP::RPC::StandaloneServer
# Expose our services
def initialize(*args)
super(args[0], args[1], args[2], args[3])
add_method(self, 'add', 'a', 'b')
add_method(self, 'div', 'a', 'b')
end
# Handler methods
def add(a, b)
return a + b
end
def div(a, b)
return a / b
end
end
server = MyServer.new("soapservice", 'soapservice', 'localhost', 8080)
trap('INT'){server.shutdown }
server.start
rescue => err
puts err.message
end
当我尝试通过指向 localhost:8080 从浏览器访问它时,它给了我以下错误“[2013-08-08T16:31:19.040360 #4840] 错误——soapservice: GET request not allowed”。我尝试通过 POST 访问它,但仍然是同样的问题。谁能告诉我应该使用什么正确的 URL 来使用此 Web 服务?