使用soap4r Ruby的SOAP

时间:2013-08-08 21:52:19

标签: ruby soap soap4r

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] ERROR - soapservice:不允许GET请求”。我试过通过POST访问它但仍然是同样的问题。任何人都可以告诉我,我应该使用正确的URL来使用这个Web服务吗?

1 个答案:

答案 0 :(得分:0)

尝试将其添加到顶部

require 'rubygems'
#gem 'soap4r'
gem 'soap4r-ruby1.9'
require 'soap/rpc/standaloneServer'
require 'builder'