savon gem example_body不合适

时间:2013-12-11 07:28:07

标签: ruby web-services savon

我有一个wsdl url来发出请求并获得响应这是我的代码(使用savon gem)

client = Savon.new('http://services.chromedata.com/Description/7a?wsdl')
service = :Description7a
port = :Description7aPort
operation = :getDivisions
division = client.operation(service, port, operation)

我可以打印example_body division.example_body

 => {:DivisionsRequest=>{:accountInfo=>{:_number=>"string", :_secret=>"string", :_country=>"string", :_language=>"string", :_behalfOf=>"string"}, :_modelYear=>"int"}} 

我可以设置像这样的值      division.body = {.........}

其他操作如

operationlist = client.operations(service, port)
=> ["getVersionInfo", "getModelYears", "getDivisions", "getSubdivisions", "getModels", "getStyles", "describeVehicle", "getCategoryDefinitions", "getTechnicalSpecificationDefinitions"]

我用过描述车辆

desc_veh = client.operation(service, port, "describeVehicle")

其example_body就像

desc_veh.example_body
=> {:VehicleDescriptionRequest=>{}}

因此无法设置desc_veh.body的值并使用.call函数

我不知道这是一个savon gem问题还是wsdl url问题

1 个答案:

答案 0 :(得分:0)

您的代码可能如下所示:

gem "savon", "~> 2.0"
require "savon"
client = Savon.client(
    :wsdl => 'http://services.chromedata.com/Description/7a?wsdl',
    :convert_request_keys_to => :camelcase,
    :log => true,
    :log_level => :debug,
    :pretty_print_xml => true
)

res = client.call(:get_divisions,
    message: { :param1 => 'value1', :param2 => 'value2' }
)

print res.to_hash

参数只是键/值对中的散列。