Ruby 调用 WebServices
敬业的IT人
互联网
佚名
2008-1-4 14:25:12
讨论组:http://group.qqread.com
Demo WebService 公开 AddNumber 方法:
[WebMethod]public int AddNumber(int x, int y){return x + y;}
用 Ruby实现 WebServices 调用:
require 'soap/wsdlDriver'
wsdl = "http://localhost/WebAppTest/WebServicesDemo/Demo.asmx?wsdl"
params = {:x => 1, :y => 4}
drv = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
#Method1:
result = drv.AddNumber(params)
#Method2:
result = drv.send("AddNumber", params)
p result["AddNumberResult"] # Return 5
你可以通过 rpc_driver 的实例直接调用 AddNumber 方法如 #Method1 所示。也可以通过 send 方法名的方式动态调用,如 #Method2 所示。参数是一个Hash,其 key 值必须和 WebMethod 定义的参数名一致。返回值也是一个Hash, 其key值是 "#{MethodName}Result "。
进入讨论组讨论。- 最新文章
- RoR:Ruby On Rails 的 Web Servic..[01-04]
- Rational系列产品介绍[01-04]
- rational rose使用技巧[01-04]
- Rational Robot压力测试实例[01-04]
- 在Windows上安装配置Apache2.2.3及实现多站点[01-04]
- 初用ruby的几个注意事项[01-04]
- 相关文章
