2014-01-27 65 views
0

我試着從瑞安貝茨的紅寶石演員運行這段代碼,但它不起作用。我認爲它假定使用薩翁1如何將此示例Savon 1代碼轉換爲Savon 2?

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 

什麼是薩翁2的正確實施?我想複製並粘貼它並使其工作。

回答

0

這是我的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 
end