rubysoapsoap4r

Ruby webservices - xmlparser issue


After trying to set up webservice setup using Ruby I encountered problems with xmlparser. As I see - it is common problem (e.g. Ruby soap4r wsdl2ruby.rb errors), but it's solution, however simple, isn't successful to me.

I'm trying to run code taken from http://www.tutorialspoint.com/ruby/ruby_web_services.htm with little correction (signal string had no enclosing apostrophe). I installed firstly soap4r using

$ gem install soap4r --include-dependencies

and fixed xmlparser.rb:66 to

  c.to_s.downcase == name

code:

require "soap/rpc/standaloneserver"

begin
   class MyServer < SOAP::RPC::StandaloneServer

      # Expose our services
      def initialize(*args)
         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("MyServer", 
            'urn:ruby:calculation', 'localhost', 8080)
  trap('INT'){
     server.shutdown
  }
  server.start
rescue => err
  puts err.message
end

this unfortunately still isn't working. It throws me an error:

undefined method `add_rpc_operation' for nil:NilClass

after invoking add_method(self, ...)


Solution

  • answering myself: this snippet is incomplete. There is lack for super constructor call. Adding:

    super(args[0], args[1], args[2], args[3])
    

    will make it all work