Ruby Web 服务 - xmlparser 问题
在尝试使用 Ruby 设置 Web 服务后,我遇到了 xmlparser 的问题。正如我所看到的 - 这是常见问题(例如 Ruby Soap4r wsdl2ruby.rb 错误),但它的解决方案,无论多么简单,对我来说并不成功。
我正在尝试运行取自 http://www.tutorialspoint.com/ruby/ruby_web_services 的代码.htm 几乎没有修正(信号字符串没有引号)。我首先安装了soap4r,
$ gem install soap4r --include-dependencies
并将xmlparser.rb:66修复为
c.to_s.downcase == name
代码:
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
不幸的是,这仍然不起作用。它向我抛出一个错误:
undefined method `add_rpc_operation' for nil:NilClass
调用 add_method(self, ...) 后
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, ...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答自己:这个片段不完整。缺少超级构造函数调用。添加:
将使一切正常工作
answering myself: this snippet is incomplete. There is lack for super constructor call. Adding:
will make it all work