如何在Ruby中将Array作为参数传递给SOAP

目前我正在使用Savon在ruby中使用WebService。 它工作得很好,但我很难传递参数 SOAP数组类型的参数。以下代码无法正常运行:
ids = [0,1,2]
client.do_get_items { |soap| soap.body = {
    'item-list' => ids
}
如果您能解决我的问题或提出替代方案,我将不胜感激 红宝石和肥皂库     
已邀请:
我只是偶然发现同样的问题,对我有用的临时解决方法如下:
ids = [0,1,2]
client.do_get_items { |soap| soap.body = {
  'item-list' => {
    'item1' => 0,
    'item2' => 1,
    'item3' => 2
  }  
}
名称“item1”,“item2”应该无关紧要。 我使用以下帮助器方法将常规数组转换为SOAP混乱:
def soap_array(array)
  returning({}) do |hash|
    array.each_with_index do |e, i|
      hash["item-#{i}"] = e
    end
  end
end
    
我遇到了类似的问题。我不得不发送字符串数组作为请求的两个参数。我使用了Savon版本2.我的最终解决方案如下所示:
class JvMatching

    CLIENT_ID = 'bb_matchnig'

    extend Savon::Model

    operations :query_index

    # arg1, arg 2 - name of parameters that should be arrays of string
    def self.query_index(contents=[], constraints=[], focus='job', result_size=20)
        super(message: { arg0: CLIENT_ID, arg1: { item: contents }, arg2: { item: constraints }, arg3: focus, arg4: result_size })      
    end  

end
帮助我找到正确解决方案的是下载SOAP UI并检查正确的请求应该是什么样子。     

要回复问题请先登录注册