當前我正在使用Savon在Ruby中使用WebService。 它工作得很好,但我很難通過參數 參數的SOAP數組類型。下面的代碼無法正常工作:如何將數組作爲參數傳遞給Ruby中的SOAP
ids = [0,1,2]
client.do_get_items { |soap| soap.body = {
'item-list' => ids
}
我將不勝感激,如果你能解決我的問題或提出替代 庫紅寶石&肥皂
當前我正在使用Savon在Ruby中使用WebService。 它工作得很好,但我很難通過參數 參數的SOAP數組類型。下面的代碼無法正常工作:如何將數組作爲參數傳遞給Ruby中的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
我也有類似的問題。我必須發送字符串數組作爲請求的兩個參數。我用薩翁第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和檢查適當的請求應該是什麼樣子等。
很好的建議,但它可能並不總是足夠的。有些SOAP服務器還要求提供SOAP-ENC:Array或類似的屬性。 Savon對陣列的支持仍然非常有限。 – tokland 2010-09-16 17:03:57