因此,我需要从我的rails应用程序访问此服务。我使用soap4r读取WSDL并动态生成访问服务的方法。
根据我所读到的内容,我应该能够链接方法来访问嵌套的XML节点,但是我不能让它工作。我尝试使用wsdl2ruby命令并通读生成的代码。据我所知,soap库不会生成这些访问器方法。我刚接触ruby,所以我不知道我是不是错过了什么?
我知道当我检查元素时,我可以看到我想要的数据。我就是拿不到。
例如,如果我使用以下代码:
require "soap/wsdlDriver"
wsdl = "http://frontdoor.ctn5.org/CablecastWS/CablecastWS.asmx?WSDL"
driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
response = driver.getChannels('nill')
puts response.inspect我得到以下输出:
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}binding
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}operation
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}body
ignored element: {http://schemas.xmlsoap.org/wsdl/soap12/}address
#<SOAP::Mapping::Object:0x80b96394 {http://www.trms.com/CablecastWS/}GetChannelsResult=#<SOAP::Mapping::Object:0x80b96178 {http://www.trms.com/CablecastWS/}Channel=[#<SOAP::Mapping::Object:0x80b95f5c {http://www.trms.com/CablecastWS/}ChannelID="1" {http://www.trms.com/CablecastWS/}Name="CTN 5">, #<SOAP::Mapping::Object:0x80b9519c {http://www.trms.com/CablecastWS/}ChannelID="2" {http://www.trms.com/CablecastWS/}Name="PPAC 2">, #<SOAP::Mapping::Object:0x80b94620 {http://www.trms.com/CablecastWS/}ChannelID="14" {http://www.trms.com/CablecastWS/}Name="Test Channel">]>>所以数据是绝对存在的!
下面是由wsdl2ruby为上面使用的方法生成的代码:
# {http://www.trms.com/CablecastWS/}GetChannels
class GetChannels
def initialize
end
end
# {http://www.trms.com/CablecastWS/}GetChannelsResponse
# getChannelsResult - ArrayOfChannel
class GetChannelsResponse
attr_accessor :getChannelsResult
def initialize(getChannelsResult = nil)
@getChannelsResult = getChannelsResult
end
end很抱歉发了这么长的帖子,我想信息越多,就越有可能有人给我指明正确的方向。
谢谢
-ray
发布于 2009-10-31 11:32:47
应答
require "soap/wsdlDriver"
wsdl = "http://frontdoor.ctn5.org/CablecastWS/CablecastWS.asmx?WSDL"
driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
response = driver.getChannels('nill')
for item in response.getChannelsResult.channel
puts item.name
puts item.channelID
end我是如何得到答案的
您可以通过以下方式了解响应的方法
response.methods这将使您获得一长串难以排序的方法,因此我喜欢减去泛型方法。Ruby可以让你减去数组。
response.methods - Object.new.methods使用这种技术,我找到了用于响应的getChannelsResult方法。我重复了这个过程
resonse.getChannelsResult.methods - Object.new.methods我为它的结果找到了通道方法。再来一次!
response.getChannelsResult.channel.methods - Object.new.methods这返回了一堆方法,包括: sort,min,max等,所以我猜是Array。一个简单的确认是按顺序进行的
response.getChannelsResult.channel.class果然,它返回了Array。为了简单起见,我只使用数组的第一项来获取它的方法
response.getChannelsResult.channel.first.methods - Object.new.methods哇哇,我又找到了两个方法"name“和"channelID”
https://stackoverflow.com/questions/1653130
复制相似问题