我试着从Ryan Bates的ruby cast中运行这段代码,但它不起作用。我认为它假定使用了Savon 1。
require "savon"
client = Savon::Client.new("http://www.webservicex.net/uszip.asmx?WSDL")
response = client.request :web, :get_info_by_zip, body: { "USZip" => zip }
if response.success?
data = response.to_array(:get_info_by_zip_response, :get_info_by_zip_result, :new_data_set, :table).first
if data
@state = data[:state]
@city = data[:city]
@area_code = data[:area_code]
@time_zone = data[:time_zone]
puts @state
puts @city
puts @area_code
end
end Savon 2的正确实现是什么?我想复制并粘贴它,然后让它工作。
发布于 2014-01-28 06:42:54
下面是我的Service-Wrapper类的摘录,该类为其他ruby对象提供SOAP-Services。我通过为每个SOAP操作提供WSDL位置和自己的方法来初始化客户端。第三方方法是通过传递一个块的@client.call调用的,该块创建一个带有所提供参数的SOAP消息。
class Client
include Singleton
def wsdl_method_to_call
begin
response = @client.call(:wsdl_method_to_call) do
message auth:CREDENTIALS, param_1: param_1_value, param_2: param_2_value
end
rescue
raise CustomServiceException.new("Error ... , response : #{response}")
end
end
def initialize()
@client = Savon::Client.new(wsdl: WSDL)
end
private
WSDL = "http://service_host/wsdl"
CREDENTIALS = "foo|bar"
end所以也许你应该试着这样做:
response = client.call(:get_info_by_zip) do
message USZip: zip
endhttps://stackoverflow.com/questions/21391018
复制相似问题